1
0
Fork 0

WS30: Improved coastlines

Modify the ws30 shader to build a coastline using
a high resolution overlay texture mixed with the
landclass texture.
This commit is contained in:
Stuart Buchanan 2022-05-28 20:44:25 +01:00
parent 141aad7901
commit dc167d0656
3 changed files with 54 additions and 11 deletions

View file

@ -27,7 +27,14 @@
<wrap-t>repeat</wrap-t>
<internal-format>normalized</internal-format>
</texture>
<texture n="8">
<image>Textures/Terrain/sand6.png</image>
<type>2d</type>
<filter>nearest</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
<internal-format>normalized</internal-format>
</texture>
<texture n="10">
<image>Textures/Terrain/snow3.png</image>
<type>2d</type>
@ -292,6 +299,15 @@
<internal-format><use>texture[6]/internal-format</use></internal-format>
</texture-unit>
<texture-unit>
<unit>8</unit>
<image><use>texture[8]/image</use></image>
<filter><use>texture[8]/filter</use></filter>
<wrap-s><use>texture[8]/wrap-s</use></wrap-s>
<wrap-t><use>texture[8]/wrap-t</use></wrap-t>
<internal-format><use>texture[8]/internal-format</use></internal-format>
</texture-unit>
<program>
<vertex-shader>Shaders/ws30-ALS-ultra.vert</vertex-shader>
<vertex-shader>Shaders/filters-ALS.vert</vertex-shader>
@ -828,6 +844,16 @@
<name>perlin</name>
<type>sampler-2d</type>
<value type="int">6</value>
</uniform>
<uniform>
<name>coastline</name>
<type>sampler-2d</type>
<value type="int">7</value>
</uniform>
<uniform>
<name>sand</name>
<type>sampler-2d</type>
<value type="int">8</value>
</uniform>
<uniform>
<name>swatch_size</name>

View file

@ -103,6 +103,12 @@ uniform vec4 fg_materialParams1[128];
uniform vec4 fg_materialParams2[128];
uniform vec4 fg_materialParams3[128];
// Coastline texture - generated from VPBTechnique
uniform sampler2D coastline;
// Sand texture
uniform sampler2D sand;
uniform mat4 fg_zUpTransform;
uniform vec3 fg_modelOffset;
@ -440,22 +446,32 @@ void main()
// Testing code: mix with green to show values of variables at each point
//vec4 green = vec4(0.0, 0.5, 0.0, 0.0);
//texel = mix(texel, green, (mfact[2]));
if ((water_shader == 1) && (fg_photoScenery == false) && fg_materialParams3[lc].x > 0.5) {
// This is a water fragment, so calculate the fragment color procedurally
// and mix with some sand and cliff colour depending on steepness
vec4 steep_texel = lookup_ground_texture_array(2, ground_tex_coord, lc, dxdy_gc); // Uses the same index as the gradient texture, which it is
vec4 beach_texel = lookup_ground_texture_array(3, ground_tex_coord, lc, dxdy_gc); // Use the dot texture, which is overloaded to be the beach texture
vec4 coast = texture2D(coastline, tile_coord);
if (coast.b > 0.01) {
float waterline_min_steepness = fg_materialParams3[lc].y;
float waterline_max_steepness = fg_materialParams3[lc].z;
vec4 steep_texel = lookup_ground_texture_array(2, ground_tex_coord, lc, dxdy_gc); // Uses the same index as the gradient texture, which it is
vec4 beach_texel = texture2D(sand, ground_tex_coord); // Use the dot texture, which is overloaded to be the beach texture
texel = mix(steep_texel, beach_texel, smoothstep(waterline_max_steepness - 0.1, waterline_max_steepness - 0.03, steepness));
// G channel used to force a beach texel and reduce artifacts between the beach and the land.
fragColor = mix(generateWaterTexel(), texel, smoothstep(0.1,0.9,(coast.b + coast.g - noise_500m) / steepness));
//fragColor = mix(texel, generateWaterTexel(), smoothstep(waterline_min_steepness,waterline_max_steepness,steepness));
fragColor.rgb += getClusteredLightsContribution(ecPosition.xyz, n, fragColor.rgb);
} else if ((water_shader == 1) && (fg_photoScenery == false) && (fg_materialParams3[lc].x > 0.5)) {
// This is a water fragment, so calculate the fragment color procedurally
// and mix with some sand and cliff colour depending on steepness
//vec4 steep_texel = lookup_ground_texture_array(2, ground_tex_coord, lc, dxdy_gc); // Uses the same index as the gradient texture, which it is
//vec4 beach_texel = lookup_ground_texture_array(3, ground_tex_coord, lc, dxdy_gc); // Use the dot texture, which is overloaded to be the beach texture
// Mix from a rocky texture to beach for steep slopes, which invariably represent the elevation mesh not being perfectly
// aligned with the landclass mesh.
texel = mix(steep_texel, beach_texel, smoothstep(waterline_max_steepness - 0.1, waterline_max_steepness - 0.03, steepness));
// texel = mix(steep_texel, beach_texel, smoothstep(waterline_max_steepness - 0.1, waterline_max_steepness - 0.03, steepness));
// Mix from the beach into the water, which produces a pleasing translucent shallow water effect.
texel = mix(texel, generateWaterTexel(), smoothstep(waterline_min_steepness,waterline_max_steepness,steepness));
fragColor = texel;
//fragColor = mix(texel, generateWaterTexel(), smoothstep(waterline_min_steepness,waterline_max_steepness,steepness));
fragColor = generateWaterTexel();
fragColor.rgb += getClusteredLightsContribution(ecPosition.xyz, n, fragColor.rgb);
} else {
// Lookup material parameters for the landclass at this fragment.

View file

@ -269,8 +269,9 @@ Started September 2000 by David Megginson, david@megginson.com
<line-features-lod-level type="int" userarchive="y">5</line-features-lod-level>
<area-features-lod-level type="int" userarchive="y">5</area-features-lod-level>
<vegetation-lod-level type="int" userarchive="y">6</vegetation-lod-level>
<water-texture-size type="int" userarchive="y">2048</water-texture-size>
<coastline-lod-level type="int" userarchive="y">3</coastline-lod-level>
<coastline-width type="float" userarchive="y">80.0</coastline-width>
<coastline-width type="float" userarchive="y">150.0</coastline-width>
<lod-level n="0">
<area-features-min-width>10000</area-features-min-width>
<line-features-min-width>9999.9</line-features-min-width>