Fix character array binding

This commit is contained in:
2023-03-23 14:59:20 +00:00
parent 05d1d3d1eb
commit b352d17f72
8 changed files with 15 additions and 126 deletions
-9
View File
@@ -1,9 +0,0 @@
#version 450 core
layout (location=0) out vec4 fColor;
uniform sampler2DArray thetexture;
in vec4 vColor;
in vec3 vTexCoord;
void main()
{
fColor = texture(thetexture, vec3 (vTexCoord.xyz)) * vColor;
}
-13
View File
@@ -1,13 +0,0 @@
#version 450 core
layout (location = 0) in vec3 inPos;
layout (location = 1) in vec4 inColor;
layout (location = 2) in vec4 inTexCoord;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
out vec4 vColor;
out vec3 vTexCoord;
void main()
{
gl_Position = theMat * vec4(inPos.xyz, 1.0);
vColor = inColor;
vTexCoord = inTexCoord.xyz;
}
-26
View File
@@ -1,26 +0,0 @@
#version 450 core
layout (location=0) out vec4 fCol;
layout (location=1) out vec4 fPos;
layout (location=2) out vec4 fNorm;
in vec2 tPos;
in vec3 gTexCoords;
in vec4 gPos;
in vec4 gNorm;
in vec4 gColor;
in float gRot;
layout (binding=40) uniform sampler2DArray diffuseSampler;
layout (binding=41) uniform sampler2DArray normalSampler;
vec2 rotateV2 (float a, vec2 v)
{
return vec2(v.x*cos(a) - v.y*sin(a), v.x*sin(a) + v.y*cos(a));
}
void main()
{
//fCol = gColor * texture(tex,tPos);
fCol = texture(diffuseSampler,gTexCoords);
fPos = gPos;
vec4 basenorm = texture(normalSampler,gTexCoords) - 0.5;
//fNorm = fPos - vec4(rotateV2(gRot,basenorm.xz), basenorm.y,0);
vec2 n = rotateV2(gRot,vec2(-basenorm.x,-basenorm.z));
fNorm = vec4(fPos.xyz - vec3(n,basenorm.y),0);
}
-50
View File
@@ -1,50 +0,0 @@
#version 450 core
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
in vec4 vColor [];
out vec4 gColor;
out vec2 tPos;
out vec4 gPos;
out vec4 gNorm;
out vec3 gTexCoords;
out float gRot;
// consider using isLHS to check if the wall is facing the center
float isLHS (vec2 startV, vec2 testV)
{ return sign( -startV.x * testV.y + startV.y * testV.x); }
void main()
{ gColor = vColor[0];
vec2 p1xy = gl_in[0].gl_Position.xy;
vec2 p2xy = gl_in[0].gl_Position.zw;
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1);
vec4 p3 = vec4 (p1.xy,100,1);
vec4 p4 = vec4 (p2.xy,100,1);
vec2 d = vec2(p1.xy - p2.xy);
float rot = atan(d.y,d.x);
float dist = distance(p1xy,p2xy);
float tcoordx = dist / 50;
float tcoordz = 11;
vec4 norm = vec4( d.y, -d.x, 0, 0);
gPos = p1; tPos = vec2 ( 1,-1) ; gl_Position = vec4(theMat * p1);
gNorm = gPos - norm;
gTexCoords = vec3 (0,0,tcoordz);
gRot = rot;
EmitVertex();
gPos = p3; tPos = vec2 ( 1, 1) ; gl_Position = vec4(theMat * p3);
gNorm = gPos - norm;
gTexCoords = vec3 (0,2,tcoordz);
gRot = rot;
EmitVertex();
gPos = p2; tPos = vec2 (-1,-1) ; gl_Position = vec4(theMat * p2);
gNorm = gPos - norm;
gTexCoords = vec3 (tcoordx,0,tcoordz);
gRot = rot;
EmitVertex();
gPos = p4; tPos = vec2 (-1, 1) ; gl_Position = vec4(theMat * p4);
gNorm = gPos - norm;
gTexCoords = vec3 (tcoordx,2,tcoordz);
gRot = rot;
EmitVertex();
EndPrimitive();
}
-9
View File
@@ -1,9 +0,0 @@
#version 450 core
layout (location = 0) in vec4 poss;
layout (location = 1) in vec4 color;
out vec4 vColor;
void main()
{
gl_Position = poss;
vColor = color;
}
+1 -2
View File
@@ -21,10 +21,9 @@ data RenderData = RenderData
, _shadowWallShader :: Shader
, _shadowLightShader :: (Shader,VBO)
, _shadowCombineShader :: (Shader,VBO)
, _positionalBlankShader :: (Shader,VBO)
--, _positionalBlankShader :: (Shader,VBO)
, _wallBlankShader :: Shader
, _windowShader :: Shader
, _wallTextureShader :: Shader
, _fullscreenShader :: Shader
, _bloomBlurShader :: Shader
, _colorBlurShader :: Shader
+9 -12
View File
@@ -22,6 +22,13 @@ import Shader.Data
import Shader.Parameters
import Graphics.GL.Core45
{- BINDING LIST:
0 base
40 texture array diffuse
41 texture array normals
50 charMapVert
-}
numDrawableWalls :: Int
numDrawableWalls = 5000
@@ -119,8 +126,6 @@ preloadRender = do
shadowcombineshader <- makeShaderSized "shadow/combine" [vert,geom,frag] [1] 1 pmPoints
poke (shadVBOptr shadowlightshader) 1
-- positional shader
positionalBlankShad <- makeShader "positional/blank" [vert, frag] [3] pmTriangles
-- 2D draw shaders
bslist <- makeShader "dualTwoD/basic" [vert, frag] [3, 4] pmTriangles
bslista <- makeShader4 "shape/basic" [vert, frag] shapeVerxSizes nShapeVerxComp pmTriangles shVBO
@@ -129,10 +134,8 @@ preloadRender = do
aslist <- makeShader "dualTwoD/arc" [vert, frag] [3, 4, 3] pmTriangles
eslist <- makeShader "dualTwoD/ellipse" [vert, geom, frag] [3, 4] pmTriangles
cslist <-
makeShader "picture/textureArray" [vert, frag] [3, 4, 4] pmTriangles
-- >>= _1 (addTextureArray' "data/texture/charMapVert.png" 2 16 32 95 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR)
>>= _1 (addTextureArray' "data/texture/charMapVert.png" 2 16 32 95 GL_NEAREST_MIPMAP_LINEAR GL_LINEAR)
-- this should really be a 2d texture array
makeShader "picture/charArray" [vert, frag] [3, 4, 4] pmTriangles
addBindTextureArray 50 "data/texture/charMapVert.png" 2 16 32 95 GL_NEAREST_MIPMAP_LINEAR GL_LINEAR
screentexturevbo <- mglCreate glCreateBuffers
withArray (concat cornerList) $ \ptr ->
@@ -152,9 +155,6 @@ preloadRender = do
barrelShad <- makeShader "texture/barrel" [vert, geom, frag] [2, 2, 2, 1] pmPoints
-- blank wallShader
wallBlankShad <- makeShaderUsingVAO "wall/blank" [vert, geom, frag] pmPoints wpColVAO
-- textured wallShader
wallTextureShad <-
makeShaderUsingVAO "wall/texture" [vert, geom, frag] pmPoints wpColVAO
let wallverxstrd = 8
wallvbo <- setupVBO wallverxstrd
wallshader <- makeShader4 "wall/basic" [vert,geom,frag] [4,4] wallverxstrd pmPoints wallvbo
@@ -220,11 +220,8 @@ preloadRender = do
, _shadowWallShader = shadowwallshader
, _shadowLightShader = shadowlightshader
, _shadowCombineShader = shadowcombineshader
, _positionalBlankShader = positionalBlankShad
, _wallBlankShader = wallBlankShad
, _wallTextureShader = wallTextureShad
, _windowShader = wallBlankShad{_shaderVAO = winColVAO}
-- , _textureArrayShader = textArrayShad
, _fullscreenShader = fsShad
, _alphaDivideShader = alphadivideshader
, _lightingTextureShader = lightingTextureShad
+5 -5
View File
@@ -2,7 +2,7 @@ module Shader.AuxAddition
( addSamplerTexture2D
, vaddTextureNoFilter
, addTextureArray
, addTextureArray'
, addBindTextureArray
, initTexture2D
, initTexture2DArray
, tilesToLine
@@ -128,9 +128,9 @@ addTextureArray texturePath (shad,vbo) = do
return (shad & shaderTextures .:~ TO texname
, vbo)
addTextureArray' :: String -> GLsizei -> GLsizei -> GLsizei -> GLsizei -> GLenum -> GLenum
-> Shader -> IO Shader
addTextureArray' fp nlev w h d minfilt magfilt shad = do
addBindTextureArray :: GLuint -> String -> GLsizei -> GLsizei -> GLsizei -> GLsizei -> GLenum -> GLenum
-> IO ()
addBindTextureArray bindpoint fp nlev w h d minfilt magfilt = do
Right cmap <- readImage fp
let texdata = convertRGBA8 cmap
texname <- mglCreate $ glCreateTextures GL_TEXTURE_2D_ARRAY
@@ -140,7 +140,7 @@ addTextureArray' fp nlev w h d minfilt magfilt shad = do
glGenerateTextureMipmap texname
glTextureParameteri texname GL_TEXTURE_MIN_FILTER (unsafeCoerce minfilt)
glTextureParameteri texname GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt)
return (shad & shaderTextures .:~ TO texname )
glBindTextureUnit bindpoint texname
tilesToLine
:: Int -- ^ Parameter a