From 605f0e3c742ae4e68455a86378792ebb4e656a60 Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Thu, 12 Nov 2020 20:47:08 +0000 Subject: [PATCH 1/2] WS3.0: Add forest texture to shader Interm shader update until texture array support available. --- Compositor/Effects/ws30.eff | 53 ++++++++++++++++++++++++++++---- Compositor/Shaders/ALS/ws30.frag | 35 ++++++++++----------- 2 files changed, 63 insertions(+), 25 deletions(-) diff --git a/Compositor/Effects/ws30.eff b/Compositor/Effects/ws30.eff index 3471da921..acece4aa5 100644 --- a/Compositor/Effects/ws30.eff +++ b/Compositor/Effects/ws30.eff @@ -46,6 +46,19 @@ normalized + Textures/Terrain/forest.png + 2d + linear-mipmap-linear + + repeat + repeat + + + normalized + + Textures/Terrain/water.png 2d linear-mipmap-linear @@ -492,9 +505,8 @@ texture[0]/image - - texture[0]/filter - + nearest-mipmap-nearest + nearest-mipmap-nearest texture[0]/wrap-s @@ -504,6 +516,11 @@ texture[0]/internal-format + + max + max + max + @@ -562,6 +579,25 @@ + + 4 + + texture[4]/image + + + texture[4]/filter + + + texture[4]/wrap-s + + + texture[4]/wrap-t + + + texture[4]/internal-format + + + Shaders/ALS/generic-base.vert Shaders/ALS/shadows-include.vert @@ -732,20 +768,25 @@ 0 - texture1 + grass sampler-2d 1 - texture2 + city sampler-2d 2 - texture3 + forest sampler-2d 3 + + water + sampler-2d + 4 + colorMode int diff --git a/Compositor/Shaders/ALS/ws30.frag b/Compositor/Shaders/ALS/ws30.frag index f227d516a..c794b508c 100644 --- a/Compositor/Shaders/ALS/ws30.frag +++ b/Compositor/Shaders/ALS/ws30.frag @@ -13,9 +13,10 @@ varying vec3 relPos; uniform float fg_Fcoef; uniform sampler2D landclass; -uniform sampler2D texture1; -uniform sampler2D texture2; -uniform sampler2D texture3; +uniform sampler2D grass; +uniform sampler2D city; +uniform sampler2D forest; +uniform sampler2D water; varying float yprime_alt; @@ -64,7 +65,6 @@ void main() vec3 lightDir = gl_LightSource[0].position.xyz; vec3 halfVector = gl_LightSource[0].halfVector.xyz; vec4 texel; - vec4 lc; vec4 fragColor; vec4 specular = vec4(0.0); float intensity; @@ -96,27 +96,24 @@ void main() // is closer to what the OpenGL fixed function pipeline does. color = clamp(color, 0.0, 1.0); -/* - landclass = texture2D(texture, gl_TexCoord[0].st); - texel = (landclass.r > 0.148) * texture2D(texture, gl_TexCoord[3].st) + - (landclass.g < 0.02) * texture2D(texture, gl_TexCoord[2].st) + - (1 - ((landclass.r > 0.148) || (landclass.g < 0.02))) * texture2D(texture, gl_TexCoord[1].st); -*/ - lc = texture2D(landclass, gl_TexCoord[0].st); - if (lc.r > 0.148) { - // Water - texel = texture2D(texture3, gl_TexCoord[0].st); - } else if (lc.g > 0.02) { - texel = texture2D(texture1, gl_TexCoord[0].st); + int lc = int(texture2D(landclass, gl_TexCoord[0].st).r * 256.0 + 0.5); + + if ((lc == 1) || (lc == 2) || (lc == 4) || (lc == 5)) + { + texel = texture2D(city, gl_TexCoord[0].st); + } else if ((lc > 21) && (lc < 25)) + { + texel = texture2D(forest, gl_TexCoord[0].st); + } else if (lc > 38) + { + texel = texture2D(water, gl_TexCoord[0].st); } else { - texel = texture2D(texture2, gl_TexCoord[0].st); + texel = texture2D(grass, gl_TexCoord[0].st); } //texel = texture2D(texture, gl_TexCoord[0].st); fragColor = color * texel + specular; - - // here comes the terrain haze model From 3cace276d211ced8e5bc435cc4ec579cdfe3121c Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Sat, 14 Nov 2020 21:04:30 +0000 Subject: [PATCH 2/2] WS3.0: Add tile_level, tile_width, tile_height Add Uniforms to WS3.0 fragment shader to provide LoD information and make sampling of adjacent points in the landclass texture easier. --- Compositor/Shaders/ALS/ws30.frag | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Compositor/Shaders/ALS/ws30.frag b/Compositor/Shaders/ALS/ws30.frag index c794b508c..c6eaac854 100644 --- a/Compositor/Shaders/ALS/ws30.frag +++ b/Compositor/Shaders/ALS/ws30.frag @@ -35,6 +35,11 @@ uniform float overcast; uniform float eye_alt; uniform float cloud_self_shading; +// Passed from VPBTechnique, not the Effect +uniform int tile_level; +uniform float tile_width; +uniform float tile_height; + const float EarthRadius = 5800000.0; const float terminator_width = 200000.0;