diff options
author | Joe Crayne <joe@jerkface.net> | 2019-04-29 23:11:39 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-04-29 23:11:39 -0400 |
commit | c9c0db44f79c5ad13c0937d8e36fa828447f9585 (patch) | |
tree | caf5695cab2c9030f13f0b2a039f015508908124 | |
parent | c9d1da96a78c78f18ba0d995d6a0376a00452b80 (diff) |
Skybox-related uniforms.
-rw-r--r-- | MeshSketch.hs | 13 | ||||
-rw-r--r-- | hello_obj2.lc | 9 |
2 files changed, 15 insertions, 7 deletions
diff --git a/MeshSketch.hs b/MeshSketch.hs index 288488b..7f01d4d 100644 --- a/MeshSketch.hs +++ b/MeshSketch.hs | |||
@@ -131,11 +131,11 @@ uploadState obj glarea storage = do | |||
131 | skybox <- newIORef 0 | 131 | skybox <- newIORef 0 |
132 | Right ts <- skyboxLoad skyboxes 0 | 132 | Right ts <- skyboxLoad skyboxes 0 |
133 | skybox_id <- uploadCubeMapToGPU ts | 133 | skybox_id <- uploadCubeMapToGPU ts |
134 | -- LC.updateUniforms storage $ do | 134 | LC.updateUniforms storage $ do |
135 | -- "CubeMap" @= return skybox_id | 135 | "CubeMap" @= return skybox_id |
136 | skytex <- newIORef skybox_id | 136 | skytex <- newIORef skybox_id |
137 | mi <- LC.uploadMeshToGPU cubeMesh | 137 | mi <- LC.uploadMeshToGPU cubeMesh |
138 | -- LC.addMeshToObjectArray storage "SkyCube" [] mi -- TODO | 138 | LC.addMeshToObjectArray storage "SkyCube" [] mi |
139 | 139 | ||
140 | let st = State | 140 | let st = State |
141 | { stAnimator = tm | 141 | { stAnimator = tm |
@@ -194,6 +194,8 @@ new = do | |||
194 | objName <- head . (++ ["cube.obj"]) <$> getArgs | 194 | objName <- head . (++ ["cube.obj"]) <$> getArgs |
195 | mobj <- loadOBJ objName | 195 | mobj <- loadOBJ objName |
196 | mpipeline <- loadPipeline "hello_obj2.json" $ do | 196 | mpipeline <- loadPipeline "hello_obj2.json" $ do |
197 | defObjectArray "SkyCube" Triangles $ do | ||
198 | "position" @: Attribute_V3F | ||
197 | defObjectArray "objects" Triangles $ do | 199 | defObjectArray "objects" Triangles $ do |
198 | "position" @: Attribute_V4F | 200 | "position" @: Attribute_V4F |
199 | "normal" @: Attribute_V3F | 201 | "normal" @: Attribute_V3F |
@@ -201,6 +203,7 @@ new = do | |||
201 | defObjectArray "plane" Triangles $ do | 203 | defObjectArray "plane" Triangles $ do |
202 | "position" @: Attribute_V4F | 204 | "position" @: Attribute_V4F |
203 | defUniforms $ do | 205 | defUniforms $ do |
206 | "CubeMap" @: FTextureCube | ||
204 | "CameraPosition" @: V3F | 207 | "CameraPosition" @: V3F |
205 | "ViewProjection" @: M44F | 208 | "ViewProjection" @: M44F |
206 | "diffuseTexture" @: FTexture2D | 209 | "diffuseTexture" @: FTexture2D |
@@ -314,8 +317,8 @@ onEvent w realized ev = do | |||
314 | Right ts <- skyboxLoad (stSkyboxes st) idx | 317 | Right ts <- skyboxLoad (stSkyboxes st) idx |
315 | disposeTexture =<< readIORef (stSkyTexture st) | 318 | disposeTexture =<< readIORef (stSkyTexture st) |
316 | skybox_id <- uploadCubeMapToGPU ts | 319 | skybox_id <- uploadCubeMapToGPU ts |
317 | -- LC.updateUniforms storage $ do | 320 | LC.updateUniforms (stStorage realized) $ do |
318 | -- "CubeMap" @= return skybox_id | 321 | "CubeMap" @= return skybox_id |
319 | writeIORef (stSkyTexture st) skybox_id | 322 | writeIORef (stSkyTexture st) skybox_id |
320 | put (skyboxNames (stSkyboxes st) !! idx) | 323 | put (skyboxNames (stSkyboxes st) !! idx) |
321 | return () | 324 | return () |
diff --git a/hello_obj2.lc b/hello_obj2.lc index d0fc35b..52d4a52 100644 --- a/hello_obj2.lc +++ b/hello_obj2.lc | |||
@@ -7,7 +7,9 @@ blendplane = -- NoBlending -- BlendLogicOp Xor | |||
7 | ((OneBF,SrcAlpha),(DstAlpha,DstAlpha)) | 7 | ((OneBF,SrcAlpha),(DstAlpha,DstAlpha)) |
8 | (V4 0 0 0 0) | 8 | (V4 0 0 0 0) |
9 | 9 | ||
10 | makeFrame (cameraPosition :: Vec 3 Float) | 10 | makeFrame (cubemap :: Texture) |
11 | (skybox :: PrimitiveStream Triangle ((Vec 3 Float))) | ||
12 | (cameraPosition :: Vec 3 Float) | ||
11 | (cam :: Mat 4 4 Float) | 13 | (cam :: Mat 4 4 Float) |
12 | (color :: Vec 4 Float) | 14 | (color :: Vec 4 Float) |
13 | (texture :: Texture) | 15 | (texture :: Texture) |
@@ -30,9 +32,12 @@ makeFrame (cameraPosition :: Vec 3 Float) | |||
30 | in ((r + V4 0 0 0 (0.8)))) | 32 | in ((r + V4 0 0 0 (0.8)))) |
31 | & accumulateWith (DepthOp Less True, ColorOp blendplane (V4 True True True True)) | 33 | & accumulateWith (DepthOp Less True, ColorOp blendplane (V4 True True True True)) |
32 | 34 | ||
35 | textureCubeSlot s = Texture2DSlot s | ||
33 | 36 | ||
34 | main = renderFrame $ | 37 | main = renderFrame $ |
35 | makeFrame (Uniform "CameraPosition") | 38 | makeFrame (textureCubeSlot "CubeMap") |
39 | (fetch "SkyCube" ((Attribute "position"))) | ||
40 | (Uniform "CameraPosition") | ||
36 | (Uniform "ViewProjection") | 41 | (Uniform "ViewProjection") |
37 | (Uniform "diffuseColor") | 42 | (Uniform "diffuseColor") |
38 | (Texture2DSlot "diffuseTexture") | 43 | (Texture2DSlot "diffuseTexture") |