summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-04-30 22:59:13 -0400
committerJoe Crayne <joe@jerkface.net>2019-04-30 22:59:13 -0400
commitfce8237d59397054ea467fd9b5357877342dc34b (patch)
tree8ce3ff02c5ad8edec01f54aa396005e54c1c1a98
parent3a959223200961dedef69a28146662077aa0e093 (diff)
This seems to work to use skycube and object texturing together.
-rw-r--r--MeshSketch.hs8
-rw-r--r--SavedPipeline.hs151
2 files changed, 158 insertions, 1 deletions
diff --git a/MeshSketch.hs b/MeshSketch.hs
index 70493bd..8c46d54 100644
--- a/MeshSketch.hs
+++ b/MeshSketch.hs
@@ -31,6 +31,8 @@ import LambdaCube.GL as LC
31import LambdaCube.IR as LC 31import LambdaCube.IR as LC
32import LambdaCube.Gtk 32import LambdaCube.Gtk
33import LambdaCube.GL.Data (uploadCubeMapToGPU) 33import LambdaCube.GL.Data (uploadCubeMapToGPU)
34import LambdaCube.GL.Type (TextureData(..))
35import Text.Show.Pretty (ppShow)
34 36
35import CubeMap 37import CubeMap
36import GLWidget (nullableContext, withCurrentGL) 38import GLWidget (nullableContext, withCurrentGL)
@@ -41,6 +43,7 @@ import LoadMesh
41import InfinitePlane 43import InfinitePlane
42import MtlParser (ObjMaterial(..)) 44import MtlParser (ObjMaterial(..))
43import Matrix 45import Matrix
46import SavedPipeline
44 47
45-- State created by uploadState. 48-- State created by uploadState.
46data State = State 49data State = State
@@ -193,7 +196,8 @@ new = do
193 m <- do 196 m <- do
194 objName <- head . (++ ["cube.obj"]) <$> getArgs 197 objName <- head . (++ ["cube.obj"]) <$> getArgs
195 mobj <- loadOBJ objName 198 mobj <- loadOBJ objName
196 mpipeline <- loadPipeline "hello_obj2.json" $ do 199 -- mpipeline <- loadPipeline "hello_obj2.json" $ do
200 mpipeline <- (\s -> return (Right (DynamicPipeline savedPipeline (makeSchema s)))) $ do
197 defObjectArray "SkyCube" Triangles $ do 201 defObjectArray "SkyCube" Triangles $ do
198 "position" @: Attribute_V3F 202 "position" @: Attribute_V3F
199 defObjectArray "objects" Triangles $ do 203 defObjectArray "objects" Triangles $ do
@@ -211,6 +215,8 @@ new = do
211 return $ (,) <$> mobj <*> mpipeline 215 return $ (,) <$> mobj <*> mpipeline
212 either (\e _ -> hPutStrLn stderr e >> throwIO (userError e)) (&) m $ \(obj,pipeline) -> do 216 either (\e _ -> hPutStrLn stderr e >> throwIO (userError e)) (&) m $ \(obj,pipeline) -> do
213 217
218 -- putStrLn $ ppShow (dynamicPipeline pipeline)
219
214 ref <- newIORef Nothing 220 ref <- newIORef Nothing
215 -- glarea <- newGLWidget return (lambdaRender app glmethods) 221 -- glarea <- newGLWidget return (lambdaRender app glmethods)
216 do 222 do
diff --git a/SavedPipeline.hs b/SavedPipeline.hs
new file mode 100644
index 0000000..053eb6b
--- /dev/null
+++ b/SavedPipeline.hs
@@ -0,0 +1,151 @@
1{-# LANGUAGE OverloadedLists #-}
2module SavedPipeline where
3
4import LambdaCube.IR
5import LambdaCube.Linear
6import Data.Vector (Vector)
7import Data.Map (Map)
8import GHC.Exts
9
10
11savedPipeline :: Pipeline
12savedPipeline = Pipeline
13 { info = "Generated by lambdacube-compiler 0.6.1.0, edited to support TextureCube."
14 , backend = OpenGL33
15 , textures = []
16 , samplers = []
17 , targets =
18 [ RenderTarget { renderTargets = [ TargetItem { targetSemantic = Depth , targetRef = Just (Framebuffer Depth) }
19 , TargetItem { targetSemantic = Color , targetRef = Just (Framebuffer Color) }
20 ]
21 }
22 ]
23 , programs =
24 [ Program
25 { programUniforms = fromList [ ( "ViewProjection" , M44F ) ]
26 , programStreams = fromList [ ( "vi1" , Parameter { name = "position" , ty = V4F } ) ]
27 , programInTextures = fromList []
28 , programOutput = [ Parameter { name = "f0" , ty = V4F } ]
29 , vertexShader =
30 "#version 330 core\nvec4 texture2D(sampler2D s,vec2 uv) {\n return texture(s,uv);\n}\nuniform mat4 ViewProjection;\nin vec4 vi1;\nsmooth out vec2 vo1;\nvec4 coordmap(mat4 z0,vec4 z1) {\n return (z0) * (z1);\n}\nvoid main() {\n gl_Position = coordmap (ViewProjection,vi1);\n vo1 = (vi1).xz;\n}"
31 , geometryShader = Nothing
32 , fragmentShader =
33 "#version 330 core\nvec4 texture2D(sampler2D s,vec2 uv) {\n return texture(s,uv);\n}\nsmooth in vec2 vo1;\nout vec4 f0;\nvoid main() {\n f0 = ((vec4 (1.0,1.0,1.0,0.0)) * (max ((mix (vec2 (0.0,0.0)\n ,vec2 (1.0,1.0)\n ,greaterThanEqual (fract (vo1),(vec2 (1.0,1.0)) * (0.95)))).x\n ,(mix (vec2 (0.0,0.0)\n ,vec2 (1.0,1.0)\n ,greaterThanEqual (fract (vo1),(vec2 (1.0,1.0)) * (0.95)))).y))) + (vec4 (0.0\n ,0.0\n ,0.0\n ,0.8));\n}"
34 }
35 , Program
36 { programUniforms = fromList
37 [ ( "ViewProjection" , M44F )
38 , ( "diffuseColor" , V4F )
39 , ( "diffuseTexture" , FTexture2D )
40 ]
41 , programStreams = fromList
42 [ ( "vi1" , Parameter { name = "position" , ty = V4F } )
43 , ( "vi2" , Parameter { name = "normal" , ty = V3F } )
44 , ( "vi3" , Parameter { name = "uvw" , ty = V3F } )
45 ]
46 , programInTextures = fromList [ ( "diffuseTexture" , FTexture2D ) ]
47 , programOutput = [ Parameter { name = "f0" , ty = V4F } ]
48 , vertexShader =
49 "#version 330 core\nvec4 texture2D(sampler2D s,vec2 uv) {\n return texture(s,uv);\n}\nuniform mat4 ViewProjection;\nin vec4 vi1;\nin vec3 vi2;\nin vec3 vi3;\nsmooth out vec2 vo1;\nvec4 coordmap(mat4 z0,vec4 z1) {\n return (z0) * (z1);\n}\nvoid main() {\n gl_Position = coordmap (ViewProjection,vi1);\n vo1 = vec2 ((vi3).x,(1.0) - ((vi3).y));\n}"
50 , geometryShader = Nothing
51 , fragmentShader =
52 "#version 330 core\nvec4 texture2D(sampler2D s,vec2 uv) {\n return texture(s,uv);\n}\nuniform vec4 diffuseColor;\nuniform sampler2D diffuseTexture;\nsmooth in vec2 vo1;\nout vec4 f0;\nvoid main() {\n f0 = (diffuseColor) * (texture2D (diffuseTexture,vo1));\n}"
53 }
54 , Program
55 { programUniforms = fromList
56 [ ( "CameraPosition" , V3F )
57 , ( "CubeMap" , FTextureCube )
58 , ( "ViewProjection" , M44F )
59 ]
60 , programStreams = fromList [ ( "vi1" , Parameter { name = "position" , ty = V3F } ) ]
61 , programInTextures = fromList [ ( "CubeMap" , FTextureCube ) ]
62 , programOutput = [ Parameter { name = "f0" , ty = V4F } ]
63 , vertexShader =
64 "#version 330 core\nvec4 texture2D(sampler2D s,vec2 uv) {\n return texture(s,uv);\n}\nuniform vec3 CameraPosition;\nuniform mat4 ViewProjection;\nin vec3 vi1;\nsmooth out vec3 vo1;\nvec4 point(vec3 z0) {\n return vec4 ((z0).x,(z0).y,(z0).z,1.0);\n}\nvoid main() {\n gl_Position = (ViewProjection) * (point ((vi1) + (CameraPosition)));\n vo1 = vec3 ((vi1).x,(vi1).y,(vi1).z);\n}"
65 , geometryShader = Nothing
66 , fragmentShader =
67 "#version 330 core\nvec4 texture2D(sampler2D s,vec2 uv) {\n return texture(s,uv);\n}\nuniform samplerCube CubeMap;\nsmooth in vec3 vo1;\nout vec4 f0;\nvoid main() {\n f0 = texture (CubeMap,vo1);\n}"
68 }
69 ]
70 , slots =
71 [ Slot { slotName = "plane"
72 , slotStreams = fromList [ ( "position" , V4F ) ]
73 , slotUniforms = fromList [ ( "ViewProjection" , M44F ) ]
74 , slotPrimitive = Triangles
75 , slotPrograms = [ 0 ]
76 }
77 , Slot { slotName = "objects"
78 , slotStreams = fromList [ ( "normal" , V3F ) , ( "position" , V4F ) , ( "uvw" , V3F ) ]
79 , slotUniforms = fromList [ ( "ViewProjection" , M44F )
80 , ( "diffuseColor" , V4F )
81 , ( "diffuseTexture" , FTexture2D )
82 ]
83 , slotPrimitive = Triangles
84 , slotPrograms = [ 1 ]
85 }
86 , Slot { slotName = "SkyCube"
87 , slotStreams = fromList [ ( "position" , V3F ) ]
88 , slotUniforms = fromList [ ( "CameraPosition" , V3F )
89 , ( "CubeMap" , FTextureCube )
90 , ( "ViewProjection" , M44F )
91 ]
92 , slotPrimitive = Triangles
93 , slotPrograms = [ 2 ]
94 }
95 ]
96 , streams = []
97 , commands =
98 [ SetRenderTarget 0
99 , ClearRenderTarget
100 [ ClearImage { imageSemantic = Depth , clearValue = VFloat 1.0 }
101 , ClearImage { imageSemantic = Color , clearValue = VV4F (V4 0.0 0.0 0.4 1.0) }
102 ]
103 , SetProgram 2
104 -- This command is wrong. It causes the diffuseTexture mapping to fail.
105 -- , SetSamplerUniform "CubeMap" 1
106 , SetRasterContext (TriangleCtx CullNone PolygonFill NoOffset LastVertex)
107 , SetAccumulationContext
108 AccumulationContext
109 { accViewportName = Nothing
110 , accOperations = [ DepthOp Always False
111 , ColorOp NoBlending (VV4B (V4 True True True True))
112 ]
113 }
114 , RenderSlot 2
115 -- This doesn't help.
116 -- , ClearRenderTarget [ ClearImage { imageSemantic = Depth , clearValue = VFloat 1.0 } ]
117 , SetProgram 1
118 , SetSamplerUniform "diffuseTexture" 2
119 , SetRasterContext (TriangleCtx (CullBack CCW) PolygonFill NoOffset LastVertex)
120 , SetAccumulationContext
121 AccumulationContext
122 { accViewportName = Nothing
123 , accOperations = [ DepthOp Less True
124 , ColorOp NoBlending (VV4B (V4 True True True True))
125 ]
126 }
127 , RenderSlot 1
128 , SetProgram 0
129 , SetRasterContext (TriangleCtx CullNone PolygonFill NoOffset LastVertex)
130 , SetAccumulationContext
131 AccumulationContext
132 { accViewportName = Nothing
133 , accOperations =
134 [ DepthOp Less True
135 , ColorOp
136 Blend
137 { colorEqSrc = FuncAdd
138 , alphaEqSrc = FuncAdd
139 , colorFSrc = One
140 , colorFDst = SrcAlpha
141 , alphaFSrc = DstAlpha
142 , alphaFDst = DstAlpha
143 , color = V4 0.0 0.0 0.0 0.0
144 }
145 (VV4B (V4 True True True True))
146 ]
147 }
148 , RenderSlot 0
149 ]
150 }
151