Cleanup: remove uniforms from shader datatype

This commit is contained in:
2023-03-20 01:19:10 +00:00
parent 33f31aa385
commit 32ecf46343
17 changed files with 24 additions and 99 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 36 KiB

+1 -1
View File
@@ -2,7 +2,7 @@
layout (triangles) in; layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out; layout (triangle_strip, max_vertices = 3) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
uniform vec3 lightPos; layout(location=0)uniform vec3 lightPos;
// this code is duplicated in lineShadow.geom, should not be changed on its own // this code is duplicated in lineShadow.geom, should not be changed on its own
vec4 projNear (vec4 pos) vec4 projNear (vec4 pos)
{ {
+2 -2
View File
@@ -2,8 +2,8 @@
layout(lines_adjacency) in; layout(lines_adjacency) in;
layout(triangle_strip, max_vertices = 4) out; layout(triangle_strip, max_vertices = 4) out;
layout(std140, binding = 0) uniform TheMat { mat4 theMat; }; layout(std140, binding = 0) uniform TheMat { mat4 theMat; };
uniform vec3 lightPos; layout(location=0) uniform vec3 lightPos;
uniform float radiusUniform; layout(location=1) uniform float radiusUniform;
// vec4 shift (vec4 p) { return (vec4 (p.xyz + // vec4 shift (vec4 p) { return (vec4 (p.xyz +
// (lumRad.a*normalize(p.xyz-lightPos)), 1));} // (lumRad.a*normalize(p.xyz-lightPos)), 1));}
float closestPointOnLineParam3 (vec3 a, vec3 b, vec3 p) { float closestPointOnLineParam3 (vec3 a, vec3 b, vec3 p) {
+4 -4
View File
@@ -1,6 +1,6 @@
#version 450 core #version 450 core
uniform vec3 lightPos; layout(location=0)uniform vec3 lightPos;
uniform vec4 lumRad; layout(location=1)uniform vec4 lumRad;
layout (binding = 0) uniform sampler2D screenTexture; layout (binding = 0) uniform sampler2D screenTexture;
layout (binding = 1) uniform sampler2D normals; layout (binding = 1) uniform sampler2D normals;
in vec2 vTexPos; in vec2 vTexPos;
@@ -20,8 +20,8 @@ void main() {
//float y3 = clamp(0.5 * (y1 + 1),0,1) ; //float y3 = clamp(0.5 * (y1 + 1),0,1) ;
float y3 = clamp(2*y1 + 1,0,1) ; float y3 = clamp(2*y1 + 1,0,1) ;
//float y3 = clamp(0.5 * (y1 + 2),0,1) ; //float y3 = clamp(0.5 * (y1 + 2),0,1) ;
float y = float(normbit.w == 0 ? y2 : y2); //float y = float(normbit.w == 0 ? y3 : y2);
//float y = y2; float y = y2;
float x = 1 - dist / rad; float x = 1 - dist / rad;
vec3 c = y* (x * x * x) * lumRad.rgb; vec3 c = y* (x * x * x) * lumRad.rgb;
fColor = vec4(c, 0); fColor = vec4(c, 0);
-9
View File
@@ -1,9 +0,0 @@
#version 450 core
in vec3 lum;
in vec3 dField;
out vec4 fColor;
void main()
{
vec3 c = pow (1 - min(1, dot(dField,dField)) , 2) * lum ;
fColor = vec4(c,0);
}
-32
View File
@@ -1,32 +0,0 @@
#version 450 core
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
uniform vec3 lightPos;
uniform vec4 lumRad;
out vec3 dField;
out vec3 lum;
float isLHS (vec2 startV, vec2 testV)
{ return sign( -startV.x * testV.y + startV.y * testV.x); }
void main()
{
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1);
if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0)
{ lum = lumRad.rgb;
float rad = lumRad.a;
vec4 p3 = vec4 (p1.xy,100,1);
vec4 p4 = vec4 (p2.xy,100,1);
vec2 d1 = p1.xy - lightPos.xy;
vec2 d2 = p2.xy - lightPos.xy;
vec4 a1 = theMat * p1;
vec4 a2 = theMat * p2;
vec4 a3 = theMat * p3;
vec4 a4 = theMat * p4;
dField = (p1.xyz - lightPos) / rad; gl_Position = a1; EmitVertex();
dField = (p3.xyz - lightPos) / rad; gl_Position = a3; EmitVertex();
dField = (p2.xyz - lightPos) / rad; gl_Position = a2; EmitVertex();
dField = (p4.xyz - lightPos) / rad; gl_Position = a4; EmitVertex();
EndPrimitive();
} else {}
}
-6
View File
@@ -1,6 +0,0 @@
#version 450 core
layout (location = 0) in vec4 poss;
void main()
{
gl_Position = poss;
}
+2 -2
View File
@@ -2,8 +2,8 @@
layout(points) in; layout(points) in;
layout(triangle_strip, max_vertices = 18) out; layout(triangle_strip, max_vertices = 18) out;
layout(std140, binding = 0) uniform TheMat { mat4 theMat; }; layout(std140, binding = 0) uniform TheMat { mat4 theMat; };
uniform vec3 lightPos; layout(location=0) uniform vec3 lightPos;
uniform float rad; layout(location=1) uniform float rad;
float rad2 = rad; float rad2 = rad;
// Preprocessed to include ../functions.glsl // Preprocessed to include ../functions.glsl
float closestPointOnLineParam (vec2 a, vec2 b, vec2 p) { float closestPointOnLineParam (vec2 a, vec2 b, vec2 p) {
+4 -2
View File
@@ -127,8 +127,10 @@ doDrawing' win pdata u = do
glDepthFunc GL_LESS glDepthFunc GL_LESS
-- draw wall occlusions from the camera's point of view -- draw wall occlusions from the camera's point of view
glUseProgram (pdata ^. lightingWallShadShader . shadName) glUseProgram (pdata ^. lightingWallShadShader . shadName)
glUniform3f (pdata ^?! lightingWallShadShader . shadUnis . ix 0) vfx vfy 20 glProgramUniform3f (pdata ^. lightingWallShadShader . shadName)
glUniform1f (pdata ^?! lightingWallShadShader . shadUnis . ix 1) 1000 0 vfx vfy 20
glProgramUniform1f (pdata ^. lightingWallShadShader . shadName)
1 1000
glBindVertexArray $ pdata ^. lightingWallShadShader . shadVAO . vaoName glBindVertexArray $ pdata ^. lightingWallShadShader . shadVAO . vaoName
unless (debugOn Remove_LOS cfig) $ unless (debugOn Remove_LOS cfig) $
glDrawArrays glDrawArrays
+2 -1
View File
@@ -13,6 +13,7 @@ import Dodge.Wall.Draw
import Geometry import Geometry
import ShapePicture import ShapePicture
-- not necessary: should just poke all walls to their wanted places
wallsToDraw :: World -> ([((Point2, Point2), Point4)], [((Point2, Point2), Point4)], SPic, [Wall]) wallsToDraw :: World -> ([((Point2, Point2), Point4)], [((Point2, Point2), Point4)], SPic, [Wall])
wallsToDraw w = L.fold wallsToDraw w = L.fold
( (,,,) ( (,,,)
@@ -22,9 +23,9 @@ wallsToDraw w = L.fold
<*> L.prefilter wlOpaqueDraw L.list <*> L.prefilter wlOpaqueDraw L.list
) )
(w ^. cWorld . lWorld . walls) (w ^. cWorld . lWorld . walls)
-- (wlsFromIXs w $ zonesExtract (w ^. wlZoning) $ zoneOfSight wlZoneSize cam)
where where
f wl = (_wlLine wl, _wlColor wl) f wl = (_wlLine wl, _wlColor wl)
-- (wlsFromIXs w $ zonesExtract (w ^. wlZoning) $ zoneOfSight wlZoneSize cam)
-- cam = w ^. cWorld . camPos -- cam = w ^. cWorld . camPos
--wallsToDraw --wallsToDraw
-4
View File
@@ -111,13 +111,10 @@ preloadRender = do
-- lighting shaders -- lighting shaders
lightingWallShadShad <- lightingWallShadShad <-
makeShaderUsingVAO "lighting/wallShadow" [vert, geom, frag] EPoints wpVAO makeShaderUsingVAO "lighting/wallShadow" [vert, geom, frag] EPoints wpVAO
>>= addUniforms ["lightPos","rad"]
lightingCapShad <- lightingCapShad <-
makeShaderUsingVAO "lighting/cap" [vert, geom] ETriangles shPosVAO makeShaderUsingVAO "lighting/cap" [vert, geom] ETriangles shPosVAO
>>= addUniforms ["lightPos"]
lightingLineShadowShad <- lightingLineShadowShad <-
makeShaderUsingVAO "lighting/lineShadow" [vert, geom] ELinesAdjacency shEdgeVAO makeShaderUsingVAO "lighting/lineShadow" [vert, geom] ELinesAdjacency shEdgeVAO
>>= addUniforms ["lightPos", "radiusUniform"]
shadowedgeshader <- shadowedgeshader <-
makeShaderUsingVAO "shadow/edge" [vert, geom] ELinesAdjacency shEdgeVAO makeShaderUsingVAO "shadow/edge" [vert, geom] ELinesAdjacency shEdgeVAO
@@ -158,7 +155,6 @@ preloadRender = do
grayscaleShad <- makeShaderUsingVAO "texture/grayscale" [vert, frag] ETriangleStrip fsshadvao grayscaleShad <- makeShaderUsingVAO "texture/grayscale" [vert, frag] ETriangleStrip fsshadvao
lightingTextureShad <- lightingTextureShad <-
makeShaderUsingVAO "lighting/texture" [vert, frag] ETriangleStrip fsshadvao makeShaderUsingVAO "lighting/texture" [vert, frag] ETriangleStrip fsshadvao
>>= addUniforms ["lightPos", "lumRad"]
barrelShad <- makeShader "texture/barrel" [vert, geom, frag] [2, 2, 2, 1] EPoints barrelShad <- makeShader "texture/barrel" [vert, geom, frag] [2, 2, 2, 1] EPoints
-- blank wallShader -- blank wallShader
wallBlankShad <- makeShaderUsingVAO "wall/blank" [vert, geom, frag] EPoints wpColVAO wallBlankShad <- makeShaderUsingVAO "wall/blank" [vert, geom, frag] EPoints wpColVAO
+9 -11
View File
@@ -11,8 +11,6 @@ import Control.Lens
import Control.Monad import Control.Monad
import Control.Monad.Primitive import Control.Monad.Primitive
import Data.Preload.Render import Data.Preload.Render
import qualified Data.Vector as V
--import Control.Monad
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
import qualified Data.Vector.Mutable as MV import qualified Data.Vector.Mutable as MV
import qualified Data.Vector.Unboxed.Mutable as UMV import qualified Data.Vector.Unboxed.Mutable as UMV
@@ -88,8 +86,8 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
glStencilFunc GL_EQUAL 0 255 glStencilFunc GL_EQUAL 0 255
glUseProgram (ltextShad ^. shadName) glUseProgram (ltextShad ^. shadName)
glUniform3f (_shadUnis ltextShad V.! 0) x y z glUniform3f 0 x y z
glUniform4f (_shadUnis ltextShad V.! 1) r g b rad glUniform4f 1 r g b rad
glBindVertexArray $ ltextShad ^. shadVAO . vaoName glBindVertexArray $ ltextShad ^. shadVAO . vaoName
glDrawArrays glDrawArrays
(marshalEPrimitiveMode (_shadPrim' ltextShad)) (marshalEPrimitiveMode (_shadPrim' ltextShad))
@@ -152,8 +150,8 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
glStencilFunc GL_ALWAYS 0 255 glStencilFunc GL_ALWAYS 0 255
--draw wall shadows --draw wall shadows
glUseProgram (_shadName lwallShad) glUseProgram (_shadName lwallShad)
glUniform3f (_shadUnis lwallShad V.! 0) x y z glUniform3f 0 x y z
glUniform1f (_shadUnis lwallShad V.! 1) rad glUniform1f 1 rad
glBindVertexArray $ lwallShad ^. shadVAO . vaoName -- Just (_vao $ _shadVAO lwallShad) glBindVertexArray $ lwallShad ^. shadVAO . vaoName -- Just (_vao $ _shadVAO lwallShad)
glDrawArrays glDrawArrays
(marshalEPrimitiveMode $ _shadPrim' lwallShad) (marshalEPrimitiveMode $ _shadPrim' lwallShad)
@@ -164,8 +162,8 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
--draw silhouette shadows --draw silhouette shadows
glEnable GL_DEPTH_CLAMP glEnable GL_DEPTH_CLAMP
glUseProgram (_shadName llinesShad) glUseProgram (_shadName llinesShad)
glUniform3f (_shadUnis llinesShad V.! 0) x y z glUniform3f 0 x y z
glUniform1f (_shadUnis llinesShad V.! 1) rad glUniform1f 1 rad
glBindVertexArray (_vaoName $ _shadVAO llinesShad) glBindVertexArray (_vaoName $ _shadVAO llinesShad)
glDrawElements glDrawElements
(marshalEPrimitiveMode $ _shadPrim' llinesShad) (marshalEPrimitiveMode $ _shadPrim' llinesShad)
@@ -177,7 +175,7 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
glCullFace GL_BACK glCullFace GL_BACK
glCullFace GL_FRONT glCullFace GL_FRONT
glUseProgram (_shadName lcapShad) glUseProgram (_shadName lcapShad)
glUniform3f (_shadUnis lcapShad V.! 0) x y z glUniform3f 0 x y z
glBindVertexArray $ lcapShad ^. shadVAO . vaoName --Just (_vao $ _shadVAO lcapShad) glBindVertexArray $ lcapShad ^. shadVAO . vaoName --Just (_vao $ _shadVAO lcapShad)
glDrawElements glDrawElements
(marshalEPrimitiveMode $ _shadPrim' lcapShad) (marshalEPrimitiveMode $ _shadPrim' lcapShad)
@@ -196,8 +194,8 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
glStencilFunc GL_EQUAL 0 255 glStencilFunc GL_EQUAL 0 255
glUseProgram (ltextShad ^. shadName) --Just (_shadProg ltextShad) glUseProgram (ltextShad ^. shadName) --Just (_shadProg ltextShad)
glUniform3f (_shadUnis ltextShad V.! 0) x y z glUniform3f 0 x y z
glUniform4f (_shadUnis ltextShad V.! 1) r g b rad glUniform4f 1 r g b rad
--bindVertexArrayObject $= ltextShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO ltextShad) --bindVertexArrayObject $= ltextShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO ltextShad)
glBindVertexArray $ ltextShad ^. shadVAO . vaoName -- Just (_vao $ _shadVAO ltextShad) glBindVertexArray $ ltextShad ^. shadVAO . vaoName -- Just (_vao $ _shadVAO ltextShad)
glDrawArrays glDrawArrays
-4
View File
@@ -24,14 +24,10 @@ drawShaderLay :: Int -> UMV.MVector (PrimState IO) Int -> Int -> (FullShader,VBO
{-# INLINE drawShaderLay #-} {-# INLINE drawShaderLay #-}
drawShaderLay l countsVector shadIn fs = do drawShaderLay l countsVector shadIn fs = do
i <- UMV.read countsVector shadIn i <- UMV.read countsVector shadIn
--currentProgram $= Just (_shadProg' fs)
glUseProgram (_shadName $ fst fs) glUseProgram (_shadName $ fst fs)
glBindVertexArray $ fs ^. _1 . shadVAO . vaoName glBindVertexArray $ fs ^. _1 . shadVAO . vaoName
--bindVertexArrayObject $= Just (_vaoName $ _shadVAO' fs)
case _shadTex' $ fst fs of case _shadTex' $ fst fs of
Just ShaderTexture{_textureObject = txo} --, _textureTarget = tt} Just ShaderTexture{_textureObject = txo} --, _textureTarget = tt}
-- -> textureBinding Texture2D $= Just txo
-- -> glBindTexture tt txo
-> glBindTextureUnit 0 txo -> glBindTextureUnit 0 txo
_ -> return () _ -> return ()
glDrawArrays glDrawArrays
-13
View File
@@ -2,7 +2,6 @@ module Shader.AuxAddition
( addSamplerTexture2D ( addSamplerTexture2D
, vaddTextureNoFilter , vaddTextureNoFilter
, addTextureArray , addTextureArray
, addUniforms
, initTexture2D , initTexture2D
, initTexture2DArray , initTexture2DArray
, tilesToLine -- ^ kept in case it is needed in the future , tilesToLine -- ^ kept in case it is needed in the future
@@ -10,10 +9,6 @@ module Shader.AuxAddition
import Data.Preload.Render import Data.Preload.Render
import Unsafe.Coerce import Unsafe.Coerce
import Shader.Data import Shader.Data
import Control.Monad
import qualified Data.ByteString as BS
import Data.ByteString.Char8 (pack)
import qualified Data.Vector as V
import Data.List.Extra import Data.List.Extra
import Codec.Picture import Codec.Picture
import qualified Data.Vector.Storable as VS import qualified Data.Vector.Storable as VS
@@ -142,11 +137,3 @@ tilesToLine
-> [a] -> [a]
-> [a] -> [a]
tilesToLine n w = concat . concat . transpose . chunksOf n . chunksOf w tilesToLine n w = concat . concat . transpose . chunksOf n . chunksOf w
addUniforms :: [String] -> FullShader -> IO FullShader
addUniforms uniStrings shad = do foldM addUniform shad uniStrings
addUniform :: FullShader -> String -> IO FullShader
addUniform shad unistr = BS.useAsCString (pack unistr) $ \cstr -> do
loc <- glGetUniformLocation (_shadName shad) cstr
return $ shad & shadUnis %~ (V.++ V.fromList [loc])
-5
View File
@@ -43,7 +43,6 @@ makeShader s shaderlist sizes pm = do
, _shadVAO = vao , _shadVAO = vao
, _shadPrim' = pm , _shadPrim' = pm
, _shadTex' = Nothing , _shadTex' = Nothing
, _shadUnis = mempty
} }
, vbo) , vbo)
@@ -67,7 +66,6 @@ makeShader4 s shaderlist sizes strd pm vbo = do
, _shadVAO = vao , _shadVAO = vao
, _shadPrim' = pm , _shadPrim' = pm
, _shadTex' = Nothing , _shadTex' = Nothing
, _shadUnis = mempty
} }
setupVBO :: Int -> IO VBO setupVBO :: Int -> IO VBO
@@ -108,7 +106,6 @@ makeByteStringShaderUsingVAO s shaderlist pm vao = do
, _shadVAO = vao , _shadVAO = vao
, _shadPrim' = pm , _shadPrim' = pm
, _shadTex' = Nothing , _shadTex' = Nothing
, _shadUnis = mempty
} }
-- | Takes the VAO from elsewhere -- | Takes the VAO from elsewhere
@@ -128,7 +125,6 @@ makeShaderUsingVAO s shaderlist pm theVAO = do
, _shadVAO = theVAO , _shadVAO = theVAO
, _shadPrim' = pm , _shadPrim' = pm
, _shadTex' = Nothing , _shadTex' = Nothing
, _shadUnis = mempty
} }
{- | {- |
@@ -154,7 +150,6 @@ makeShaderSized s shaderlist sizes ndraw pm = do
, _shadVAO = vao , _shadVAO = vao
, _shadPrim' = pm , _shadPrim' = pm
, _shadTex' = Nothing , _shadTex' = Nothing
, _shadUnis = mempty
} }
, vbo) , vbo)
-3
View File
@@ -28,13 +28,11 @@ module Shader.Data
, shadVAO , shadVAO
, shadPrim' , shadPrim'
, shadTex' , shadTex'
, shadUnis
-- | Synonyms -- | Synonyms
, vert , vert
, geom , geom
, frag , frag
) where ) where
import Data.Vector (Vector)
import Graphics.GL.Core45 import Graphics.GL.Core45
import Foreign import Foreign
import Control.Lens import Control.Lens
@@ -44,7 +42,6 @@ data FullShader = FullShader
, _shadVAO :: VAO , _shadVAO :: VAO
, _shadPrim' :: EPrimitiveMode , _shadPrim' :: EPrimitiveMode
, _shadTex' :: Maybe ShaderTexture , _shadTex' :: Maybe ShaderTexture
, _shadUnis :: Vector GLint
} }
{- | Vertex array object: contains the reference to the object, {- | Vertex array object: contains the reference to the object,
and its buffer targets. -} and its buffer targets. -}