WS30 - Improved coastline shader
Make the coastline shader consistent between the coastline texture and the underlying landclass texture, irrespective of materials.
This commit is contained in:
parent
bc2f4b4c80
commit
71bdd9e99b
6 changed files with 424 additions and 31 deletions
|
@ -27,6 +27,14 @@
|
|||
<wrap-t>repeat</wrap-t>
|
||||
<internal-format>normalized</internal-format>
|
||||
</texture>
|
||||
<texture n="7">
|
||||
<image>Textures/Globe/ocean_depth_1.png</image>
|
||||
<type>2d</type>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>repeat</wrap-s>
|
||||
<wrap-t>repeat</wrap-t>
|
||||
<internal-format>normalized</internal-format>
|
||||
</texture>
|
||||
<texture n="8">
|
||||
<image>Textures/Terrain/sand6.png</image>
|
||||
<type>2d</type>
|
||||
|
@ -997,6 +1005,14 @@
|
|||
<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-detailed.vert</vertex-shader>
|
||||
<vertex-shader>Shaders/filters-ALS.vert</vertex-shader>
|
||||
|
@ -1273,11 +1289,16 @@
|
|||
<type>sampler-2d</type>
|
||||
<value type="int">7</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>swatch_size</name>
|
||||
<type>int</type>
|
||||
<value><use>xsize</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>sand</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">8</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>swatch_size</name>
|
||||
<type>int</type>
|
||||
<value><use>xsize</use></value>
|
||||
</uniform>
|
||||
<!-- BEGIN shadows include -->
|
||||
<uniform>
|
||||
<name>shadow_tex</name>
|
||||
|
|
|
@ -102,6 +102,9 @@ uniform vec3 fg_modelOffset;
|
|||
// Coastline texture - generated from VPBTechnique
|
||||
uniform sampler2D coastline;
|
||||
|
||||
// Sand texture
|
||||
uniform sampler2D sand;
|
||||
|
||||
const float EarthRadius = 5800000.0;
|
||||
const float terminator_width = 200000.0;
|
||||
|
||||
|
@ -330,20 +333,37 @@ float noise_2000m = Noise3D(worldPos.xyz, 2000.0);
|
|||
|
||||
get_landclass_id(tile_coord, dxdy_gc, lc, lc_n, num_unique_neighbors, mfact);
|
||||
get_material(lc, ground_tex_coord, dxdy_gc, mat_shininess, mat_ambient, mat_diffuse, mat_specular, dxdy, st);
|
||||
vec4 coast = texture2D(coastline, tile_coord);
|
||||
|
||||
if (fg_photoScenery) {
|
||||
texel = texture(landclass, vec2(gl_TexCoord[0].s, 1.0 - gl_TexCoord[0].t));
|
||||
water = (texture(coastline, vec2(tile_coord.s, tile_coord.t)).r > 0.1);
|
||||
} else if (coast.g > 0.1) {
|
||||
texel = lookup_ground_texture_array(0, tile_coord, lc, dxdy);
|
||||
water = texture(landclass, vec2(tile_coord.s, tile_coord.t)).z > 0.9;
|
||||
} else {
|
||||
// Lookup the base texture texel for this fragment and any neighbors, with mixing
|
||||
texel = get_mixed_texel(0, ground_tex_coord, lc, num_unique_neighbors, lc_n, mfact, dxdy_gc);
|
||||
water = texture(landclass, vec2(tile_coord.s, tile_coord.t)).z > 0.9;
|
||||
}
|
||||
|
||||
if ((water_shader == 1) && water) {
|
||||
// This is a water fragment, so calculate the fragment color procedurally
|
||||
fragColor = generateWaterTexel();
|
||||
float steep = 0.9;
|
||||
float steepToBeach = 0.93;
|
||||
float beachToWater = 0.95;
|
||||
float waterStart = 0.97;
|
||||
|
||||
if ((water_shader == 1) && ((coast.b > 0.05) || (water && steepness < (waterStart + 0.02)))) {
|
||||
|
||||
// This is a water fragment, so calculate the fragment color procedurally, but mix in the steep and beach
|
||||
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(steep, steepToBeach, steepness));
|
||||
fragColor = mix(texel, generateWaterTexel(), smoothstep(beachToWater,waterStart,steepness));
|
||||
|
||||
fragColor.rgb += getClusteredLightsContribution(eyePos.xyz, n, fragColor.rgb);
|
||||
} else if ((water_shader == 1) && water) {
|
||||
fragColor = generateWaterTexel();
|
||||
fragColor.rgb += getClusteredLightsContribution(eyePos.xyz, n, fragColor.rgb);
|
||||
} else {
|
||||
// Photoscenery or land fragment, so determine the shading and color normally
|
||||
vec4 color = gl_Color * mat_ambient;
|
||||
|
|
|
@ -120,8 +120,7 @@ void main()
|
|||
rawPos = (fg_zUpTransform * gl_Vertex).xy;
|
||||
worldPos = fg_modelOffset + gl_Vertex.xyz;
|
||||
eyePos = gl_ModelViewMatrix * gl_Vertex;
|
||||
steepness = dot(normalize(vec3(fg_zUpTransform * vec4(gl_Normal,1.0))), vec3 (0.0, 0.0, 1.0));
|
||||
|
||||
steepness = abs(dot(normalize(vec3(fg_zUpTransform * vec4(gl_Normal,1.0))), vec3 (0.0, 0.0, 1.0)));
|
||||
|
||||
// this code is copied from default.vert
|
||||
|
||||
|
@ -213,6 +212,8 @@ if (terminator < 1000000.0) // the full, sunrise and sunset computation
|
|||
// two times terminator width governs how quickly light fades into shadow
|
||||
// now the light-dimming factor
|
||||
earthShade = 0.6 * (1.0 - smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt)) + 0.4;
|
||||
|
||||
//earthShade = 1.0;
|
||||
|
||||
// parametrized version of the Flightgear ground lighting function
|
||||
lightArg = (terminator-yprime_alt)/100000.0;
|
||||
|
|
|
@ -428,6 +428,7 @@ void main()
|
|||
|
||||
get_landclass_id(tile_coord, dxdy_gc, lc, lc_n, num_unique_neighbors, mfact);
|
||||
get_material(lc, ground_tex_coord, dxdy_gc, mat_shininess, mat_ambient, mat_diffuse, mat_specular, dxdy, st);
|
||||
vec4 coast = texture2D(coastline, tile_coord);
|
||||
|
||||
if (fg_photoScenery) {
|
||||
// The photoscenery orthophotos are stored in the landclass texture
|
||||
|
@ -438,6 +439,9 @@ void main()
|
|||
// Do not attempt any mixing
|
||||
flag = 0;
|
||||
mix_flag = 0;
|
||||
} else if (coast.g > 0.1) {
|
||||
texel = lookup_ground_texture_array(0, tile_coord, lc, dxdy);
|
||||
water = texture(landclass, vec2(tile_coord.s, tile_coord.t)).z > 0.9;
|
||||
} else {
|
||||
// Lookup the base texture texel for this fragment and any neighbors, with mixing
|
||||
texel = get_mixed_texel(0, ground_tex_coord, lc, num_unique_neighbors, lc_n, mfact, dxdy_gc);
|
||||
|
@ -450,31 +454,21 @@ 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]));
|
||||
vec4 coast = texture2D(coastline, tile_coord);
|
||||
if (coast.b > 0.05) {
|
||||
|
||||
float steep = 0.9;
|
||||
float steepToBeach = 0.93;
|
||||
float beachToWater = 0.95;
|
||||
float waterStart = 0.97;
|
||||
|
||||
if ((coast.b > 0.05) || (water && steepness < (waterStart + 0.02))) {
|
||||
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.a) / steepness));
|
||||
//fragColor = mix(texel, generateWaterTexel(), smoothstep(waterline_min_steepness,waterline_max_steepness,steepness));
|
||||
texel = mix(steep_texel, beach_texel, smoothstep(steep, steepToBeach, steepness));
|
||||
fragColor = mix(texel, generateWaterTexel(), smoothstep(beachToWater,waterStart,steepness));
|
||||
fragColor.rgb += getClusteredLightsContribution(ecPosition.xyz, n, fragColor.rgb);
|
||||
} else if (water) {
|
||||
// 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));
|
||||
|
||||
// Mix from the beach into the water, which produces a pleasing translucent shallow water effect.
|
||||
//fragColor = mix(texel, generateWaterTexel(), smoothstep(0.3,1.0,texture(coastline, vec2(tile_coord.s, tile_coord.t)).r));
|
||||
fragColor = generateWaterTexel();
|
||||
fragColor.rgb += getClusteredLightsContribution(ecPosition.xyz, n, fragColor.rgb);
|
||||
} else {
|
||||
|
|
|
@ -209,8 +209,7 @@ void main()
|
|||
// WS2: worldPos = (osg_ViewMatrixInverse *gl_ModelViewMatrix * gl_Vertex).xyz;
|
||||
worldPos = fg_modelOffset + gl_Vertex.xyz;
|
||||
|
||||
|
||||
steepness = dot(normalize(vec3(fg_zUpTransform * vec4(gl_Normal,1.0))), vec3 (0.0, 0.0, 1.0));
|
||||
steepness = abs(dot(normalize(vec3(fg_zUpTransform * vec4(gl_Normal,1.0))), vec3 (0.0, 0.0, 1.0)));
|
||||
// Gradient direction used for small scale noise. In the same space as noise coords, rawpos.xy.
|
||||
grad_dir = normalize(gl_Normal.xy);
|
||||
|
||||
|
|
358
Shaders/ws30-water-high.frag
Normal file
358
Shaders/ws30-water-high.frag
Normal file
|
@ -0,0 +1,358 @@
|
|||
// SPDX-FileCopyrightText: (C) 2022 Stuart Buchanan stuart13@gmail.com
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Helper functions for WS30 water implementation, heavily based on the
|
||||
// water-ALS-base.frag and waterr_ALS-high.frag
|
||||
|
||||
#version 130
|
||||
#extension GL_EXT_texture_array : enable
|
||||
|
||||
// Hardcoded indexes into the texture atlas
|
||||
const int ATLAS_INDEX_WATER = 0;
|
||||
const int ATLAS_INDEX_WATER_REFLECTION = 1;
|
||||
const int ATLAS_INDEX_WAVES_VERT10_NM = 2;
|
||||
const int ATLAS_INDEX_WATER_SINE_NMAP = 3;
|
||||
const int ATLAS_INDEX_WATER_REFLECTION_GREY = 4;
|
||||
const int ATLAS_INDEX_SEA_FOAM = 5;
|
||||
const int ATLAS_INDEX_PERLIN_NOISE_NM = 6;
|
||||
const int ATLAS_INDEX_OCEAN_DEPTH = 7;
|
||||
const int ATLAS_INDEX_GLOBAL_COLORS = 8;
|
||||
const int ATLAS_INDEX_PACKICE_OVERLAY = 9;
|
||||
|
||||
// WS30 uniforms
|
||||
uniform sampler2DArray textureArray;
|
||||
uniform float ground_scattering;
|
||||
uniform float overcast;
|
||||
uniform float fg_tileWidth;
|
||||
uniform float fg_tileHeight;
|
||||
|
||||
// Water.eff uniforms
|
||||
uniform float sea_r;
|
||||
uniform float sea_g;
|
||||
uniform float sea_b;
|
||||
uniform float osg_SimulationTime;
|
||||
uniform float WindN;
|
||||
uniform float WindE;
|
||||
uniform float WaveFreq;
|
||||
uniform float WaveAmp;
|
||||
uniform float WaveSharp;
|
||||
uniform float WaveAngle;
|
||||
uniform float WaveFactor;
|
||||
uniform float saturation;
|
||||
|
||||
// WS30 varying
|
||||
varying vec3 relPos;
|
||||
|
||||
// Water.eff varying
|
||||
varying float earthShade;
|
||||
varying vec3 lightdir;
|
||||
varying vec4 waterTex1;
|
||||
varying vec4 waterTex2;
|
||||
varying vec4 waterTex4;
|
||||
varying vec3 specular_light;
|
||||
|
||||
//WS3.0 varying
|
||||
varying float steepness;
|
||||
|
||||
|
||||
/////// functions /////////
|
||||
|
||||
float getShadowing();
|
||||
vec3 getClusteredLightsContribution(vec3 p, vec3 n, vec3 texel);
|
||||
|
||||
void rotationmatrix(in float angle, out mat4 rotmat)
|
||||
{
|
||||
rotmat = mat4( cos( angle ), -sin( angle ), 0.0, 0.0,
|
||||
sin( angle ), cos( angle ), 0.0, 0.0,
|
||||
0.0 , 0.0 , 1.0, 0.0,
|
||||
0.0 , 0.0 , 0.0, 1.0 );
|
||||
}
|
||||
|
||||
// wave functions ///////////////////////
|
||||
struct Wave {
|
||||
float freq; // 2*PI / wavelength
|
||||
float amp; // amplitude
|
||||
float phase; // speed * 2*PI / wavelength
|
||||
vec2 dir;
|
||||
};
|
||||
|
||||
Wave wave0 = Wave(1.0, 1.0, 0.5, vec2(0.97, 0.25));
|
||||
Wave wave1 = Wave(2.0, 0.5, 1.3, vec2(0.97, -0.25));
|
||||
Wave wave2 = Wave(1.0, 1.0, 0.6, vec2(0.95, -0.3));
|
||||
Wave wave3 = Wave(2.0, 0.5, 1.4, vec2(0.99, 0.1));
|
||||
|
||||
float evaluateWave(in Wave w, in vec2 pos, in float t) {
|
||||
return w.amp * sin( dot(w.dir, pos) * w.freq + t * w.phase);
|
||||
}
|
||||
|
||||
// derivative of wave function
|
||||
float evaluateWaveDeriv(in Wave w, in vec2 pos, in float t) {
|
||||
return w.freq * w.amp * cos( dot(w.dir, pos)*w.freq + t*w.phase);
|
||||
}
|
||||
|
||||
// sharp wave functions
|
||||
float evaluateWaveSharp(in Wave w, in vec2 pos, in float t, in float k) {
|
||||
return w.amp * pow(sin( dot(w.dir, pos)*w.freq + t*w.phase)* 0.5 + 0.5 , k);
|
||||
}
|
||||
|
||||
float evaluateWaveDerivSharp(in Wave w, in vec2 pos, in float t, in float k) {
|
||||
return k*w.freq*w.amp * pow(sin( dot(w.dir, pos)*w.freq + t*w.phase)* 0.5 + 0.5 , k - 1) * cos( dot(w.dir, pos)*w.freq + t*w.phase);
|
||||
}
|
||||
|
||||
void sumWaves(in float angle, in float dangle, in float windScale, in float factor, out float ddx, float ddy) {
|
||||
mat4 RotationMatrix;
|
||||
float deriv;
|
||||
vec4 P = waterTex1 * 1024;
|
||||
|
||||
rotationmatrix(radians(angle + dangle * windScale + 0.6 * sin(P.x * factor)), RotationMatrix);
|
||||
P *= RotationMatrix;
|
||||
|
||||
P.y += evaluateWave(wave0, P.xz, osg_SimulationTime);
|
||||
deriv = evaluateWaveDeriv(wave0, P.xz, osg_SimulationTime );
|
||||
ddx = deriv * wave0.dir.x;
|
||||
ddy = deriv * wave0.dir.y;
|
||||
|
||||
//P.y += evaluateWave(wave1, P.xz, osg_SimulationTime);
|
||||
//deriv = evaluateWaveDeriv(wave1, P.xz, osg_SimulationTime);
|
||||
//ddx += deriv * wave1.dir.x;
|
||||
//ddy += deriv * wave1.dir.y;
|
||||
|
||||
P.y += evaluateWaveSharp(wave2, P.xz, osg_SimulationTime, WaveSharp);
|
||||
deriv = evaluateWaveDerivSharp(wave2, P.xz, osg_SimulationTime, WaveSharp);
|
||||
ddx += deriv * wave2.dir.x;
|
||||
ddy += deriv * wave2.dir.y;
|
||||
|
||||
//P.y += evaluateWaveSharp(wave3, P.xz, osg_SimulationTime, WaveSharp);
|
||||
//deriv = evaluateWaveDerivSharp(wave3, P.xz, osg_SimulationTime, WaveSharp);
|
||||
//ddx += deriv * wave3.dir.x;
|
||||
//ddy += deriv * wave3.dir.y;
|
||||
}
|
||||
|
||||
vec4 generateWaterTexel()
|
||||
{
|
||||
vec4 texel;
|
||||
float dist = length(relPos);
|
||||
float tileScale = 1 / (fg_tileHeight + fg_tileWidth) / 2.0;
|
||||
|
||||
vec4 sca = vec4(0.005, 0.005, 0.005, 0.005) * tileScale;
|
||||
vec4 sca2 = vec4(0.02, 0.02, 0.02, 0.02) * tileScale;
|
||||
vec4 tscale = vec4(0.25, 0.25, 0.25, 0.25) / 10000.0 * tileScale;
|
||||
|
||||
mat4 RotationMatrix;
|
||||
|
||||
// compute direction to viewer
|
||||
vec3 E = normalize(-relPos);
|
||||
|
||||
// compute direction to light source
|
||||
vec3 L = normalize(lightdir);
|
||||
|
||||
// half vector
|
||||
vec3 Hv = normalize(L + E);
|
||||
|
||||
vec3 Normal = vec3 (0.0, 0.0, 1.0);
|
||||
|
||||
const float water_shininess = 240.0;
|
||||
|
||||
float windEffect = sqrt( WindE*WindE + WindN*WindN ) * 0.6; //wind speed in kt
|
||||
float windScale = 15.0/(3.0 + windEffect); //wave scale
|
||||
float windEffect_low = 0.3 + 0.7 * smoothstep(0.0, 5.0, windEffect); //low windspeed wave filter
|
||||
float waveRoughness = 0.01 + smoothstep(0.0, 40.0, windEffect); //wave roughness filter
|
||||
|
||||
float mixFactor = 0.2 + 0.02 * smoothstep(0.0, 50.0, windEffect);
|
||||
mixFactor = clamp(mixFactor, 0.3, 0.8);
|
||||
|
||||
// there's no need to do wave patterns or foam for pixels which are so far away that we can't actually see them
|
||||
// we only need detail in the near zone or where the sun reflection is
|
||||
|
||||
int detail_flag;
|
||||
if ((dist > 15000.0) && (dot(normalize(vec3 (lightdir.x, lightdir.y, 0.0) ), normalize(relPos)) < 0.7 )) {detail_flag = 0;}
|
||||
else {detail_flag = 1;}
|
||||
|
||||
// sine waves
|
||||
float ddx, ddx1, ddx2, ddx3, ddy, ddy1, ddy2, ddy3;
|
||||
float angle;
|
||||
|
||||
ddx = 0.0, ddy = 0.0;
|
||||
ddx1 = 0.0, ddy1 = 0.0;
|
||||
ddx2 = 0.0, ddy2 = 0.0;
|
||||
ddx3 = 0.0, ddy3 = 0.0;
|
||||
|
||||
if (detail_flag == 1)
|
||||
{
|
||||
angle = 0.0;
|
||||
|
||||
wave0.freq = WaveFreq ;
|
||||
wave0.amp = WaveAmp;
|
||||
wave0.dir = vec2 (0.0, 1.0); //vec2(cos(radians(angle)), sin(radians(angle)));
|
||||
|
||||
angle -= 45;
|
||||
wave1.freq = WaveFreq * 2.0 ;
|
||||
wave1.amp = WaveAmp * 1.25;
|
||||
wave1.dir = vec2(0.70710, -0.7071); //vec2(cos(radians(angle)), sin(radians(angle)));
|
||||
|
||||
angle += 30;
|
||||
wave2.freq = WaveFreq * 3.5;
|
||||
wave2.amp = WaveAmp * 0.75;
|
||||
wave2.dir = vec2(0.96592, -0.2588);// vec2(cos(radians(angle)), sin(radians(angle)));
|
||||
|
||||
angle -= 50;
|
||||
wave3.freq = WaveFreq * 3.0 ;
|
||||
wave3.amp = WaveAmp * 0.75;
|
||||
wave3.dir = vec2(0.42261, -0.9063); //vec2(cos(radians(angle)), sin(radians(angle)));
|
||||
|
||||
// sum waves
|
||||
sumWaves(WaveAngle, -1.5, windScale, WaveFactor, ddx, ddy);
|
||||
sumWaves(WaveAngle, 1.5, windScale, WaveFactor, ddx1, ddy1);
|
||||
|
||||
//reset the waves
|
||||
angle = 0.0;
|
||||
float waveamp = WaveAmp * 0.75;
|
||||
|
||||
wave0.freq = WaveFreq ;
|
||||
wave0.amp = waveamp;
|
||||
wave0.dir = vec2 (0.0, 1.0); //vec2(cos(radians(angle)), sin(radians(angle)));
|
||||
|
||||
angle -= 20;
|
||||
wave1.freq = WaveFreq * 2.0 ;
|
||||
wave1.amp = waveamp * 1.25;
|
||||
wave1.dir = vec2(0.93969, -0.34202);// vec2(cos(radians(angle)), sin(radians(angle)));
|
||||
|
||||
angle += 35;
|
||||
wave2.freq = WaveFreq * 3.5;
|
||||
wave2.amp = waveamp * 0.75;
|
||||
wave2.dir = vec2(0.965925, 0.25881); //vec2(cos(radians(angle)), sin(radians(angle)));
|
||||
|
||||
angle -= 45;
|
||||
wave3.freq = WaveFreq * 3.0 ;
|
||||
wave3.amp = waveamp * 0.75;
|
||||
wave3.dir = vec2(0.866025, -0.5); //vec2(cos(radians(angle)), sin(radians(angle)));
|
||||
}
|
||||
// end sine stuff
|
||||
|
||||
//cover = 5.0 * smoothstep(0.6, 1.0, scattering);
|
||||
//cover = 5.0 * ground_scattering;
|
||||
|
||||
vec4 viewt = normalize(waterTex4);
|
||||
vec2 st = vec2(waterTex2 * tscale * windScale);
|
||||
vec4 disdis = texture(textureArray, vec3(st, ATLAS_INDEX_WATER_SINE_NMAP)) * 2.0 - 1.0;
|
||||
|
||||
vec4 vNorm;
|
||||
|
||||
//normalmaps
|
||||
st = vec2(waterTex1 + disdis * sca2) * windScale;
|
||||
vec4 nmap = texture(textureArray, vec3(st, ATLAS_INDEX_WAVES_VERT10_NM)) * 2.0 - 1.0;
|
||||
vec4 nmap1 = texture(textureArray, vec3(st, ATLAS_INDEX_PERLIN_NOISE_NM)) * 2.0 - 1.0;
|
||||
|
||||
rotationmatrix(radians(3.0 * sin(osg_SimulationTime * 0.0075)), RotationMatrix);
|
||||
st = vec2(waterTex2 * RotationMatrix * tscale) * windScale;
|
||||
nmap += texture(textureArray, vec3(st, ATLAS_INDEX_WAVES_VERT10_NM)) * 2.0 - 1.0;
|
||||
|
||||
nmap *= windEffect_low;
|
||||
nmap1 *= windEffect_low;
|
||||
|
||||
// mix water and noise, modulated by factor
|
||||
vNorm = normalize(mix(nmap, nmap1, mixFactor) * waveRoughness);
|
||||
vNorm.r += ddx + ddx1 + ddx2 + ddx3;
|
||||
|
||||
//if (normalmap_dds > 0) {vNorm = -vNorm;} //dds fix
|
||||
|
||||
//load reflection
|
||||
vec4 refl ;
|
||||
refl.r = sea_r;
|
||||
refl.g = sea_g;
|
||||
refl.b = sea_b;
|
||||
refl.a = 1.0;
|
||||
|
||||
float intensity;
|
||||
// de-saturate for reduced light
|
||||
refl.rgb = mix(refl.rgb, vec3 (0.248, 0.248, 0.248), 1.0 - smoothstep(0.1, 0.8, ground_scattering));
|
||||
|
||||
// de-saturate light for overcast haze
|
||||
intensity = length(refl.rgb);
|
||||
refl.rgb = mix(refl.rgb, intensity * vec3 (1.0, 1.0, 1.0), 0.5 * smoothstep(0.1, 0.9, overcast));
|
||||
|
||||
vec3 N;
|
||||
st = vec2(waterTex1 + disdis * sca2) * windScale;
|
||||
vec3 N0 = vec3(texture(textureArray, vec3(st, ATLAS_INDEX_WAVES_VERT10_NM))) * 2.0 - 1.0;
|
||||
st = vec2(waterTex1 + disdis * sca) * windScale;
|
||||
vec3 N1 = vec3(texture(textureArray, vec3(st, ATLAS_INDEX_PERLIN_NOISE_NM))) * 2.0 - 1.0;
|
||||
|
||||
st = vec2(waterTex1 * tscale) * windScale;
|
||||
N0 += vec3(texture(textureArray, vec3(st, ATLAS_INDEX_WAVES_VERT10_NM))) * 2.0 - 1.0;
|
||||
N1 += vec3(texture(textureArray, vec3(st, ATLAS_INDEX_PERLIN_NOISE_NM))) * 2.0 - 1.0;
|
||||
|
||||
rotationmatrix(radians(2.0 * sin(osg_SimulationTime * 0.005)), RotationMatrix);
|
||||
st = vec2(waterTex2 * RotationMatrix * (tscale + sca2)) * windScale;
|
||||
N0 += vec3(texture(textureArray, vec3(st, ATLAS_INDEX_WAVES_VERT10_NM))) * 2.0 - 1.0;
|
||||
N1 += vec3(texture(textureArray, vec3(st, ATLAS_INDEX_PERLIN_NOISE_NM))) * 2.0 - 1.0;
|
||||
|
||||
rotationmatrix(radians(-4.0 * sin(osg_SimulationTime * 0.003)), RotationMatrix);
|
||||
st = vec2(waterTex1 * RotationMatrix + disdis * sca2) * windScale;
|
||||
N0 += vec3(texture(textureArray, vec3(st, ATLAS_INDEX_WAVES_VERT10_NM))) * 2.0 - 1.0;
|
||||
st = vec2(waterTex1 * RotationMatrix + disdis * sca) * windScale;
|
||||
N1 += vec3(texture(textureArray, vec3(st, ATLAS_INDEX_PERLIN_NOISE_NM))) * 2.0 - 1.0;
|
||||
|
||||
N0 *= windEffect_low;
|
||||
N1 *= windEffect_low;
|
||||
|
||||
N0.r += (ddx + ddx1 + ddx2 + ddx3);
|
||||
N0.g += (ddy + ddy1 + ddy2 + ddy3);
|
||||
|
||||
N = normalize(mix(Normal + N0, Normal + N1, mixFactor) * waveRoughness);
|
||||
|
||||
vec3 specular_color = vec3(specular_light * earthShade) * pow(max(0.0, dot(N, Hv)), water_shininess) * 6.0;
|
||||
|
||||
// secondary reflection of sky irradiance
|
||||
vec3 ER = E - 2.0 * N * dot(E,N);
|
||||
float ctrefl = dot(vec3(0.0,0.0,1.0), -normalize(ER));
|
||||
//float fresnel = -0.5 + 8.0 * (1.0-smoothstep(0.0,0.4, dot(E,N)));
|
||||
float fresnel = 8.0 * (1.0-smoothstep(0.0,0.4, dot(E,N)));
|
||||
//specular_color += (ctrefl*ctrefl) * fresnel* specular_light.rgb;
|
||||
|
||||
specular_color += ((0.15*(1.0-ctrefl* ctrefl) * fresnel) - 0.3) * specular_light.rgb * earthShade;
|
||||
vec4 specular = vec4(specular_color, 0.5);
|
||||
|
||||
specular = specular * saturation * 0.3 * earthShade ;
|
||||
|
||||
//calculate fresnel
|
||||
vec4 invfres = vec4( dot(vNorm, viewt) );
|
||||
vec4 fres = vec4(1.0) + invfres;
|
||||
refl *= fres;
|
||||
|
||||
vec4 ambient_light;
|
||||
//intensity = length(specular_light.rgb);
|
||||
ambient_light.rgb = max(specular_light.rgb * earthShade, vec3(0.05, 0.05, 0.05));
|
||||
//ambient_light.rgb = max(intensity * normalize(vec3 (0.33, 0.4, 0.5)), vec3 (0.1,0.1,0.1));
|
||||
ambient_light.a = 1.0;
|
||||
|
||||
// compute object shadow effect
|
||||
|
||||
float shadowValue = getShadowing();
|
||||
specular = specular * shadowValue;
|
||||
refl = refl * (0.7 + 0.3 *shadowValue);
|
||||
|
||||
|
||||
texel = refl + specular * smoothstep(0.3, 0.6, ground_scattering);
|
||||
|
||||
// For the clustered lighting function we use the simple up direction (Normal) to get an
|
||||
// approximate lighting contribution, as the procedural normal map is done afterwards.
|
||||
//texel += vec4(getClusteredLightsContribution(ecPosition.xyz, Normal, vec3(1.0)), 0.0) * light_distance_fading(dist) * 2.0 * pow(max(0.0,dot(E,N)), water_shininess);
|
||||
|
||||
if (dist < 10000.0)
|
||||
{
|
||||
float foamSlope = 0.10 + 0.1 * windScale;
|
||||
float waveSlope = N.g + min(50.0*(1.0 - steepness), 0.1);
|
||||
|
||||
if ((steepness < 0.9999) || (windEffect >= 8.0) && (waveSlope >= foamSlope)) {
|
||||
//add foam
|
||||
st = vec2(waterTex2 * tscale) * 25.0;
|
||||
vec4 foam_texel = texture(textureArray, vec3(st, ATLAS_INDEX_SEA_FOAM) );
|
||||
|
||||
texel = mix(texel, max(texel, texel + foam_texel), smoothstep(0.01, 0.50, waveSlope));
|
||||
}
|
||||
}
|
||||
|
||||
texel *= ambient_light;
|
||||
|
||||
return texel;
|
||||
}
|
Loading…
Add table
Reference in a new issue