Move towards geometry instancing for shadows
This commit is contained in:
+20
-8
@@ -18,7 +18,7 @@ import qualified Data.Vector.Unboxed.Mutable as UMV
|
||||
import Dodge.Data.Config
|
||||
import Foreign hiding (rotate)
|
||||
import Geometry.Data
|
||||
import Graphics.GL.Core43
|
||||
import Graphics.GL.Core45
|
||||
import Picture.Data
|
||||
import Shader
|
||||
import Shader.Data
|
||||
@@ -137,6 +137,14 @@ createLightMap pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos drawCPUS
|
||||
glDisable GL_CULL_FACE
|
||||
glDisable GL_STENCIL_TEST
|
||||
|
||||
lightsToArray :: [(Point3,Float,Point3)] -> [Float]
|
||||
lightsToArray xs = concat (take 20 $ map t xs ++ repeat [0,0,0,0])
|
||||
++ concat (take 20 $ map s xs ++ repeat [0,0,0,0])
|
||||
where
|
||||
t (V3 a b c,_,_) = [a,b,c,1]
|
||||
s (_,d,V3 e f g) = [e,f,g,d]
|
||||
--t (V3 a b c,d,V3 e f g) = [a,b,c,1]
|
||||
|
||||
instanceLightMap ::
|
||||
RenderData ->
|
||||
[(Point3, Float, Point3)] -> -- Lights
|
||||
@@ -150,10 +158,13 @@ instanceLightMap ::
|
||||
TO ->
|
||||
IO ()
|
||||
instanceLightMap pdata lightPoints nWalls nSils nCaps toPos = do
|
||||
let llinesShad = _lightingLineShadowShader pdata
|
||||
lcapShad = _lightingCapShader pdata
|
||||
lwallShad = _lightingWallShadShader pdata
|
||||
ltextShad = _lightingTextureShader pdata
|
||||
let llinesShad = _shadowEdgeShader pdata
|
||||
lcapShad = _shadowCapShader pdata
|
||||
lwallShad = _shadowWallShader pdata
|
||||
--llinesShad = _lightingLineShadowShader pdata
|
||||
ltextShad = _shadowLightShader pdata
|
||||
withArray (lightsToArray lightPoints) $ \ptr ->
|
||||
glNamedBufferSubData (pdata ^. lightsUBO) 0 620 ptr
|
||||
-- we assume that the renderbuffer's depth has been correctly set elsewhere
|
||||
-- we will not be changing that here
|
||||
glDepthMask GL_FALSE
|
||||
@@ -172,7 +183,7 @@ instanceLightMap pdata lightPoints nWalls nSils nCaps toPos = do
|
||||
--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 (zip lightPoints [(0::Int)..])) $ \((V3 x y z, rad, V3 r g b),i) -> do
|
||||
glDepthFunc GL_LESS
|
||||
-- setup stencil
|
||||
glColorMask GL_FALSE GL_FALSE GL_FALSE GL_FALSE
|
||||
@@ -186,6 +197,7 @@ instanceLightMap pdata lightPoints nWalls nSils nCaps toPos = do
|
||||
--uniform (_shadUnis lwallShad V.! 0)
|
||||
-- $= Vector3 x y z
|
||||
glUniform3f (_shadUnis' lwallShad V.! 0) x y z
|
||||
glUniform1i (_shadUnis' lwallShad V.! 1) (fromIntegral i)
|
||||
--bindVertexArrayObject $= lwallShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad)
|
||||
glBindVertexArray $ lwallShad ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad)
|
||||
glDrawArrays
|
||||
@@ -194,8 +206,7 @@ instanceLightMap pdata lightPoints nWalls nSils nCaps toPos = do
|
||||
(fromIntegral nWalls)
|
||||
--draw silhouette shadows
|
||||
glUseProgram (_shadProg' llinesShad)
|
||||
glUniform3f (_shadUnis' llinesShad V.! 0) x y z
|
||||
glUniform1f (_shadUnis' llinesShad V.! 1) rad
|
||||
glUniform1i (_shadUnis' llinesShad V.! 0) (fromIntegral i)
|
||||
glBindVertexArray (_vaoName $ _shadVAO' llinesShad)
|
||||
glDrawElements
|
||||
(marshalEPrimitiveMode $ _shadPrim' llinesShad)
|
||||
@@ -207,6 +218,7 @@ instanceLightMap pdata lightPoints nWalls nSils nCaps toPos = do
|
||||
glCullFace GL_BACK
|
||||
glUseProgram (_shadProg' lcapShad)
|
||||
glUniform3f (_shadUnis' lcapShad V.! 0) x y z
|
||||
glUniform1i (_shadUnis' lcapShad V.! 1) (fromIntegral i)
|
||||
glBindVertexArray $ lcapShad ^. shadVAO' . vaoName --Just (_vao $ _shadVAO lcapShad)
|
||||
glDrawElements
|
||||
(marshalEPrimitiveMode $ _shadPrim' lcapShad)
|
||||
|
||||
Reference in New Issue
Block a user