diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-01 17:56:26 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-01 17:56:26 +0000 |
commit | d5cdbbf38380239524e351cb69aec94090884ca5 (patch) | |
tree | 5d7dff2f2775701069806eceb4eaef23b22eba3f /gfx/gl/shaders | |
parent | Reformat with new clang-format (diff) | |
parent | Remove more use of legacy types (diff) | |
download | ilt-d5cdbbf38380239524e351cb69aec94090884ca5.tar.bz2 ilt-d5cdbbf38380239524e351cb69aec94090884ca5.tar.xz ilt-d5cdbbf38380239524e351cb69aec94090884ca5.zip |
Merge remote-tracking branch 'origin/terrain'
Diffstat (limited to 'gfx/gl/shaders')
-rw-r--r-- | gfx/gl/shaders/commonPoint.glsl | 6 | ||||
-rw-r--r-- | gfx/gl/shaders/commonShadowPoint.glsl | 3 | ||||
-rw-r--r-- | gfx/gl/shaders/directionalLight.fs | 9 | ||||
-rw-r--r-- | gfx/gl/shaders/dynamicPoint.vs | 2 | ||||
-rw-r--r-- | gfx/gl/shaders/dynamicPointInst.vs | 2 | ||||
-rw-r--r-- | gfx/gl/shaders/fixedPoint.vs | 2 | ||||
-rw-r--r-- | gfx/gl/shaders/landmass.fs | 8 | ||||
-rw-r--r-- | gfx/gl/shaders/material.fs | 2 | ||||
-rw-r--r-- | gfx/gl/shaders/materialOut.glsl | 2 | ||||
-rw-r--r-- | gfx/gl/shaders/pointLight.fs | 4 | ||||
-rw-r--r-- | gfx/gl/shaders/pointLight.gs | 1 | ||||
-rw-r--r-- | gfx/gl/shaders/pointLight.vs | 5 | ||||
-rw-r--r-- | gfx/gl/shaders/shadowDynamicPoint.vs | 2 | ||||
-rw-r--r-- | gfx/gl/shaders/shadowDynamicPointInst.vs | 2 | ||||
-rw-r--r-- | gfx/gl/shaders/shadowFixedPoint.vs | 2 | ||||
-rw-r--r-- | gfx/gl/shaders/spotLight.fs | 4 | ||||
-rw-r--r-- | gfx/gl/shaders/spotLight.gs | 1 | ||||
-rw-r--r-- | gfx/gl/shaders/spotLight.vs | 5 | ||||
-rw-r--r-- | gfx/gl/shaders/water.fs | 5 | ||||
-rw-r--r-- | gfx/gl/shaders/water.vs | 9 |
20 files changed, 46 insertions, 30 deletions
diff --git a/gfx/gl/shaders/commonPoint.glsl b/gfx/gl/shaders/commonPoint.glsl index 35510e1..a9817fb 100644 --- a/gfx/gl/shaders/commonPoint.glsl +++ b/gfx/gl/shaders/commonPoint.glsl @@ -16,13 +16,11 @@ getMaterialDetail(uint midx) void main() { - vec4 worldPos = model * vec4(position, 1.0); - - FragPos = worldPos.xyz; + FragPos = (model * vec4(position, 1.0)).xyz + modelPos; TexCoords = texCoord; Normal = (model * vec4(normal, 0.0)).xyz; Colour = colour; Material = getMaterialDetail(material); - gl_Position = viewProjection * worldPos; + gl_Position = viewProjection * vec4(FragPos - viewPoint, 1); } diff --git a/gfx/gl/shaders/commonShadowPoint.glsl b/gfx/gl/shaders/commonShadowPoint.glsl index c7cbd3e..216642e 100644 --- a/gfx/gl/shaders/commonShadowPoint.glsl +++ b/gfx/gl/shaders/commonShadowPoint.glsl @@ -1,6 +1,7 @@ void main() { - gl_Position = viewProjection * model * vec4(position, 1.0); + vec4 worldPos = model * vec4(position, 1.0); + gl_Position = viewProjection * vec4(worldPos.xyz - viewPoint + modelPos, 1); gl_Position.z = max(gl_Position.z, -1); } diff --git a/gfx/gl/shaders/directionalLight.fs b/gfx/gl/shaders/directionalLight.fs index ca10ef5..f36d83f 100644 --- a/gfx/gl/shaders/directionalLight.fs +++ b/gfx/gl/shaders/directionalLight.fs @@ -7,12 +7,13 @@ out vec3 FragColor; in vec2 TexCoords; -layout(binding = 0) uniform sampler2D gPosition; +layout(binding = 0) uniform isampler2D gPosition; layout(binding = 1) uniform sampler2D gNormal; layout(binding = 2) uniform sampler2D shadowMap; uniform vec3 lightDirection; uniform vec3 lightColour; +uniform ivec3 lightPoint; uniform mat4 lightViewProjection[MAX_MAPS]; uniform vec4 shadowMapRegion[MAX_MAPS]; uniform uint lightViewProjectionCount; @@ -27,10 +28,10 @@ insideShadowCube(vec3 v) } float -isShaded(vec3 Position) +isShaded(vec4 Position) { for (uint m = 0u; m < lightViewProjectionCount; m++) { - vec3 PositionInLightSpace = (lightViewProjection[m] * vec4(Position, 1.0f)).xyz; + const vec3 PositionInLightSpace = (lightViewProjection[m] * Position).xyz; const float inside = insideShadowCube(PositionInLightSpace); if (inside > 0) { const float lightSpaceDepth @@ -44,7 +45,7 @@ isShaded(vec3 Position) void main() { - const vec3 Position = texture(gPosition, TexCoords).xyz; + const vec4 Position = vec4(texture(gPosition, TexCoords).xyz - lightPoint, 1); const vec3 Normal = texture(gNormal, TexCoords).rgb; const float shaded = isShaded(Position); FragColor = (1 - shaded) * max(dot(-lightDirection, Normal) * lightColour, 0); diff --git a/gfx/gl/shaders/dynamicPoint.vs b/gfx/gl/shaders/dynamicPoint.vs index 961535c..097cd11 100644 --- a/gfx/gl/shaders/dynamicPoint.vs +++ b/gfx/gl/shaders/dynamicPoint.vs @@ -5,6 +5,8 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; +uniform ivec3 viewPoint; uniform mat4 model; +uniform ivec3 modelPos; include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/dynamicPointInst.vs b/gfx/gl/shaders/dynamicPointInst.vs index 2d6cee5..529fe1d 100644 --- a/gfx/gl/shaders/dynamicPointInst.vs +++ b/gfx/gl/shaders/dynamicPointInst.vs @@ -5,6 +5,8 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; +uniform ivec3 viewPoint; layout(location = 5) in mat4 model; +layout(location = 9) in ivec3 modelPos; include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/fixedPoint.vs b/gfx/gl/shaders/fixedPoint.vs index ed78c96..3cea737 100644 --- a/gfx/gl/shaders/fixedPoint.vs +++ b/gfx/gl/shaders/fixedPoint.vs @@ -5,6 +5,8 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; +uniform ivec3 viewPoint; const mat4 model = mat4(1); +const vec3 modelPos = ivec3(0); include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/landmass.fs b/gfx/gl/shaders/landmass.fs index 4dc92bb..fc43bf2 100644 --- a/gfx/gl/shaders/landmass.fs +++ b/gfx/gl/shaders/landmass.fs @@ -11,9 +11,9 @@ const vec3 rock = vec3(.2, .2, .1); const vec3 sand = vec3(.76, .7, .5); const vec3 snow = vec3(.97, .97, .99); -const float beachline = .5; -const float snowline_low = 28; -const float snowline_high = 30; +const float beachline = 500; +const float snowline_low = 28000; +const float snowline_high = 30000; const float slope_min = .99; const float slope_mid = .95; @@ -60,7 +60,7 @@ main() } } - gPosition = vec4(FragPos, 1); + gPosition = ivec4(FragPos, 1); gNormal = vec4(Normal, 1); gAlbedoSpec = vec4(color, 1); } diff --git a/gfx/gl/shaders/material.fs b/gfx/gl/shaders/material.fs index 20fa8ab..5b93707 100644 --- a/gfx/gl/shaders/material.fs +++ b/gfx/gl/shaders/material.fs @@ -42,7 +42,7 @@ main() { vec4 textureColour = getTextureColour(Material, TexCoords); float opaque = step(0.5, mix(textureColour.a, 1, Colour.a)); - gPosition = vec4(FragPos, opaque); + gPosition = ivec4(FragPos, opaque); gNormal = vec4(Normal, opaque); gl_FragDepth = mix(1.0, gl_FragCoord.z, opaque); gAlbedoSpec = mix(textureColour, vec4(Colour.rgb, 1), Colour.a); diff --git a/gfx/gl/shaders/materialOut.glsl b/gfx/gl/shaders/materialOut.glsl index dc5f8e8..846825e 100644 --- a/gfx/gl/shaders/materialOut.glsl +++ b/gfx/gl/shaders/materialOut.glsl @@ -1,3 +1,3 @@ -layout(location = 0) out vec4 gPosition; +layout(location = 0) out ivec4 gPosition; layout(location = 1) out vec4 gNormal; layout(location = 2) out vec4 gAlbedoSpec; diff --git a/gfx/gl/shaders/pointLight.fs b/gfx/gl/shaders/pointLight.fs index bd32c05..ba327b6 100644 --- a/gfx/gl/shaders/pointLight.fs +++ b/gfx/gl/shaders/pointLight.fs @@ -3,7 +3,7 @@ out vec3 FragColor; -layout(binding = 0) uniform sampler2D gPosition; +layout(binding = 0) uniform isampler2D gPosition; layout(binding = 1) uniform sampler2D gNormal; uniform ivec4 viewPort; uniform vec3 colour; @@ -26,5 +26,5 @@ main() if (normalDot < 0) { discard; } - FragColor = (colour * normalDot) / (1 + (kq * pow(lightDist, 2))); + FragColor = (colour * normalDot) / (1 + (kq * pow(lightDist / 1000.0, 2))); } diff --git a/gfx/gl/shaders/pointLight.gs b/gfx/gl/shaders/pointLight.gs index 03d131d..9c41ed4 100644 --- a/gfx/gl/shaders/pointLight.gs +++ b/gfx/gl/shaders/pointLight.gs @@ -19,6 +19,7 @@ const vec3[] cube = vec3[]( // http://www.cs.umd.edu/gvil/papers/av_ts.pdf vec3(1, 1, -1) // Back-top-right ); uniform mat4 viewProjection; +uniform ivec3 viewPoint; in vec3 centre[]; in float size[]; diff --git a/gfx/gl/shaders/pointLight.vs b/gfx/gl/shaders/pointLight.vs index 35682fa..00a34a3 100644 --- a/gfx/gl/shaders/pointLight.vs +++ b/gfx/gl/shaders/pointLight.vs @@ -4,6 +4,7 @@ layout(location = 0) in vec3 position; uniform vec3 colour; uniform float kq; +uniform ivec3 viewPoint; out vec3 centre; out float size; @@ -12,6 +13,6 @@ void main() { centre = position; - size = (8 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); - gl_Position = vec4(centre, 0); + size = (8000 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); + gl_Position = vec4(centre - viewPoint, 0); } diff --git a/gfx/gl/shaders/shadowDynamicPoint.vs b/gfx/gl/shaders/shadowDynamicPoint.vs index f3ed533..f21b3b6 100644 --- a/gfx/gl/shaders/shadowDynamicPoint.vs +++ b/gfx/gl/shaders/shadowDynamicPoint.vs @@ -3,6 +3,8 @@ include(`meshIn.glsl') uniform mat4 viewProjection; +uniform ivec3 viewPoint; uniform mat4 model; +uniform ivec3 modelPos; include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowDynamicPointInst.vs b/gfx/gl/shaders/shadowDynamicPointInst.vs index 1bf74ef..28a62d9 100644 --- a/gfx/gl/shaders/shadowDynamicPointInst.vs +++ b/gfx/gl/shaders/shadowDynamicPointInst.vs @@ -3,6 +3,8 @@ include(`meshIn.glsl') uniform mat4 viewProjection; +uniform ivec3 viewPoint; layout(location = 5) in mat4 model; +layout(location = 9) in ivec3 modelPos; include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowFixedPoint.vs b/gfx/gl/shaders/shadowFixedPoint.vs index 8921707..168d5f1 100644 --- a/gfx/gl/shaders/shadowFixedPoint.vs +++ b/gfx/gl/shaders/shadowFixedPoint.vs @@ -3,6 +3,8 @@ include(`meshIn.glsl') uniform mat4 viewProjection; +uniform ivec3 viewPoint; const mat4 model = mat4(1); +const ivec3 modelPos = ivec3(0); include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/spotLight.fs b/gfx/gl/shaders/spotLight.fs index add86fd..937f922 100644 --- a/gfx/gl/shaders/spotLight.fs +++ b/gfx/gl/shaders/spotLight.fs @@ -3,7 +3,7 @@ out vec3 FragColor; -layout(binding = 0) uniform sampler2D gPosition; +layout(binding = 0) uniform isampler2D gPosition; layout(binding = 1) uniform sampler2D gNormal; uniform ivec4 viewPort; uniform vec3 colour; @@ -30,5 +30,5 @@ main() if (normalDot < 0) { discard; } - FragColor = (colour * normalDot) / (1 + (kq * pow(lightDist, 2))); + FragColor = (colour * normalDot) / (1 + (kq * pow(lightDist / 1000.0, 2))); } diff --git a/gfx/gl/shaders/spotLight.gs b/gfx/gl/shaders/spotLight.gs index ad65675..b58c169 100644 --- a/gfx/gl/shaders/spotLight.gs +++ b/gfx/gl/shaders/spotLight.gs @@ -10,6 +10,7 @@ const vec3[] pyramid = vec3[]( // four-sided vec3(1, -1, 1) // Front-right ); uniform mat4 viewProjection; +uniform ivec3 viewPoint; uniform float arc; in vec3 position[]; diff --git a/gfx/gl/shaders/spotLight.vs b/gfx/gl/shaders/spotLight.vs index dca0854..ac1d1db 100644 --- a/gfx/gl/shaders/spotLight.vs +++ b/gfx/gl/shaders/spotLight.vs @@ -6,6 +6,7 @@ uniform vec3 v_direction; uniform vec3 colour; uniform float kq; uniform float arc; +uniform ivec3 viewPoint; out vec3 position; out vec3 direction; @@ -17,7 +18,7 @@ main() { position = v_position; direction = normalize(v_direction); - size = (8 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); + size = (8000 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); cosarc = cos(arc / 2); - gl_Position = vec4(position, 0); + gl_Position = vec4(position - viewPoint, 0); } diff --git a/gfx/gl/shaders/water.fs b/gfx/gl/shaders/water.fs index 04aa94c..8891733 100644 --- a/gfx/gl/shaders/water.fs +++ b/gfx/gl/shaders/water.fs @@ -5,13 +5,12 @@ include(`materialInterface.glsl') include(`materialOut.glsl') uniform sampler2D texture0; -uniform vec3 waves; void main() { - gPosition = vec4(FragPos, 1); + gPosition = ivec4(FragPos, 1); gNormal = vec4(Normal, 1); gAlbedoSpec = texture(texture0, TexCoords); - gAlbedoSpec.a *= clamp(-FragPos.z * .7, .1, 1.0); + gAlbedoSpec.a *= clamp(-FragPos.z * .0007, .1, 1.0); } diff --git a/gfx/gl/shaders/water.vs b/gfx/gl/shaders/water.vs index a21b49f..f6c7c8f 100644 --- a/gfx/gl/shaders/water.vs +++ b/gfx/gl/shaders/water.vs @@ -4,17 +4,18 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; -uniform vec3 waves; +uniform ivec3 viewPoint; +uniform float waves; void main() { - vec4 wpos = vec4(position.x + cos(waves.x), position.y + cos(waves.x * waves.y / 2), - cos(waves.x + position.x + (position.y / 8)) * .3, 1.0); + vec3 wpos = vec3(position.x + (cos(waves) * 1000.0), position.y + (cos(waves * 0 / 2) * 1000.0), + cos(waves + (position.x / 1000000.0) + (position.y / 8000.0)) * 300.0); FragPos = vec3(wpos.xy, position.z); TexCoords = texCoord; Normal = normal; - gl_Position = viewProjection * wpos; + gl_Position = viewProjection * vec4(wpos - viewPoint, 1.0); } |