From 695f849f77c353aa387b38a2d791ed42d8c9bf48 Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 20 Mar 2023 15:09:43 +0000 Subject: [PATCH] Add file --- shader/cloud/basic.frag | 16 ++++++++++++++ shader/cloud/basic.vert | 18 ++++++++++++++++ shader/floor/arrayPos.frag | 23 ++++++++++++++++++++ shader/floor/arrayPos.vert | 12 +++++++++++ shader/wall/basic.frag | 24 +++++++++++++++++++++ shader/wall/basic.geom | 44 ++++++++++++++++++++++++++++++++++++++ shader/wall/basic.vert | 9 ++++++++ 7 files changed, 146 insertions(+) create mode 100644 shader/cloud/basic.frag create mode 100644 shader/cloud/basic.vert create mode 100644 shader/floor/arrayPos.frag create mode 100644 shader/floor/arrayPos.vert create mode 100644 shader/wall/basic.frag create mode 100644 shader/wall/basic.geom create mode 100644 shader/wall/basic.vert diff --git a/shader/cloud/basic.frag b/shader/cloud/basic.frag new file mode 100644 index 000000000..a17f3f5d3 --- /dev/null +++ b/shader/cloud/basic.frag @@ -0,0 +1,16 @@ +#version 450 core +in vec4 vPosID; +in vec4 vCol; +in vec4 vCenterSize; +in vec4 vControls; +layout (location=0) out vec4 fCol; +layout (location=1) out vec4 fPos; +layout (location=2) out vec4 fNorm; +void main() +{ + float d = dot(vControls,vControls); + if (d > 1) {discard;} + fCol = vCol; + fPos = vec4(vPosID.xy, vPosID.z + (1-d) * vCenterSize.w, 1); + fNorm = vec4(vCenterSize.xyz - fPos.xyz, 1); +} diff --git a/shader/cloud/basic.vert b/shader/cloud/basic.vert new file mode 100644 index 000000000..6a817c65a --- /dev/null +++ b/shader/cloud/basic.vert @@ -0,0 +1,18 @@ +#version 450 core +layout (location = 0) in vec4 posID; +layout (location = 1) in vec4 col; +layout (location = 2) in vec4 centerSize; +layout (location = 3) in vec4 controls; +layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; +out vec4 vPosID; +out vec4 vCol; +out vec4 vCenterSize; +out vec4 vControls; +void main() +{ + gl_Position = theMat * vec4(posID.xyz,1); + vPosID = posID; + vCol = col; + vCenterSize = centerSize; + vControls = controls; +} diff --git a/shader/floor/arrayPos.frag b/shader/floor/arrayPos.frag new file mode 100644 index 000000000..8306f774d --- /dev/null +++ b/shader/floor/arrayPos.frag @@ -0,0 +1,23 @@ +#version 450 core +in vec4 vTexPosRot; +in vec2 vPos; +layout (location=0) out vec4 fCol; +layout (location=1) out vec4 fPos; +layout (location=2) out vec4 normal; +//layout (binding=0) uniform sampler2DArray tilesetSampler; +layout (binding=1) uniform sampler2DArray normalSampler; +layout (binding=2) uniform sampler2DArray diffuseSampler; +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() +{ + vec3 vTexPos = vTexPosRot.xyz; + float rot = vTexPosRot.w; + fCol = vec4(texture(diffuseSampler,vTexPos)); + fPos = vec4(vPos,0,1); + vec4 bn = vec4(texture(normalSampler,vTexPos) - 0.5); + vec3 nmap1 = vec3(rotateV2(rot,bn.xy), bn.z); + normal = vec4(-nmap1 ,0); +} diff --git a/shader/floor/arrayPos.vert b/shader/floor/arrayPos.vert new file mode 100644 index 000000000..b0c3f882e --- /dev/null +++ b/shader/floor/arrayPos.vert @@ -0,0 +1,12 @@ +#version 450 core +layout (location = 0) in vec4 posXX; +layout (location = 1) in vec4 texPosRot; +layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; +out vec4 vTexPosRot; +out vec2 vPos; +void main() +{ + vPos = posXX.xy; + gl_Position = theMat * vec4(vPos,0,1.0) ; + vTexPosRot = texPosRot; +} diff --git a/shader/wall/basic.frag b/shader/wall/basic.frag new file mode 100644 index 000000000..4031efe82 --- /dev/null +++ b/shader/wall/basic.frag @@ -0,0 +1,24 @@ +#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 gAng; +layout (binding=1) uniform sampler2DArray normalSampler; +layout (binding=2) uniform sampler2DArray diffuseSampler; +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 = texture(diffuseSampler,gTexCoords); + fPos = gPos; + vec4 basenorm = texture(normalSampler,gTexCoords) - 0.5; + vec2 n1 = rotateV2(gAng,vec2(basenorm.x,basenorm.z)); + fNorm = vec4(-vec3(n1,basenorm.y),0); +} diff --git a/shader/wall/basic.geom b/shader/wall/basic.geom new file mode 100644 index 000000000..5aca72490 --- /dev/null +++ b/shader/wall/basic.geom @@ -0,0 +1,44 @@ +#version 450 core +layout (points) in; +layout (triangle_strip, max_vertices = 4) out; +layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; +in vec2 vTexAng[]; +out float gAng; +out vec2 tPos; +out vec4 gPos; +out vec4 gNorm; +out vec3 gTexCoords; +// 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() +{ gAng = vTexAng[0].y; + float tcoordz = vTexAng[0].x; + 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 dist = distance(p1xy,p2xy); + float tcoordx = dist / 50; + 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); + EmitVertex(); + gPos = p3; tPos = vec2 ( 1, 1) ; gl_Position = vec4(theMat * p3); + gNorm = gPos - norm; + gTexCoords = vec3 (0,2,tcoordz); + EmitVertex(); + gPos = p2; tPos = vec2 (-1,-1) ; gl_Position = vec4(theMat * p2); + gNorm = gPos - norm; + gTexCoords = vec3 (tcoordx,0,tcoordz); + EmitVertex(); + gPos = p4; tPos = vec2 (-1, 1) ; gl_Position = vec4(theMat * p4); + gNorm = gPos - norm; + gTexCoords = vec3 (tcoordx,2,tcoordz); + EmitVertex(); + EndPrimitive(); +} diff --git a/shader/wall/basic.vert b/shader/wall/basic.vert new file mode 100644 index 000000000..0a9f29f7c --- /dev/null +++ b/shader/wall/basic.vert @@ -0,0 +1,9 @@ +#version 450 core +layout (location = 0) in vec4 poss; +layout (location = 1) in vec4 texAngXX; +out vec2 vTexAng; +void main() +{ + gl_Position = poss; + vTexAng = texAngXX.xy; +}