summaryrefslogtreecommitdiff
path: root/gfx/gl
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-02-20 01:01:42 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-02-20 01:06:47 +0000
commitd8c0bee891a9bc30bebcd5682bdba4d5b21cfd5b (patch)
tree0272b77e896819efabe7c77db388d562d78da86a /gfx/gl
parentCustom land and water shaders (diff)
downloadilt-d8c0bee891a9bc30bebcd5682bdba4d5b21cfd5b.tar.bz2
ilt-d8c0bee891a9bc30bebcd5682bdba4d5b21cfd5b.tar.xz
ilt-d8c0bee891a9bc30bebcd5682bdba4d5b21cfd5b.zip
Remove spare bits from shaders and tidy up
Diffstat (limited to 'gfx/gl')
-rw-r--r--gfx/gl/shaders/basicShader.fs2
-rw-r--r--gfx/gl/shaders/landmassShader.fs20
-rw-r--r--gfx/gl/shaders/landmassShader.vs4
-rw-r--r--gfx/gl/shaders/waterShader.vs7
4 files changed, 13 insertions, 20 deletions
diff --git a/gfx/gl/shaders/basicShader.fs b/gfx/gl/shaders/basicShader.fs
index b6c011d..fe9a6b3 100644
--- a/gfx/gl/shaders/basicShader.fs
+++ b/gfx/gl/shaders/basicShader.fs
@@ -11,5 +11,5 @@ uniform vec3 ambientColor;
void main()
{
gl_FragColor = texture(sampler, texCoord0);
- gl_FragColor.xyz *= clamp(ambientColor + (dot(-lightDirection, normal0) * lightColor), 0.0, 1.0);
+ gl_FragColor.rgb *= clamp(ambientColor + (dot(-lightDirection, normal0) * lightColor), 0.0, 1.0);
}
diff --git a/gfx/gl/shaders/landmassShader.fs b/gfx/gl/shaders/landmassShader.fs
index 36cc971..55c30ac 100644
--- a/gfx/gl/shaders/landmassShader.fs
+++ b/gfx/gl/shaders/landmassShader.fs
@@ -13,27 +13,23 @@ const vec3 grass = vec3(.1, .4, .05);
const vec3 sand = vec3(.76, .7, .5);
const vec3 snow = vec3(.97, .97, .99);
-vec2
-grad_between(float x, float lower, float upper)
-{
- float off = (x - lower) / (upper - lower);
- return vec2(off, 1 - off);
-}
+const float beachline = .5;
+const float snowline_low = 28;
+const float snowline_high = 30;
void
main()
{
gl_FragColor = texture(sampler, texCoord0);
- gl_FragColor.xyz *= clamp(ambientColor + (dot(-lightDirection, normal0) * lightColor), 0.0, 1.0);
- if (height < 0.5) {
+ gl_FragColor.rgb *= clamp(ambientColor + (dot(-lightDirection, normal0) * lightColor), 0.0, 1.0);
+ if (height < beachline) {
gl_FragColor.rgb *= sand;
}
- else if (height > 30) {
+ else if (height > snowline_high) {
gl_FragColor.rgb *= snow;
}
- else if (height > 28) {
- vec2 grad = grad_between(height, 28, 30);
- gl_FragColor.rgb *= grass + (snow - grass) * grad.x;
+ else if (height > snowline_low) {
+ gl_FragColor.rgb *= mix(grass, snow, (height - snowline_low) / (snowline_high - snowline_low));
}
else {
gl_FragColor.rgb *= grass;
diff --git a/gfx/gl/shaders/landmassShader.vs b/gfx/gl/shaders/landmassShader.vs
index 72c9060..dc92e95 100644
--- a/gfx/gl/shaders/landmassShader.vs
+++ b/gfx/gl/shaders/landmassShader.vs
@@ -9,12 +9,10 @@ out vec3 normal0;
out float height;
uniform mat4 viewProjection;
-uniform mat4 model;
-uniform vec3 waves;
void main()
{
- gl_Position = viewProjection * model * vec4(position, 1.0);
+ gl_Position = viewProjection * vec4(position, 1.0);
texCoord0 = texCoord;
normal0 = normal;
height = position.y;
diff --git a/gfx/gl/shaders/waterShader.vs b/gfx/gl/shaders/waterShader.vs
index 55a0fb8..2efff85 100644
--- a/gfx/gl/shaders/waterShader.vs
+++ b/gfx/gl/shaders/waterShader.vs
@@ -8,16 +8,15 @@ out vec2 texCoord0;
out float depth;
uniform mat4 viewProjection;
-uniform mat4 model;
uniform vec3 waves;
void main()
{
vec3 wpos = vec3(
position.x + cos(waves.x),
- cos(waves.x + position.x + (position.z / 7)) * .3,
- position.z + cos(waves.x * waves.z));
- gl_Position = viewProjection * model * vec4(wpos, 1.0);
+ cos(waves.x + position.x + (position.z / 8)) * .3,
+ position.z + cos(waves.x * waves.z / 2));
+ gl_Position = viewProjection * vec4(wpos, 1.0);
texCoord0 = texCoord;
depth = position.y;
}