To openglraw

This commit is contained in:
2023-03-09 22:00:19 +00:00
parent 9989c65d75
commit 52d0286433
+26 -23
View File
@@ -1,6 +1,5 @@
module Render ( module Render (
createLightMap, createLightMap,
divideSize,
renderFoldable, renderFoldable,
renderLayer, renderLayer,
pingPongBetween, pingPongBetween,
@@ -20,15 +19,11 @@ import Dodge.Data.Config
import Foreign hiding (rotate) import Foreign hiding (rotate)
import Geometry.Data import Geometry.Data
import Graphics.GL.Core43 import Graphics.GL.Core43
import Graphics.Rendering.OpenGL hiding (Color, Line, Polygon, T, imageHeight, scale, translate)
import Picture.Data import Picture.Data
import Shader import Shader
import Shader.Data import Shader.Data
import Shader.ExtraPrimitive import Shader.ExtraPrimitive
divideSize :: Int -> Size -> Size
divideSize i (Size x y) = Size (div x $ fromIntegral i) (div y $ fromIntegral i)
-- | Determine where light is shining in the world. -- | Determine where light is shining in the world.
-- think of the produced texture as showing what RGB values should be "taken -- think of the produced texture as showing what RGB values should be "taken
-- away" from the shape colors. -- away" from the shape colors.
@@ -55,26 +50,30 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUSh
ltextShad = _lightingTextureShader pdata ltextShad = _lightingTextureShader pdata
-- we assume that the renderbuffer's depth has been correctly set elsewhere -- we assume that the renderbuffer's depth has been correctly set elsewhere
-- we will not be changing that here -- we will not be changing that here
depthMask $= Disabled glDepthMask GL_FALSE
-- clearColor is specified differently in preloadRender -- clearColor is specified differently in preloadRender
-- the colors are inverted -- the colors are inverted
clearColor $= Color4 1 1 1 1 glClearColor 1 1 1 1
clear [ColorBuffer] glClear GL_COLOR_BUFFER_BIT
-- for each of the lights: -- for each of the lights:
-- 1. stencil out the shadows from this light's point of view -- 1. stencil out the shadows from this light's point of view
-- 2. calculate lighting based on each fragment's position -- 2. calculate lighting based on each fragment's position
-- to consider: adding normals/a "material" for each fragment -- to consider: adding normals/a "material" for each fragment
blendFunc $= (Zero, OneMinusSrcColor) glBlendFunc GL_ZERO GL_ONE_MINUS_SRC_COLOR
stencilTest $= Enabled glEnable GL_STENCIL_TEST
stencilOpSeparate Front $= (OpKeep, OpKeep, OpIncrWrap) --stencilTest $= Enabled
stencilOpSeparate Back $= (OpKeep, OpKeep, OpDecrWrap) glStencilOpSeparate GL_FRONT GL_KEEP GL_KEEP GL_INCR_WRAP
--stencilOpSeparate Front $= (OpKeep, OpKeep, OpIncrWrap)
--stencilOpSeparate Back $= (OpKeep, OpKeep, OpDecrWrap)
glStencilOpSeparate GL_BACK GL_KEEP GL_KEEP GL_DECR_WRAP
flip VFSM.mapM_ (VFSM.fromList lightPoints) $ \(V3 x y z, rad, V3 r g b) -> do flip VFSM.mapM_ (VFSM.fromList lightPoints) $ \(V3 x y z, rad, V3 r g b) -> do
depthFunc $= Just Less glDepthFunc GL_LESS
-- setup stencil -- setup stencil
colorMask $= Color4 Disabled Disabled Disabled Disabled glColorMask GL_FALSE GL_FALSE GL_FALSE GL_FALSE
clear [StencilBuffer] glClear GL_STENCIL_BUFFER_BIT
cullFace $= Nothing glDisable GL_CULL_FACE
stencilFunc $= (Always, 0, 255) --cullFace $= Nothing
glStencilFunc GL_ALWAYS 0 255
--draw wall shadows --draw wall shadows
--currentProgram $= Just (_shadProg lwallShad) --currentProgram $= Just (_shadProg lwallShad)
glUseProgram (_shadProg' lwallShad) glUseProgram (_shadProg' lwallShad)
@@ -104,7 +103,9 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUSh
GL_UNSIGNED_SHORT GL_UNSIGNED_SHORT
nullPtr nullPtr
--draw caps on the near plane as required --draw caps on the near plane as required
cullFace $= Just Back glEnable GL_CULL_FACE
glCullFace GL_BACK
--cullFace $= Just Back
--currentProgram $= Just (_shadProg lcapShad) --currentProgram $= Just (_shadProg lcapShad)
--uniform (_shadUnis lcapShad V.! 0) $= Vector3 x y z --uniform (_shadUnis lcapShad V.! 0) $= Vector3 x y z
glUseProgram (_shadProg' lcapShad) glUseProgram (_shadProg' lcapShad)
@@ -119,12 +120,14 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUSh
CPUObjShads -> drawCPUShadows (V3 x y z) rad CPUObjShads -> drawCPUShadows (V3 x y z) rad
_ -> return () _ -> return ()
--draw lightmap itself --draw lightmap itself
depthFunc $= Just Always glEnable GL_DEPTH_TEST
glDepthFunc GL_ALWAYS
--depthFunc $= Just Always
-- bind world position texture -- bind world position texture
bindTO toPos bindTO toPos
colorMask $= Color4 Enabled Enabled Enabled Enabled glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
--stencilOp $= (OpKeep, OpKeep, OpKeep) --stencilOp $= (OpKeep, OpKeep, OpKeep)
stencilFunc $= (Equal, 0, 255) glStencilFunc GL_EQUAL 0 255
--currentProgram $= ltextShad ^? shadProg --Just (_shadProg ltextShad) --currentProgram $= ltextShad ^? shadProg --Just (_shadProg ltextShad)
--uniform (_shadUnis ltextShad V.! 0) $= Vector3 x y z --uniform (_shadUnis ltextShad V.! 0) $= Vector3 x y z
--uniform (_shadUnis ltextShad V.! 1) $= Vector4 r g b rad --uniform (_shadUnis ltextShad V.! 1) $= Vector4 r g b rad
@@ -138,8 +141,8 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos drawCPUSh
0 0
(fromIntegral (4 :: Int)) (fromIntegral (4 :: Int))
--cleanup: may not be necessary, depending on what comes after... --cleanup: may not be necessary, depending on what comes after...
cullFace $= Nothing glDisable GL_CULL_FACE
stencilTest $= Disabled glDisable GL_STENCIL_TEST
-- assumes that vertices have already been sent to the shader -- assumes that vertices have already been sent to the shader
pingPongBetween :: pingPongBetween ::