1
0
Fork 0

Packice overlay and water color variations for high quality water shader in Atmospheric Light Scattering

This commit is contained in:
Thorsten Renk 2013-04-15 14:29:04 +03:00
parent 402d75a602
commit df35c11af2
5 changed files with 218 additions and 19 deletions

View file

@ -45,6 +45,13 @@
<wrap-t>repeat</wrap-t>
<internal-format>normalized</internal-format>
</texture>
<texture n="10">
<image>Textures.high/Terrain/packice-overlay.png</image>
<filter>linear-mipmap-linear</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
<internal-format>normalized</internal-format>
</texture>
<normalmap_dds type="float">0.0</normalmap_dds>
<saturation>
<use>/rendering/scene/saturation</use>
@ -132,6 +139,9 @@
<fogtype>
<use>/sim/rendering/shaders/skydome</use>
</fogtype>
<ice_cover>
<use>/environment/sea/surface/ice-cover</use>
</ice_cover>
<!-- sea colors -->
<sea_r>
<use>/environment/sea/color_r</use>
@ -312,6 +322,24 @@
<use>texture[6]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
<unit>7</unit>
<image>
<use>texture[10]/image</use>
</image>
<filter>
<use>texture[10]/filter</use>
</filter>
<wrap-s>
<use>texture[10]/wrap-s</use>
</wrap-s>
<wrap-t>
<use>texture[10]/wrap-t</use>
</wrap-t>
<internal-format>
<use>texture[10]/internal-format</use>
</internal-format>
</texture-unit>
<program>
<vertex-shader>Shaders/water_lightfield.vert</vertex-shader>
@ -342,6 +370,11 @@
<type>sampler-2d</type>
<value type="int">6</value>
</uniform>
<uniform>
<name>ice_texture</name>
<type>sampler-2d</type>
<value type="int">7</value>
</uniform>
<!-- normalmap is .dds-->
<uniform>
<name>normalmap_dds</name>
@ -486,6 +519,11 @@
<type>float</type>
<value><use>cloud_self_shading</use></value>
</uniform>
<uniform>
<name>ice_cover</name>
<type>float</type>
<value><use>ice_cover</use></value>
</uniform>
<!-- sea colors -->
<uniform>
<name>sea_r</name>

View file

@ -404,6 +404,9 @@
<color_r type="double" userarchive="n">0.148</color_r>
<color_g type="double" userarchive="n">0.27</color_g>
<color_b type="double" userarchive="n">0.3</color_b>
<surface>
<ice-cover> 0.0</ice-cover>
</surface>
</sea>
<!-- definitions for the scattering skydome shader -->

View file

@ -12,6 +12,7 @@ uniform sampler2D water_normalmap;
uniform sampler2D water_dudvmap;
uniform sampler2D sea_foam;
uniform sampler2D perlin_normalmap;
uniform sampler2D ice_texture;
uniform sampler3D Noise;
@ -23,8 +24,8 @@ varying vec4 waterTex2; //moving texcoords
varying vec4 waterTex4; //viewts
varying vec3 viewerdir;
varying vec3 lightdir;
//varying vec3 specular_light;
varying vec3 relPos;
varying vec3 rawPos;
varying float earthShade;
varying float yprime_alt;
@ -49,6 +50,7 @@ uniform float scattering;
uniform float ground_scattering;
uniform float cloud_self_shading;
uniform float eye_alt;
uniform float ice_cover;
uniform float sea_r;
uniform float sea_g;
uniform float sea_b;
@ -68,6 +70,93 @@ vec3 fog_Func(vec3 color, int type);
/////// functions /////////
float rand2D(in vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
float rand3D(in vec3 co){
return fract(sin(dot(co.xyz ,vec3(12.9898,78.233,144.7272))) * 43758.5453);
}
float cosine_interpolate(in float a, in float b, in float x)
{
float ft = x * 3.1415927;
float f = (1.0 - cos(ft)) * .5;
return a*(1.0-f) + b*f;
}
float simple_interpolate(in float a, in float b, in float x)
{
return a + smoothstep(0.0,1.0,x) * (b-a);
}
float interpolatedNoise2D(in float x, in float y)
{
float integer_x = x - fract(x);
float fractional_x = x - integer_x;
float integer_y = y - fract(y);
float fractional_y = y - integer_y;
float v1 = rand2D(vec2(integer_x, integer_y));
float v2 = rand2D(vec2(integer_x+1.0, integer_y));
float v3 = rand2D(vec2(integer_x, integer_y+1.0));
float v4 = rand2D(vec2(integer_x+1.0, integer_y +1.0));
float i1 = simple_interpolate(v1 , v2 , fractional_x);
float i2 = simple_interpolate(v3 , v4 , fractional_x);
return simple_interpolate(i1 , i2 , fractional_y);
}
float interpolatedNoise3D(in float x, in float y, in float z)
{
float integer_x = x - fract(x);
float fractional_x = x - integer_x;
float integer_y = y - fract(y);
float fractional_y = y - integer_y;
float integer_z = z - fract(z);
float fractional_z = z - integer_z;
float v1 = rand3D(vec3(integer_x, integer_y, integer_z));
float v2 = rand3D(vec3(integer_x+1.0, integer_y, integer_z));
float v3 = rand3D(vec3(integer_x, integer_y+1.0, integer_z));
float v4 = rand3D(vec3(integer_x+1.0, integer_y +1.0, integer_z));
float v5 = rand3D(vec3(integer_x, integer_y, integer_z+1.0));
float v6 = rand3D(vec3(integer_x+1.0, integer_y, integer_z+1.0));
float v7 = rand3D(vec3(integer_x, integer_y+1.0, integer_z+1.0));
float v8 = rand3D(vec3(integer_x+1.0, integer_y +1.0, integer_z+1.0));
float i1 = simple_interpolate(v1,v5, fractional_z);
float i2 = simple_interpolate(v2,v6, fractional_z);
float i3 = simple_interpolate(v3,v7, fractional_z);
float i4 = simple_interpolate(v4,v8, fractional_z);
float ii1 = simple_interpolate(i1,i2,fractional_x);
float ii2 = simple_interpolate(i3,i4,fractional_x);
return simple_interpolate(ii1 , ii2 , fractional_y);
}
float Noise2D(in vec2 coord, in float wavelength)
{
return interpolatedNoise2D(coord.x/wavelength, coord.y/wavelength);
}
float Noise3D(in vec3 coord, in float wavelength)
{
return interpolatedNoise3D(coord.x/wavelength, coord.y/wavelength, coord.z/wavelength);
}
void rotationmatrix(in float angle, out mat4 rotmat)
{
rotmat = mat4( cos( angle ), -sin( angle ), 0.0, 0.0,
@ -199,6 +288,12 @@ void main(void)
const vec4 sca2 = vec4(0.02, 0.02, 0.02, 0.02);
const vec4 tscale = vec4(0.25, 0.25, 0.25, 0.25);
float noise_50m = Noise3D(rawPos.xyz, 50.0);
float noise_250m = Noise3D(rawPos.xyz,250.0);
float noise_1500m = Noise3D(rawPos.xyz,1500.0);
float noise_2000m = Noise3D(rawPos.xyz,2000.0);
float noise_2500m = Noise3D(rawPos.xyz, 2500.0);
mat4 RotationMatrix;
// compute direction to viewer
@ -332,6 +427,7 @@ void main(void)
if (normalmap_dds > 0)
{vNorm = -vNorm;} //dds fix
vNorm = vNorm * (0.5 + 0.5 * noise_250m);
//load reflection
@ -342,6 +438,7 @@ void main(void)
refl.b = sea_b;
refl.a = 1.0;
refl.g = refl.g * (0.9 + 0.2* noise_2500m);
float intensity;
// de-saturate for reduced light
@ -435,7 +532,16 @@ void main(void)
finalColor *= ambient_light;
// add ice
vec4 ice_texel = texture2D(ice_texture, vec2(waterTex2) * 0.2 );
float nSum = 0.5 * (noise_250m + noise_50m);
float mix_factor = smoothstep(1.0 - ice_cover, 1.04-ice_cover, nSum);
finalColor = mix(finalColor, ice_texel, mix_factor * ice_texel.a);
finalColor.a = 1.0;
finalColor *= ambient_light;

View file

@ -11,7 +11,7 @@ varying vec4 waterTex1;
varying vec4 waterTex2;
varying vec4 waterTex4;
varying vec3 relPos;
varying vec3 rawPos;
varying vec3 viewerdir;
varying vec3 lightdir;
@ -31,6 +31,7 @@ uniform float visibility;
uniform float overcast;
uniform float ground_scattering;
uniform mat4 osg_ViewMatrixInverse;
vec3 specular_light;
@ -72,6 +73,7 @@ void main(void)
vec3 shadedFogColor = vec3(0.65, 0.67, 0.78);
rawPos = (osg_ViewMatrixInverse *gl_ModelViewMatrix * gl_Vertex).xyz;
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;

View file

@ -194,13 +194,63 @@
<col>3</col>
</text>
<text>
<enable>
<property>/sim/rendering/shaders/skydome</property>
</enable>
<label>Ice cover</label>
<halign>left</halign>
<row>4</row>
<col>0</col>
</text>
<text>
<enable>
<property>/sim/rendering/shaders/skydome</property>
</enable>
<label>none</label>
<halign>right</halign>
<row>4</row>
<col>1</col>
</text>
<slider>
<enable>
<property>/sim/rendering/shaders/skydome</property>
</enable>
<name>ice-cover</name>
<row>4</row>
<col>2</col>
<min>0.0</min>
<max>1.0</max>
<live>true</live>
<property>/environment/sea/surface/ice-cover</property>
<binding>
<command>dialog-apply</command>
<object-name>ice-cover</object-name>
</binding>
</slider>
<text>
<enable>
<property>/sim/rendering/shaders/skydome</property>
</enable>
<label>thick</label>
<halign>left</halign>
<row>4</row>
<col>3</col>
</text>
<text>
<enable>
<property>/sim/rendering/shaders/skydome</property>
</enable>
<label>Dust cover</label>
<halign>left</halign>
<row>4</row>
<row>5</row>
<col>0</col>
</text>
@ -210,7 +260,7 @@
</enable>
<label>none</label>
<halign>right</halign>
<row>4</row>
<row>5</row>
<col>1</col>
</text>
@ -219,7 +269,7 @@
<property>/sim/rendering/shaders/skydome</property>
</enable>
<name>dust-level</name>
<row>4</row>
<row>5</row>
<col>2</col>
<min>0.0</min>
<max>0.7</max>
@ -237,7 +287,7 @@
</enable>
<label>dusty</label>
<halign>left</halign>
<row>4</row>
<row>5</row>
<col>3</col>
</text>
@ -247,7 +297,7 @@
</enable>
<label>Wetness</label>
<halign>left</halign>
<row>5</row>
<row>6</row>
<col>0</col>
</text>
@ -257,7 +307,7 @@
</enable>
<label>dry</label>
<halign>right</halign>
<row>5</row>
<row>6</row>
<col>1</col>
</text>
@ -266,7 +316,7 @@
<property>/sim/rendering/shaders/skydome</property>
</enable>
<name>wetness</name>
<row>5</row>
<row>6</row>
<col>2</col>
<min>0.0</min>
<max>0.7</max>
@ -284,7 +334,7 @@
</enable>
<label>wet</label>
<halign>left</halign>
<row>5</row>
<row>6</row>
<col>3</col>
</text>
@ -295,7 +345,7 @@
</enable>
<label>Vegetation</label>
<halign>left</halign>
<row>6</row>
<row>7</row>
<col>0</col>
</text>
@ -305,7 +355,7 @@
</enable>
<label>none</label>
<halign>right</halign>
<row>6</row>
<row>7</row>
<col>1</col>
</text>
@ -314,7 +364,7 @@
<property>/sim/rendering/shaders/skydome</property>
</enable>
<name>lichen-level</name>
<row>6</row>
<row>7</row>
<col>2</col>
<min>0.0</min>
<max>0.7</max>
@ -332,7 +382,7 @@
</enable>
<label>mossy</label>
<halign>left</halign>
<row>6</row>
<row>7</row>
<col>3</col>
</text>
@ -343,7 +393,7 @@
</enable>
<label>Season (experimental)</label>
<halign>left</halign>
<row>7</row>
<row>8</row>
<col>0</col>
</text>
@ -353,7 +403,7 @@
</enable>
<label>summer</label>
<halign>right</halign>
<row>7</row>
<row>8</row>
<col>1</col>
</text>
@ -362,7 +412,7 @@
<property>/sim/rendering/shaders/skydome</property>
</enable>
<name>season</name>
<row>7</row>
<row>8</row>
<col>2</col>
<min>0.0</min>
<max>2.0</max>
@ -380,7 +430,7 @@
</enable>
<label>late autumn</label>
<halign>left</halign>
<row>7</row>
<row>8</row>
<col>3</col>
</text>