Setup multiple target basic shaders

This commit is contained in:
2021-08-31 20:05:15 +01:00
parent 146bab6fe3
commit cf77163b3f
21 changed files with 381 additions and 28 deletions
+13
View File
@@ -0,0 +1,13 @@
#version 430 core
in vec4 vColor;
in vec3 vPosition;
in vec3 vparams;
layout (location=0) out vec4 fColor;
layout (location=1) out vec3 fPosition;
void main()
{
float d = (dot(vec2(vparams.xy),vec2(vparams.xy)));
if ( d > 1 || d < vparams.z ) {discard;}
fColor = vColor;
fPosition = vPosition;
}
+37
View File
@@ -0,0 +1,37 @@
#version 430 core
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
in vec4 vColor [];
in vec4 vparams [];
out vec4 gColor;
out float gRadIn;
out vec2 angles;
out vec2 dist;
uniform mat4 worldMat;
void main()
{
angles = vparams[0].xy;
vec4 cenPos = gl_in[0].gl_Position;
gColor = vColor[0];
float width = vparams[0].w ;
float rad = vparams[0].z + width;
gRadIn = 1 - width * 2 / rad;
// I am not currently sure why the multiplicand is 4 and not 2
gl_Position = worldMat * vec4 (cenPos.x + rad, cenPos.y + rad, cenPos.z , 1);
dist = vec2 (1,1);
EmitVertex();
gl_Position = worldMat * vec4 (cenPos.x - rad, cenPos.y + rad, cenPos.z , 1);
dist = vec2 (-1,1);
EmitVertex();
gl_Position = worldMat * vec4 (cenPos.x + rad, cenPos.y - rad, cenPos.z , 1);
dist = vec2 (1,-1);
EmitVertex();
gl_Position = worldMat * vec4 (cenPos.x - rad, cenPos.y - rad, cenPos.z , 1);
dist = vec2 (-1,-1);
EmitVertex();
EndPrimitive();
}
+14
View File
@@ -0,0 +1,14 @@
#version 430 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec4 color;
layout (location = 2) in vec3 boxXboxYwidth;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
out vec4 vColor;
out vec3 vPosition;
out vec3 vparams;
void main() {
gl_Position = theMat * vec4(position,1);
vColor = color;
vparams = boxXboxYwidth;
vPosition = position;
}
+10
View File
@@ -0,0 +1,10 @@
#version 430 core
in vec4 vCol;
in vec3 vPos;
layout (location=0) out vec4 fCol;
layout (location=1) out vec3 fPos;
void main()
{
fCol = vCol;
fPos = vPos;
}
+11
View File
@@ -0,0 +1,11 @@
#version 430 core
layout (location = 0) in vec3 pos;
layout (location = 1) in vec4 col;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
out vec4 vCol;
out vec3 vPos;
void main() {
gl_Position = theMat * vec4(pos,1);
vCol = col;
vPos = pos;
}
+7
View File
@@ -0,0 +1,7 @@
#version 430 core
in vec4 vColor;
out vec4 fColor;
void main()
{
fColor = vColor;
}
+12
View File
@@ -0,0 +1,12 @@
#version 430 core
layout (location = 0) in vec4 position;
layout (location = 1) in vec4 color;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
out vec4 vColor;
void main()
{
vec4 posxy = theMat * vec4(position.xyz,1);
vec4 posz = theMat * vec4(position.xyw,1);
gl_Position = vec4(posxy.xy,posz.z,1);
vColor = color;
}
+16
View File
@@ -0,0 +1,16 @@
#version 430 core
in vec4 vColor;
in vec2 boxOut;
in vec2 boxIn;
out vec4 fColor;
void main()
{
//float d = x - y - 1 + 2* sqrt(y);
float d = sqrt(boxOut.x) + sqrt(boxOut.y) - 1.0;
// float e = sqrt(f(x,wStart)) + sqrt(f(y,wEnd)) - 1.0;
float e = sqrt(boxIn.x) + sqrt(boxIn.y) - 1.0;
if ( d < 0 || e > 0) { discard; }
fColor = vColor;
}
+76
View File
@@ -0,0 +1,76 @@
#version 430 core
layout (triangles) in;
layout (triangle_strip, max_vertices = 5) out;
in vec4 vColor[];
in vec2 vPosOff[];
in float vRadMag[];
out vec4 gColor;
out float wStart;
out float wEnd;
out vec3 gBoundingBox;
out vec2 box2 ;
vec2 normV2 (vec2 v)
{ return vec2(-v.y,v.x) ;
}
float lhs (vec2 da, vec2 db)
{ return sign(dot(da, normV2(db))) ;
}
float extrapolate (vec2 inOne, vec2 inZeroA, vec2 inZeroB, vec2 xy)
{
float det = inOne.x * (inZeroA.y - inZeroB.y)
+ inZeroA.x * (inZeroB.y - inOne.y)
+ inZeroB.x * (inOne.y - inZeroA.y)
;
float r = (inZeroA.y - inZeroB.y) ;
float s = (inZeroB.x - inZeroA.x) ;
float t = (inZeroA.x * inZeroB.y - inZeroB.x * inZeroA.y) ;
return r * xy.x + s * xy.y + t
/ det ;
}
void main()
{
vec3 pa = gl_in[0].gl_Position.xyz;
vec3 pb = gl_in[1].gl_Position.xyz;
vec3 pc = gl_in[2].gl_Position.xyz;
wStart = vRadMag [0];
wEnd = vRadMag [2];
box2 = vec2 (1,0);
gBoundingBox = vec3 (0.9,0.1,0);
gColor = vColor[0];
gl_Position = vec4 (vPosOff[0] , pa.z , 1);
EmitVertex();
box2 = vec2 (0,1);
gBoundingBox = vec3 (0.1,0.9,0);
gColor = vColor[2];
gl_Position = vec4 (vPosOff[2] , pc.z , 1);
EmitVertex();
box2 = vec2( extrapolate(vPosOff[0],vPosOff[2],pb.xy,pa.xy)
, extrapolate(vPosOff[2],vPosOff[0],pb.xy,pa.xy)
) ;
box2 = vec2(0.2,0);
gBoundingBox = vec3 (1,0,1);
gColor = vColor[0];
gl_Position = vec4 (pa, 1);
EmitVertex();
box2 = vec2( extrapolate(vPosOff[0],vPosOff[2],pb.xy,pc.xy)
, extrapolate(vPosOff[2],vPosOff[0],pb.xy,pc.xy)
) ;
box2 = vec2(0,0.2);
gBoundingBox = vec3 (0,1,1);
gColor = vColor[2];
gl_Position = vec4 (pc, 1);
EmitVertex();
box2 = vec2( 0,0 ) ;
gBoundingBox = vec3 (0,0,0);
gColor = vColor[1];
gl_Position = vec4 (pb, 1);
EmitVertex();
EndPrimitive();
}
+15
View File
@@ -0,0 +1,15 @@
#version 430 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec4 color;
layout (location = 2) in vec4 boxes;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
out vec4 vColor;
out vec2 boxOut;
out vec2 boxIn;
void main()
{
gl_Position = theMat * vec4(position.xyz,1);
vColor = color;
boxOut = boxes.xy ;
boxIn = boxes.zw ;
}
+15
View File
@@ -0,0 +1,15 @@
#version 430 core
out vec4 FragColor;
in vec4 gColor;
in vec2 gTexCoord;
uniform sampler2D aTexture;
void main()
{
FragColor = texture(aTexture, vec2 (gTexCoord.x * 0.0078125, gTexCoord.y)) * gColor;
// FragColor = texture(aTexture, vTexCoord);
// FragColor = gColor;
// FragColor = vec4 (1,1,1,1);
}
+35
View File
@@ -0,0 +1,35 @@
#version 430 core
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
in vec4 vColor [];
in vec3 vTexCoord [];
out vec4 gColor;
out vec2 gTex;
void main()
{
vec3 cenPos = gl_in[0].gl_Position.xyz;
float sizex = vTexCoord[0].y;
float sizey = vTexCoord[0].z;
//float size = 0.05;
gColor = vColor[0];
float texPos = vTexCoord[0].x;
gl_Position = vec4 (cenPos.x - sizex*0.5, cenPos.y - sizey*0.5, cenPos.z , 1);
//gl_Position = vec4 (0, 0 , 5 , 1);
gTex = vec2 (texPos*0.0078125, 1);
EmitVertex();
gl_Position = vec4 (cenPos.x - sizex*0.5, cenPos.y + sizey*0.5, cenPos.z , 1);
//gl_Position = vec4 (0, 0.5 , 5 , 1);
gTex = vec2 (texPos*0.0078125, 0);
EmitVertex();
gl_Position = vec4 (cenPos.x + sizex*0.5, cenPos.y - sizey*0.5, cenPos.z , 1);
//gl_Position = vec4 (0.5, 0.5 , -5 , 1);
gTex = vec2 ((texPos+1)*0.0078125, 1);
EmitVertex();
gl_Position = vec4 (cenPos.x + sizex*0.5, cenPos.y + sizey*0.5, cenPos.z , 1);
gTex = vec2 ((texPos+1)*0.0078125, 0);
//gl_Position = vec4 (0.5, 0 , -5 , 1);
EmitVertex();
EndPrimitive();
}
+13
View File
@@ -0,0 +1,13 @@
#version 430 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec4 aColor;
layout (location = 2) in vec2 aTexCoord;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
out vec4 gColor;
out vec2 gTexCoord;
void main()
{
gl_Position = theMat * vec4(aPos, 1.0);
gColor = aColor;
gTexCoord = aTexCoord;
}
+16
View File
@@ -0,0 +1,16 @@
#version 430 core
in vec4 gColC;
in vec4 gColE;
in vec3 gPos;
in vec2 gBoundingBox;
layout (location=0) out vec4 fCol;
layout (location=1) out vec3 fPos;
void main()
{
float d = dot(gBoundingBox,gBoundingBox);
if ( d > 1) { discard; }
fCol = mix (gColE , gColC, d);
fPos = vPos;
}
+40
View File
@@ -0,0 +1,40 @@
#version 430 core
layout (triangles) in;
layout (triangle_strip, max_vertices = 4) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
in vec4 vCol[];
out vec4 gColC; // center color
out vec4 gColE; // edge color
out vec2 gBoundingBox;
out vec3 gPos;
void main()
{
vec4 pat = gl_in[0].gl_Position;
vec4 pbt = gl_in[1].gl_Position;
vec4 pct = gl_in[2].gl_Position;
vec4 pa = theMat * pat;
vec4 pb = theMat * pbt;
vec4 pc = theMat * pct;
gColC = vCol[0];
gColE = vCol[1];
gBoundingBox = vec2 (-1,1);
gl_Position = pb;
gPos = pbt.xyz;
EmitVertex();
gBoundingBox = vec2 (1,1);
gl_Position = pa;
gPos = pat.xyz;
EmitVertex();
gBoundingBox = vec2 (-1,-1);
gl_Position = pc;
gPos = pct.xyz;
EmitVertex();
gBoundingBox = vec2 (1,-1);
gl_Position = pa + pc - pb;
gPos = pat.xyz + pct.xyz - pbt.xyz;
EmitVertex();
EndPrimitive();
}
+11
View File
@@ -0,0 +1,11 @@
#version 430 core
layout (location = 0) in vec3 pos;
layout (location = 1) in vec4 col;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
out vec4 vCol;
void main()
{
//gl_Position = theMat * vec4(pos,1);
gl_Position = vec4(pos,1);
vCol = col;
}
+3 -1
View File
@@ -35,9 +35,11 @@ data RenderData = RenderData
, _fboBase :: (FramebufferObject, TextureObject)
, _fboBloom :: (FramebufferObject, TextureObject)
, _fboColor :: (FramebufferObject, TextureObject)
, _fboPos :: (FramebufferObject, TextureObject)
, _rboBaseBloom :: RenderbufferObject
, _fboLighting :: (FramebufferObject, TextureObject)
, _rboLighting :: RenderbufferObject
, _fboLightingHigh :: (FramebufferObject, TextureObject)
--, _rboLighting :: RenderbufferObject
, _matUBO :: BufferObject
}
makeLenses ''RenderData
+5 -5
View File
@@ -358,30 +358,30 @@ miniGun = defaultAutoGun
[ ammoCheckI
, withWarmUpI 26
, useTimeCheckI
, withRecoilI recoilAmount
--, afterRecoil recoilAmount
, withSoundForI 28 2
--, withThinSmokeI
, torqueAfterI 0.05
, withSidePushI 53
, withRecoilI recoilAmount
, afterRecoil recoilAmount
, withRandomOffsetI 12
, trigDoAlso (useAmmoParamsVelMod vm1)
--, torqueBeforeForcedI 0.001
, withSidePushI 52
, withRecoilI recoilAmount
, afterRecoil recoilAmount
, withRandomOffsetI 11
, withOldDir od1
, trigDoAlso (useAmmoParamsVelMod vm2)
--, torqueBeforeForcedI 0.001
, withSidePushI 51
, withRecoilI recoilAmount
, afterRecoil recoilAmount
, withRandomOffsetI 10
, withOldDir od2
, trigDoAlso (useAmmoParamsVelMod vm3)
, useAmmo 4
--, torqueBeforeForcedI 0.001
, withSidePushI 50
, withRecoilI recoilAmount
, afterRecoil recoilAmount
, withRandomOffsetI 9
, withMuzFlareI
, withOldDir od3
+8 -5
View File
@@ -23,11 +23,14 @@ sizeFBOs
-> IO RenderData
sizeFBOs xsize ysize xfull yfull rdata = do
resizeRBO (_rboBaseBloom rdata) xsize ysize
resizeRBO (_rboLighting rdata) xsize ysize
rdata' <- foldM (updateFBOTO xsize ysize minMagFilter GL_RGBA8) rdata [fboBase, fboColor,fboLighting]
rdata'' <- updateFBOTO xsize ysize linMinMagFilter GL_RGBA16F rdata' fboBloom
rdata''' <- foldM (updateFBOTO xfull yfull minMagFilter GL_RGBA8) rdata'' [fbo2, fbo3]
foldM (updateFBOTO (xsize `div` 2) (ysize `div` 2) linMinMagFilter GL_RGBA16F) rdata''' [fboFourth1,fboFourth2]
rdata' <- foldM (updateFBOTO xsize ysize minMagFilter GL_RGBA8) rdata
[fboBase, fboColor,fboLighting,fboLightingHigh]
rdata'' <- foldM (updateFBOTO xsize ysize linMinMagFilter GL_RGBA16F) rdata'
[fboBloom, fboPos]
rdata''' <- foldM (updateFBOTO xfull yfull minMagFilter GL_RGBA8) rdata''
[fbo2, fbo3]
foldM (updateFBOTO (xsize `div` 2) (ysize `div` 2) linMinMagFilter GL_RGBA16F) rdata'''
[fboFourth1,fboFourth2]
resizeRBO
:: RenderbufferObject
+8 -3
View File
@@ -68,7 +68,7 @@ preloadRender = do
<- makeShader "lighting/lineShadow" [vert,geom,frag] [3] ELinesAdjacency
>>= addUniforms ["lightPos"]
-- 2D draw shaders
bslist <- makeShader "twoD/basic" [vert,frag] [3,4] ETriangles
bslist <- makeShader "dualTwoD/basic" [vert,frag] [3,4] ETriangles
aslist <- makeShader "twoD/arc" [vert,frag] [3,4,3] ETriangles
eslist <- makeShader "twoD/ellipse" [vert,geom,frag] [3,4] ETriangles
bezierQuadShader <- makeShader "twoD/bezierQuad" [vert,frag] [3,4,4] ETriangleStrip
@@ -104,7 +104,7 @@ preloadRender = do
rboLightingName <- genObjectName
bindRenderbuffer Renderbuffer $= rboLightingName
renderbufferStorage Renderbuffer Depth24Stencil8 (RenderbufferSize 800 600)
fboLightingName <- setupFramebufferGivenStencil rboLightingName
--fboLightingName <- setupFramebufferGivenStencil rboLightingName
rboBaseBloomName <- genObjectName
bindRenderbuffer Renderbuffer $= rboBaseBloomName
@@ -113,6 +113,9 @@ preloadRender = do
fboBaseName <- setupFramebufferGivenStencil rboBaseBloomName
fboBloomName <- setupFramebufferGivenStencil rboBaseBloomName
fboColorName <- setupFramebufferGivenStencil rboBaseBloomName
fboPosName <- setupFramebufferGivenStencil rboBaseBloomName
fboLightingName <- setupFramebufferGivenStencil rboBaseBloomName
fboLightingHighName <- setupFramebufferGivenStencil rboBaseBloomName
fboFourth1Name <- setupTextureFramebuffer 300 300
fboFourth2Name <- setupTextureFramebuffer 300 300
@@ -154,10 +157,12 @@ preloadRender = do
, _fboFourth1 = fboFourth1Name
, _fboFourth2 = fboFourth2Name
, _fboLighting = fboLightingName
, _rboLighting = rboLightingName
, _fboLightingHigh = fboLightingHighName
--, _rboLighting = rboLightingName
, _fboBase = fboBaseName
, _fboBloom = fboBloomName
, _fboColor = fboColorName
, _fboPos = fboPosName
, _rboBaseBloom = rboBaseBloomName
, _matUBO = theUBO
}
+16 -14
View File
@@ -35,20 +35,22 @@ createLightMap pdata lightPoints nWalls nSils nsurfVs = do
-- clear buffer to full alpha and furthest depth
-- clearColor is specified in preloadRender
clearColor $= Color4 1 1 1 1
clear [ColorBuffer,DepthBuffer]
--colorMask $= Color4 Disabled Disabled Disabled Disabled
cullFace $= Just Back
cullFace $= Nothing
-- we assume that the camera position uniforms have been correctly set elsewhere
-- draw wall surfaces from the camera's point of view in order to set z buffer
drawShader (_lightingWallShader pdata) nWalls
-- draw foreground elements the camera's your point of view to set z buffer
drawShader (_lightingSurfaceShader pdata) nsurfVs
-- draw wall occlusions from the camera's point of view
drawShader (_lightingOccludeShader pdata) nWalls
--hypothesis: the above three draw calls only work because the
--uniform was set to your position, that being the last light source in the list
--if this hypothesis is correct, then the code is brittle and should be changed
clear [ColorBuffer]
-- we assume that the renderbuffer's depth has been correctly set elsewhere
-- clear [ColorBuffer,DepthBuffer]
-- --colorMask $= Color4 Disabled Disabled Disabled Disabled
-- cullFace $= Just Back
-- cullFace $= Nothing
-- -- we assume that the camera position uniforms have been correctly set elsewhere
-- -- draw wall surfaces from the camera's point of view in order to set z buffer
-- drawShader (_lightingWallShader pdata) nWalls
-- -- draw foreground elements the camera's your point of view to set z buffer
-- drawShader (_lightingSurfaceShader pdata) nsurfVs
-- -- draw wall occlusions from the camera's point of view
-- drawShader (_lightingOccludeShader pdata) nWalls
-- --hypothesis: the above three draw calls only work because the
-- --uniform was set to your position, that being the last light source in the list
-- --if this hypothesis is correct, then the code is brittle and should be changed
-- for each of the lights:
-- stencil out the walls from this light's point of view