WS30: Improve water line features
This commit is contained in:
parent
8cbbbcdc8a
commit
4d3466216a
8 changed files with 1180 additions and 121 deletions
86
Effects/ws30-water.eff
Normal file
86
Effects/ws30-water.eff
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PropertyList>
|
||||
<name>Effects/ws30-water</name>
|
||||
<inherits-from>Effects/ws30</inherits-from>
|
||||
<!--
|
||||
ALS ultra shaders.
|
||||
-->
|
||||
|
||||
<technique n="5">
|
||||
<pass n="0">
|
||||
<program n="0">
|
||||
<fragment-shader n="0">Shaders/ws30-water-ALS-ultra.frag</fragment-shader>
|
||||
</program>
|
||||
</pass>
|
||||
</technique>
|
||||
|
||||
<!-- ALS High and Medium settings technique.
|
||||
Uses quality_level and tquality_level uniforms to change quality in fragment shader.
|
||||
-->
|
||||
|
||||
<technique n="6">
|
||||
<pass n="0">
|
||||
<program n="0">
|
||||
<fragment-shader n="0">Shaders/ws30-water-ALS-detailed.frag</fragment-shader>
|
||||
</program>
|
||||
</pass>
|
||||
</technique>
|
||||
|
||||
<!-- ALS low settings technique -->
|
||||
|
||||
<technique n="7">
|
||||
<pass n="0">
|
||||
<program n="0">
|
||||
<fragment-shader n="0">Shaders/ws30-water-ALS.frag</fragment-shader>
|
||||
</program>
|
||||
</pass>
|
||||
</technique>
|
||||
|
||||
<!-- Non-ALS technique with texture rotation -->
|
||||
<technique n="11">
|
||||
<pass n="0">
|
||||
<!-- Hardcoded texture unit as we don't do a material lookup -->
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
<type>2d</type>
|
||||
<image>Textures/Terrain/water.png</image>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>repeat</wrap-s>
|
||||
<wrap-t>repeat</wrap-t>
|
||||
<environment>
|
||||
<mode>modulate</mode>
|
||||
</environment>
|
||||
</texture-unit>
|
||||
|
||||
<program n="0">
|
||||
<!-- Note different index -->
|
||||
<fragment-shader n="1">Shaders/ws30-water-q1.frag</fragment-shader>
|
||||
</program>
|
||||
</pass>
|
||||
</technique>
|
||||
|
||||
<!-- Minimal technique -->
|
||||
<technique n="12">
|
||||
<pass n="0">
|
||||
<!-- Hardcoded texture unit as we don't do a material lookup -->
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
<type>2d</type>
|
||||
<image>Textures/Terrain/water.png</image>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>repeat</wrap-s>
|
||||
<wrap-t>repeat</wrap-t>
|
||||
<environment>
|
||||
<mode>modulate</mode>
|
||||
</environment>
|
||||
</texture-unit>
|
||||
|
||||
<program n="0">
|
||||
<!-- Note different index -->
|
||||
<fragment-shader n="1">Shaders/ws30-water-q1.frag</fragment-shader>
|
||||
</program>
|
||||
</pass>
|
||||
</technique>
|
||||
|
||||
|
||||
</PropertyList>
|
|
@ -1,117 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PropertyList>
|
||||
<name>Effects/ws30water</name>
|
||||
<inherits-from>Effects/water</inherits-from>
|
||||
<technique n="1">
|
||||
<pass n="0">
|
||||
<!-- Hardcoded texture unit as we don't do a material lookup -->
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
<type>2d</type>
|
||||
<image>Textures/Terrain/water.png</image>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>repeat</wrap-s>
|
||||
<wrap-t>repeat</wrap-t>
|
||||
<environment>
|
||||
<mode>modulate</mode>
|
||||
</environment>
|
||||
</texture-unit>
|
||||
</pass>
|
||||
</technique>
|
||||
<technique n="2">
|
||||
<pass n="0">
|
||||
<!-- Hardcoded texture unit as we don't do a material lookup -->
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
<type>2d</type>
|
||||
<image>Textures/Terrain/water.png</image>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>repeat</wrap-s>
|
||||
<wrap-t>repeat</wrap-t>
|
||||
<environment>
|
||||
<mode>modulate</mode>
|
||||
</environment>
|
||||
</texture-unit>
|
||||
</pass>
|
||||
</technique>
|
||||
<technique n="3">
|
||||
<pass n="0">
|
||||
<!-- Hardcoded texture unit as we don't do a material lookup -->
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
<type>2d</type>
|
||||
<image>Textures/Terrain/water.png</image>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>repeat</wrap-s>
|
||||
<wrap-t>repeat</wrap-t>
|
||||
<environment>
|
||||
<mode>modulate</mode>
|
||||
</environment>
|
||||
</texture-unit>
|
||||
</pass>
|
||||
</technique>
|
||||
<technique n="4">
|
||||
<pass n="0">
|
||||
<!-- Hardcoded texture unit as we don't do a material lookup -->
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
<type>2d</type>
|
||||
<image>Textures/Terrain/water.png</image>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>repeat</wrap-s>
|
||||
<wrap-t>repeat</wrap-t>
|
||||
<environment>
|
||||
<mode>modulate</mode>
|
||||
</environment>
|
||||
</texture-unit>
|
||||
</pass>
|
||||
</technique>
|
||||
<technique n="5">
|
||||
<pass n="0">
|
||||
<!-- Hardcoded texture unit as we don't do a material lookup -->
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
<type>2d</type>
|
||||
<image>Textures/Terrain/water.png</image>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>repeat</wrap-s>
|
||||
<wrap-t>repeat</wrap-t>
|
||||
<environment>
|
||||
<mode>modulate</mode>
|
||||
</environment>
|
||||
</texture-unit>
|
||||
</pass>
|
||||
</technique>
|
||||
<technique n="11">
|
||||
<pass n="0">
|
||||
<!-- Hardcoded texture unit as we don't do a material lookup -->
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
<type>2d</type>
|
||||
<image>Textures/Terrain/water.png</image>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>repeat</wrap-s>
|
||||
<wrap-t>repeat</wrap-t>
|
||||
<environment>
|
||||
<mode>modulate</mode>
|
||||
</environment>
|
||||
</texture-unit>
|
||||
</pass>
|
||||
</technique>
|
||||
<technique n="12">
|
||||
<pass n="0">
|
||||
<!-- Hardcoded texture unit as we don't do a material lookup -->
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
<type>2d</type>
|
||||
<image>Textures/Terrain/water.png</image>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>repeat</wrap-s>
|
||||
<wrap-t>repeat</wrap-t>
|
||||
<environment>
|
||||
<mode>modulate</mode>
|
||||
</environment>
|
||||
</texture-unit>
|
||||
</pass>
|
||||
</technique>
|
||||
</PropertyList>
|
|
@ -628,7 +628,7 @@
|
|||
<material n="3001" include="Materials/base/water.xml">
|
||||
<name>ws30water</name>
|
||||
<name>ws30coastline</name>
|
||||
<effect>Effects/ws30water</effect>
|
||||
<effect>Effects/ws30-water</effect>
|
||||
<texture>Terrain/water.png</texture>
|
||||
</material>
|
||||
|
||||
|
@ -690,7 +690,7 @@
|
|||
</material>
|
||||
|
||||
<material n="3004">
|
||||
<effect>Effects/water-inland</effect>
|
||||
<effect>Effects/ws30-water</effect>
|
||||
<name>ws30River</name>
|
||||
<texture>Terrain/water-lake.png</texture>
|
||||
<line-feature-tex-x0>0.0</line-feature-tex-x0>
|
||||
|
|
|
@ -447,7 +447,7 @@ void main()
|
|||
//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.01) {
|
||||
if (coast.b > 0.05) {
|
||||
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
|
||||
|
@ -456,7 +456,7 @@ void main()
|
|||
|
||||
|
||||
// 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(generateWaterTexel(), texel, smoothstep(0.1,0.9,(coast.b + coast.a) / 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)) {
|
||||
|
|
319
Shaders/ws30-water-ALS-detailed.frag
Normal file
319
Shaders/ws30-water-ALS-detailed.frag
Normal file
|
@ -0,0 +1,319 @@
|
|||
// WS30 FRAGMENT SHADER
|
||||
|
||||
// -*-C++-*-
|
||||
#version 130
|
||||
#extension GL_EXT_texture_array : enable
|
||||
// written by Thorsten Renk, Oct 2011, based on default.frag
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// TEST PHASE TOGGLES AND CONTROLS
|
||||
//
|
||||
|
||||
// Development tools:
|
||||
// Reduce haze to almost zero, while preserving lighting. Useful for observing distant tiles.
|
||||
// Keeps the calculation overhead. This can be used for profiling.
|
||||
// Possible values: 0:Normal, 1:Reduced haze.
|
||||
const int reduce_haze_without_removing_calculation_overhead = 0;
|
||||
|
||||
// Remove haze and lighting and shows just the texture.
|
||||
// Useful for checking texture rendering and scenery.
|
||||
// The compiler will likely optimise out the haze and lighting calculations.
|
||||
// Possible values: 0:Normal, 1:Just the texture.
|
||||
const int remove_haze_and_lighting = 0;
|
||||
|
||||
// Use built-in water shader. Use for testing impact of ws30-water.frag
|
||||
const int water_shader = 1;
|
||||
|
||||
//
|
||||
// End of test phase controls
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// written by Thorsten Renk, Oct 2011, based on default.frag
|
||||
// Ambient term comes in gl_Color.rgb.
|
||||
varying vec4 light_diffuse_comp;
|
||||
varying vec3 normal;
|
||||
varying vec3 relPos;
|
||||
varying vec2 ground_tex_coord;
|
||||
varying vec2 rawPos;
|
||||
varying vec3 worldPos;
|
||||
// Testing code:
|
||||
//vec3 worldPos = vec3(5000.0, 6000.0, 7000.0) + vec3(vec2(rawPos), 600.0); // vec3(100.0, 10.0, 3.0);
|
||||
//varying vec2 orthoTexCoord;
|
||||
varying vec4 eyePos;
|
||||
|
||||
|
||||
uniform sampler2D landclass;
|
||||
uniform sampler2DArray textureArray;
|
||||
uniform sampler2D perlin;
|
||||
|
||||
//varying float yprime_alt;
|
||||
//varying float mie_angle;
|
||||
varying float steepness;
|
||||
|
||||
|
||||
uniform float visibility;
|
||||
uniform float avisibility;
|
||||
uniform float scattering;
|
||||
uniform float terminator;
|
||||
uniform float terrain_alt;
|
||||
uniform float hazeLayerAltitude;
|
||||
uniform float overcast;
|
||||
uniform float eye_alt;
|
||||
uniform float snowlevel;
|
||||
uniform float dust_cover_factor;
|
||||
uniform float lichen_cover_factor;
|
||||
uniform float wetness;
|
||||
uniform float fogstructure;
|
||||
uniform float snow_thickness_factor;
|
||||
uniform float cloud_self_shading;
|
||||
uniform float season;
|
||||
|
||||
uniform int quality_level;
|
||||
uniform int tquality_level;
|
||||
|
||||
// Passed from VPBTechnique, not the Effect
|
||||
uniform float fg_tileWidth;
|
||||
uniform float fg_tileHeight;
|
||||
uniform bool fg_photoScenery;
|
||||
uniform vec4 fg_dimensionsArray[128];
|
||||
uniform vec4 fg_ambientArray[128];
|
||||
uniform vec4 fg_diffuseArray[128];
|
||||
uniform vec4 fg_specularArray[128];
|
||||
uniform vec4 fg_textureLookup1[128];
|
||||
uniform vec4 fg_textureLookup2[128];
|
||||
uniform vec4 fg_materialParams1[128];
|
||||
uniform vec4 fg_materialParams3[128];
|
||||
uniform mat4 fg_zUpTransform;
|
||||
uniform vec3 fg_modelOffset;
|
||||
|
||||
const float EarthRadius = 5800000.0;
|
||||
const float terminator_width = 200000.0;
|
||||
|
||||
//Testing phase: Why are these in global scope in WS2 shaders?
|
||||
float alt;
|
||||
float eShade;
|
||||
float yprime_alt;
|
||||
float mie_angle;
|
||||
|
||||
float shadow_func (in float x, in float y, in float noise, in float dist);
|
||||
float DotNoise2D(in vec2 coord, in float wavelength, in float fractionalMaxDotSize, in float dot_density);
|
||||
float Noise2D(in vec2 coord, in float wavelength);
|
||||
float Noise3D(in vec3 coord, in float wavelength);
|
||||
float SlopeLines2D(in vec2 coord, in vec2 gradDir, in float wavelength, in float steepness);
|
||||
float Strata3D(in vec3 coord, in float wavelength, in float variation);
|
||||
float fog_func (in float targ, in float alt);
|
||||
float rayleigh_in_func(in float dist, in float air_pollution, in float avisibility, in float eye_alt, in float vertex_alt);
|
||||
float alt_factor(in float eye_alt, in float vertex_alt);
|
||||
float light_distance_fading(in float dist);
|
||||
float fog_backscatter(in float avisibility);
|
||||
|
||||
vec3 rayleigh_out_shift(in vec3 color, in float outscatter);
|
||||
vec3 get_hazeColor(in float light_arg);
|
||||
vec3 searchlight();
|
||||
vec3 landing_light(in float offset, in float offsetv);
|
||||
vec3 filter_combined (in vec3 color) ;
|
||||
|
||||
float getShadowing();
|
||||
vec3 getClusteredLightsContribution(vec3 p, vec3 n, vec3 texel);
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////
|
||||
// Test-phase code:
|
||||
|
||||
|
||||
// These should be sent as uniforms
|
||||
|
||||
// Tile dimensions in meters
|
||||
// vec2 tile_size = vec2(tile_width , tile_height);
|
||||
// Testing: texture coords are sent flipped right now:
|
||||
|
||||
// Note tile_size is defined in the shader include: ws30-landclass-search-functions.frag.
|
||||
// vec2 tile_size = vec2(tile_height , tile_width);
|
||||
|
||||
// From noise.frag
|
||||
float rand2D(in vec2 co);
|
||||
|
||||
// Create random landclasses without a texture lookup to stress test.
|
||||
// Each square of square_size in m is assigned a random landclass value.
|
||||
int get_random_landclass(in vec2 co, in vec2 tile_size);
|
||||
|
||||
// End Test-phase code
|
||||
////////////////////////
|
||||
|
||||
// These functions, and other function they depend on, are defined
|
||||
// in ws30-ALS-landclass-search.frag.
|
||||
|
||||
// Lookup a ground texture at a point based on the landclass at that point, without visible
|
||||
// seams at coordinate discontinuities or at landclass boundaries where texture are switched.
|
||||
// The partial derivatives of the tile_coord at the fragment is needed to adjust for
|
||||
// the stretching of different textures, so that the correct mip-map level is looked
|
||||
// up and there are no seams.
|
||||
// Texture types: 0: base texture, 1: grain texture, 2: gradient texture, 3 dot texture,
|
||||
// 4: mix texture, 5: detail texture.
|
||||
|
||||
vec4 lookup_ground_texture_array(in int texture_type, in vec2 ground_texture_coord, in int landclass_id,
|
||||
in vec4 dFdx_and_dFdy);
|
||||
|
||||
|
||||
// Look up the landclass id [0 .. 255] for this particular fragment.
|
||||
// Lookup id of any neighbouring landclass that is within the search distance.
|
||||
// Searches are performed in upto 4 directions right now, but only one landclass is looked up
|
||||
// Create a mix factor weighting the influences of nearby landclasses
|
||||
void get_landclass_id(in vec2 tile_coord, in vec4 dFdx_and_dFdy,
|
||||
out int landclass_id, out ivec4 neighbor_landclass_ids,
|
||||
out int num_unique_neighbors,out vec4 mix_factor
|
||||
);
|
||||
|
||||
|
||||
// Look up the texel of the specified texture type (e.g. grain or detail textures) for this fragment
|
||||
// and any neighbor texels, then mix.
|
||||
|
||||
vec4 get_mixed_texel(in int texture_type, in vec2 g_texture_coord,
|
||||
in int landclass_id, in int num_unique_neighbors,
|
||||
in ivec4 neighbor_texel_landclass_ids, in vec4 neighbor_mix_factors,
|
||||
in vec4 dFdx_and_dFdy
|
||||
);
|
||||
|
||||
// Determine the texel and material parameters for a particular fragment,
|
||||
// Taking into account photoscenery etc.
|
||||
void get_material(in int landclass,
|
||||
in vec2 ground_tex_coord,
|
||||
in vec4 dxdy_gc,
|
||||
out float mat_shininess,
|
||||
out vec4 mat_ambient,
|
||||
out vec4 mat_diffuse,
|
||||
out vec4 mat_specular,
|
||||
out vec4 dxdy,
|
||||
out vec2 st
|
||||
);
|
||||
|
||||
// Apply the ALS haze model to a specific fragment
|
||||
vec4 applyHaze(inout vec4 fragColor,
|
||||
inout vec3 hazeColor,
|
||||
in vec3 secondary_light,
|
||||
in float ct,
|
||||
in float hazeLayerAltitude,
|
||||
in float visibility,
|
||||
in float avisibility,
|
||||
in float dist,
|
||||
in float lightArg,
|
||||
in float mie_angle);
|
||||
|
||||
// Procedurally generate a water texel for this fragment
|
||||
vec4 generateWaterTexel();
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
|
||||
yprime_alt = light_diffuse_comp.a;
|
||||
//diffuse_term.a = 1.0;
|
||||
mie_angle = gl_Color.a;
|
||||
float effective_scattering = min(scattering, cloud_self_shading);
|
||||
|
||||
// distance to fragment
|
||||
|
||||
float dist = length(relPos);
|
||||
// angle of view vector with horizon
|
||||
float ct = dot(vec3(0.0, 0.0, 1.0), relPos)/dist;
|
||||
|
||||
// Altitude of fragment above sea level
|
||||
float msl_altitude = (relPos.z + eye_alt);
|
||||
|
||||
|
||||
vec3 shadedFogColor = vec3(0.55, 0.67, 0.88);
|
||||
// this is taken from default.frag
|
||||
vec3 n;
|
||||
float NdotL, NdotHV, fogFactor;
|
||||
vec3 lightDir = gl_LightSource[0].position.xyz;
|
||||
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
|
||||
//vec3 halfVector = normalize(normalize(lightDir) + normalize(ecViewdir));
|
||||
vec4 texel;
|
||||
vec4 snow_texel;
|
||||
vec4 detail_texel;
|
||||
vec4 mix_texel;
|
||||
vec4 fragColor;
|
||||
vec4 specular = vec4(0.0);
|
||||
float intensity;
|
||||
|
||||
// Material/texel properties
|
||||
float mat_shininess;
|
||||
vec2 st;
|
||||
vec4 mat_ambient, mat_diffuse, mat_specular, dxdy;
|
||||
|
||||
// get noise at different wavelengths
|
||||
|
||||
// used: 5m, 5m gradient, 10m, 10m gradient: heightmap of the closeup terrain, 10m also snow
|
||||
// 50m: detail texel
|
||||
// 250m: detail texel
|
||||
// 500m: distortion and overlay
|
||||
// 1500m: overlay, detail, dust, fog
|
||||
// 2000m: overlay, detail, snow, fog
|
||||
|
||||
float noise_10m;
|
||||
float noise_5m;
|
||||
noise_10m = Noise2D(rawPos.xy, 10.0);
|
||||
noise_5m = Noise2D(rawPos.xy ,5.0);
|
||||
|
||||
float noisegrad_10m;
|
||||
float noisegrad_5m;
|
||||
|
||||
float noise_50m = Noise2D(rawPos.xy, 50.0);;
|
||||
|
||||
|
||||
float noise_250m = Noise3D(worldPos.xyz,250.0);
|
||||
float noise_500m = Noise3D(worldPos.xyz, 500.0);
|
||||
float noise_1500m = Noise3D(worldPos.xyz, 1500.0);
|
||||
float noise_2000m = Noise3D(worldPos.xyz, 2000.0);
|
||||
|
||||
|
||||
|
||||
//
|
||||
|
||||
|
||||
// get the texels
|
||||
|
||||
// Oct 27 2021:
|
||||
// Geometry is in the form of roughly rectangular 'tiles'
|
||||
// with a mesh forming a grid with regular spacing.
|
||||
// Each vertex in the mesh is given an elevation
|
||||
|
||||
// Tile dimensions in m
|
||||
// Testing: created from two float uniforms in global scope. Should be sent as a vec2
|
||||
// vec2 tile_size
|
||||
|
||||
// Tile texture coordinates range [0..1] over the tile 'rectangle'
|
||||
|
||||
// This is a water fragment, so calculate the fragment color procedurally
|
||||
fragColor = generateWaterTexel();
|
||||
fragColor.rgb += getClusteredLightsContribution(eyePos.xyz, n, fragColor.rgb);
|
||||
|
||||
float lightArg = (terminator-yprime_alt)/100000.0;
|
||||
vec3 hazeColor = get_hazeColor(lightArg);
|
||||
gl_FragColor = applyHaze(fragColor, hazeColor, vec3(0.0), ct, hazeLayerAltitude, visibility, avisibility, dist, lightArg, mie_angle);
|
||||
|
||||
|
||||
// Testing phase controls:
|
||||
if (remove_haze_and_lighting == 1)
|
||||
{
|
||||
gl_FragColor = texel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
435
Shaders/ws30-water-ALS-ultra.frag
Normal file
435
Shaders/ws30-water-ALS-ultra.frag
Normal file
|
@ -0,0 +1,435 @@
|
|||
// WS30 FRAGMENT SHADER
|
||||
|
||||
// -*-C++-*-
|
||||
#version 130
|
||||
#extension GL_EXT_texture_array : enable
|
||||
// written by Thorsten Renk, Oct 2011, based on default.frag
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// TEST PHASE TOGGLES AND CONTROLS
|
||||
//
|
||||
// Remove haze and lighting and shows just the texture.
|
||||
// Useful for checking texture rendering and scenery.
|
||||
// The compiler will likely optimise out the haze and lighting calculations.
|
||||
// Possible values: 0:Normal, 1:Just the texture.
|
||||
const int remove_haze_and_lighting = 0;
|
||||
|
||||
// Randomise texture lookups for 5 non-base textures e.g. mix_texture, detaile_texture etc.
|
||||
// Each landclass is assigned 5 random textures from the ground texture array.
|
||||
// This simulates a worst case possible texture lookup scenario, without needing access to material parameters.
|
||||
// This does not simulate multiple texture sets, of which there may be up-to 4.
|
||||
// The performance will likely be worse than in a real situation - there might be fewer textures
|
||||
// for mix, detail and other textures. This might be easier on the GPUs texture caches.
|
||||
// Possible values: 0: disabled (default),
|
||||
// 1: enabled,
|
||||
// 2: remove texture array lookups for 5 textures - only base texture + neighbour base textures
|
||||
const int randomise_texture_lookups = 0;
|
||||
|
||||
// Use built-in water shader. Use for testing impact of ws30-water.frag
|
||||
const int water_shader = 1;
|
||||
|
||||
//
|
||||
// End of test phase controls
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
// Ambient term comes in gl_Color.rgb.
|
||||
varying vec4 light_diffuse_comp;
|
||||
varying vec3 normal;
|
||||
varying vec3 relPos;
|
||||
varying vec2 ground_tex_coord;
|
||||
varying vec3 worldPos;
|
||||
varying vec2 rawPos;
|
||||
varying vec3 ecViewdir;
|
||||
varying vec2 grad_dir;
|
||||
varying vec4 ecPosition;
|
||||
varying float steepness;
|
||||
|
||||
uniform sampler2D landclass;
|
||||
uniform sampler2DArray textureArray;
|
||||
uniform sampler2D perlin;
|
||||
|
||||
uniform float visibility;
|
||||
uniform float avisibility;
|
||||
uniform float scattering;
|
||||
uniform float terminator;
|
||||
uniform float terrain_alt;
|
||||
uniform float hazeLayerAltitude;
|
||||
uniform float overcast;
|
||||
uniform float eye_alt;
|
||||
uniform float snowlevel;
|
||||
uniform float dust_cover_factor;
|
||||
uniform float lichen_cover_factor;
|
||||
uniform float wetness;
|
||||
uniform float fogstructure;
|
||||
uniform float snow_thickness_factor;
|
||||
uniform float cloud_self_shading;
|
||||
uniform float season;
|
||||
uniform float air_pollution;
|
||||
|
||||
uniform float WindE;
|
||||
uniform float WindN;
|
||||
uniform float landing_light1_offset;
|
||||
uniform float landing_light2_offset;
|
||||
uniform float landing_light3_offset;
|
||||
uniform float osg_SimulationTime;
|
||||
|
||||
uniform int wind_effects;
|
||||
uniform int cloud_shadow_flag;
|
||||
uniform int use_searchlight;
|
||||
uniform int use_landing_light;
|
||||
uniform int use_alt_landing_light;
|
||||
// Testing code: Currently hardcoded to 2000, to allow noise functions to run while waiting for landclass lookup(s)
|
||||
uniform int swatch_size; //in metres, typically 1000 or 2000
|
||||
|
||||
// Passed from VPBTechnique, not the Effect
|
||||
uniform float fg_tileWidth;
|
||||
uniform float fg_tileHeight;
|
||||
uniform bool fg_photoScenery;
|
||||
// Material parameters, from material definitions and effect defaults, for each landclass.
|
||||
// xsize and ysize
|
||||
uniform vec4 fg_dimensionsArray[128];
|
||||
// RGBA ambient color
|
||||
uniform vec4 fg_ambientArray[128];
|
||||
// RGBA diffuse color
|
||||
uniform vec4 fg_diffuseArray[128];
|
||||
// RGBA specular color
|
||||
uniform vec4 fg_specularArray[128];
|
||||
// Indicies of textures in the ground texture array for different
|
||||
// texture slots (grain, gradient, dot, mix, detail) for each landclass
|
||||
uniform vec4 fg_textureLookup1[128];
|
||||
uniform vec4 fg_textureLookup2[128];
|
||||
// Each element of a vec4 contains a different materials parameter.
|
||||
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;
|
||||
|
||||
const float terminator_width = 200000.0;
|
||||
|
||||
float shadow_func (in float x, in float y, in float noise, in float dist);
|
||||
float DotNoise2D(in vec2 coord, in float wavelength, in float fractionalMaxDotSize, in float dot_density);
|
||||
float Noise2D(in vec2 coord, in float wavelength);
|
||||
float Noise3D(in vec3 coord, in float wavelength);
|
||||
float SlopeLines2D(in vec2 coord, in vec2 gradDir, in float wavelength, in float steepness);
|
||||
float Strata3D(in vec3 coord, in float wavelength, in float variation);
|
||||
float fog_func (in float targ, in float alt);
|
||||
float rayleigh_in_func(in float dist, in float air_pollution, in float avisibility, in float eye_alt, in float vertex_alt);
|
||||
float alt_factor(in float eye_alt, in float vertex_alt);
|
||||
float light_distance_fading(in float dist);
|
||||
float fog_backscatter(in float avisibility);
|
||||
|
||||
vec3 rayleigh_out_shift(in vec3 color, in float outscatter);
|
||||
vec3 get_hazeColor(in float light_arg);
|
||||
vec3 searchlight();
|
||||
vec3 landing_light(in float offset, in float offsetv);
|
||||
vec3 filter_combined (in vec3 color) ;
|
||||
|
||||
float getShadowing();
|
||||
vec3 getClusteredLightsContribution(vec3 p, vec3 n, vec3 texel);
|
||||
|
||||
|
||||
// a fade function for procedural scales which are smaller than a pixel
|
||||
|
||||
float detail_fade (in float scale, in float angle, in float dist)
|
||||
{
|
||||
float fade_dist = 2000.0 * scale * angle/max(pow(steepness,4.0), 0.1);
|
||||
|
||||
return 1.0 - smoothstep(0.5 * fade_dist, fade_dist, dist);
|
||||
}
|
||||
|
||||
//////////////////////////
|
||||
// Test-phase code:
|
||||
|
||||
|
||||
// These should be sent as uniforms
|
||||
|
||||
// Tile dimensions in meters
|
||||
// vec2 tile_size = vec2(fg_tileWidth , fg_tileHeight);
|
||||
// Testing: texture coords are sent flipped right now:
|
||||
|
||||
// Note tile_size is defined in the shader include: ws30-landclass-search-functions.frag.
|
||||
//vec2 tile_size = vec2(fg_tileHeight , fg_tileWidth);
|
||||
|
||||
|
||||
// Uniform array lookup functions example:
|
||||
// Access data[] as if it was a 1-d array of floats
|
||||
// with data sorted as rows of data values for each row of texture variants
|
||||
// using index for the relevant value
|
||||
/*
|
||||
float getFloatFromArrayData(int i)
|
||||
{
|
||||
int n = int(floor(float(i/4.0)));
|
||||
vec4 v4 = someArray[n];
|
||||
int index_within_v4 = int(mod(float(i),4.0));
|
||||
float value = v4[index_within_v4];
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
vec4 getVec4FromArrayData(int i)
|
||||
{
|
||||
return (vec4(getFloatFromArrayData(i), getFloatFromArrayData(i+1), getFloatFromArrayData(i+2), getFloatFromArrayData(i+3)));
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// From noise.frag
|
||||
float rand2D(in vec2 co);
|
||||
|
||||
|
||||
// Generates a full precision 32 bit random number from 2 seeds
|
||||
// as well as 6 random integers between 0 and factor that are rescaled 0.0-1.0
|
||||
// by re-using the significant figures from the full precision number.
|
||||
// This avoids having to generate 6 random numbers when
|
||||
// limited variation is needed: say 6 numbers with 100 levels (i.e between 0 and 100).
|
||||
// Seed 2 is incremented so the function can be called again to generate
|
||||
// a different set of numbers
|
||||
float get6_rand_nums(in float PRNGseed1,
|
||||
inout float PRNGseed2, float factor, out float [6] random_integers
|
||||
);
|
||||
|
||||
|
||||
|
||||
// Create random landclasses without a texture lookup to stress test.
|
||||
// Each square of square_size in m is assigned a random landclass value.
|
||||
int get_random_landclass(in vec2 co, in vec2 tile_size);
|
||||
|
||||
// End Test-phase code
|
||||
////////////////////////
|
||||
|
||||
|
||||
// These functions, and other function they depend on, are defined
|
||||
// in ws30-ALS-landclass-search.frag.
|
||||
|
||||
// Lookup a ground texture at a point based on the landclass at that point, without visible
|
||||
// seams at coordinate discontinuities or at landclass boundaries where texture are switched.
|
||||
// The partial derivatives of the tile_coord at the fragment is needed to adjust for
|
||||
// the stretching of different textures, so that the correct mip-map level is looked
|
||||
// up and there are no seams.
|
||||
// Texture types: 0: base texture, 1: grain texture, 2: gradient texture, 3 dot texture,
|
||||
// 4: mix texture, 5: detail texture.
|
||||
|
||||
vec4 lookup_ground_texture_array(in int texture_type, in vec2 ground_texture_coord, in int landclass_id,
|
||||
in vec4 dFdx_and_dFdy);
|
||||
|
||||
|
||||
// Look up the landclass id [0 .. 255] for this particular fragment.
|
||||
// Lookup id of any neighbouring landclass that is within the search distance.
|
||||
// Searches are performed in upto 4 directions right now, but only one landclass is looked up
|
||||
// Create a mix factor werighting the influences of nearby landclasses
|
||||
void get_landclass_id(in vec2 tile_coord, in vec4 dFdx_and_dFdy,
|
||||
out int landclass_id, out ivec4 neighbor_landclass_ids,
|
||||
out int num_unique_neighbors,out vec4 mix_factor
|
||||
);
|
||||
|
||||
|
||||
// Look up the texel of the specified texture type (e.g. grain or detail textures) for this fragment
|
||||
// and any neighbor texels, then mix.
|
||||
|
||||
vec4 get_mixed_texel(in int texture_type, in vec2 g_texture_coord,
|
||||
in int landclass_id, in int num_unique_neighbors,
|
||||
in ivec4 neighbor_texel_landclass_ids, in vec4 neighbor_mix_factors,
|
||||
in vec4 dFdx_and_dFdy
|
||||
);
|
||||
|
||||
// Determine the texel and material parameters for a particular fragment,
|
||||
// Taking into account photoscenery etc.
|
||||
void get_material(in int landclass,
|
||||
in vec2 ground_tex_coord,
|
||||
in vec4 dxdy_gc,
|
||||
out float mat_shininess,
|
||||
out vec4 mat_ambient,
|
||||
out vec4 mat_diffuse,
|
||||
out vec4 mat_specular,
|
||||
out vec4 dxdy,
|
||||
out vec2 st
|
||||
);
|
||||
|
||||
// Apply the ALS haze model to a specific fragment
|
||||
vec4 applyHaze(inout vec4 fragColor,
|
||||
inout vec3 hazeColor,
|
||||
in vec3 secondary_light,
|
||||
in float ct,
|
||||
in float hazeLayerAltitude,
|
||||
in float visibility,
|
||||
in float avisibility,
|
||||
in float dist,
|
||||
in float lightArg,
|
||||
in float mie_angle);
|
||||
|
||||
// Procedurally generate a water texel for this fragment
|
||||
vec4 generateWaterTexel();
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
float yprime_alt = light_diffuse_comp.a;
|
||||
//diffuse_term.a = 1.0;
|
||||
float mie_angle = gl_Color.a;
|
||||
float effective_scattering = min(scattering, cloud_self_shading);
|
||||
|
||||
// distance to fragment
|
||||
float dist = length(relPos);
|
||||
// angle of view vector with horizon
|
||||
float ct = dot(vec3(0.0, 0.0, 1.0), relPos)/dist;
|
||||
// float altitude of fragment above sea level
|
||||
float msl_altitude = (relPos.z + eye_alt);
|
||||
|
||||
|
||||
// this is taken from default.frag
|
||||
float NdotL, NdotHV, fogFactor;
|
||||
vec3 n = normalize(normal);
|
||||
vec3 lightDir = gl_LightSource[0].position.xyz;
|
||||
vec3 halfVector = normalize(normalize(lightDir) + normalize(ecViewdir));
|
||||
vec3 secondary_light = vec3 (0.0,0.0,0.0);
|
||||
|
||||
|
||||
// Material/texel properties
|
||||
float mat_shininess;
|
||||
vec2 st;
|
||||
vec4 mat_ambient, mat_diffuse, mat_specular, dxdy;
|
||||
|
||||
vec4 texel;
|
||||
vec4 snow_texel;
|
||||
vec4 detail_texel;
|
||||
vec4 mix_texel;
|
||||
vec4 grain_texel;
|
||||
vec4 dot_texel;
|
||||
vec4 gradient_texel;
|
||||
|
||||
vec4 fragColor;
|
||||
vec4 specular = vec4(0.0);
|
||||
float intensity;
|
||||
|
||||
// Wind motion of the overlay noise simulating movement of vegetation and loose debris
|
||||
|
||||
vec2 windPos;
|
||||
|
||||
if (wind_effects > 1)
|
||||
{
|
||||
float windSpeed = length(vec2 (WindE,WindN)) /3.0480;
|
||||
// interfering sine wave wind pattern
|
||||
float sineTerm = sin(0.35 * windSpeed * osg_SimulationTime + 0.05 * (rawPos.x + rawPos.y));
|
||||
sineTerm = sineTerm + sin(0.3 * windSpeed * osg_SimulationTime + 0.04 * (rawPos.x + rawPos.y));
|
||||
sineTerm = sineTerm + sin(0.22 * windSpeed * osg_SimulationTime + 0.05 * (rawPos.x + rawPos.y));
|
||||
sineTerm = sineTerm/3.0;
|
||||
// non-linear amplification to simulate gusts
|
||||
sineTerm = sineTerm * sineTerm;//smoothstep(0.2, 1.0, sineTerm);
|
||||
|
||||
// wind starts moving dust and leaves at around 8 m/s
|
||||
float timeArg = 0.01 * osg_SimulationTime * windSpeed * smoothstep(8.0, 15.0, windSpeed);
|
||||
timeArg = timeArg + 0.02 * sineTerm;
|
||||
|
||||
windPos = vec2 (rawPos.x + WindN * timeArg, rawPos.y + WindE * timeArg);
|
||||
}
|
||||
else
|
||||
{
|
||||
windPos = rawPos.xy;
|
||||
}
|
||||
|
||||
|
||||
// get noise at different wavelengths in units of swatch_size
|
||||
// original assumed 4km texture.
|
||||
|
||||
// used: 5m, 5m gradient, 10m, 10m gradient: heightmap of the closeup terrain, 10m also snow
|
||||
// 50m: detail texel
|
||||
// 250m: detail texel
|
||||
// 500m: distortion and overlay
|
||||
// 1500m: overlay, detail, dust, fog
|
||||
// 2000m: overlay, detail, snow, fog
|
||||
|
||||
// Perlin noise
|
||||
|
||||
float noise_10m = Noise2D(rawPos.xy, 10.0);
|
||||
float noise_5m = Noise2D(rawPos.xy ,5.0);
|
||||
float noise_2m = Noise2D(rawPos.xy ,2.0);
|
||||
float noise_1m = Noise2D(rawPos.xy ,1.0);
|
||||
float noise_01m = Noise2D(windPos.xy, 0.1);
|
||||
|
||||
// Noise relative to swatch size
|
||||
float noise_25m = Noise2D(rawPos.xy, swatch_size*0.000625);
|
||||
float noise_50m = Noise2D(rawPos.xy, swatch_size*0.00125);
|
||||
float noise_250m = Noise3D(worldPos.xyz,swatch_size*0.0625);
|
||||
float noise_500m = Noise3D(worldPos.xyz, swatch_size*0.125);
|
||||
float noise_1500m = Noise3D(worldPos.xyz, swatch_size*0.3750);
|
||||
float noise_2000m = Noise3D(worldPos.xyz, swatch_size*0.5);
|
||||
float noise_4000m = Noise3D(worldPos.xyz, swatch_size);
|
||||
|
||||
float dotnoisegrad_10m;
|
||||
|
||||
|
||||
// slope noise
|
||||
float slopenoise_50m = SlopeLines2D(rawPos.xy, grad_dir, 50.0, steepness);
|
||||
float slopenoise_100m = SlopeLines2D(rawPos.xy, grad_dir, 100.0, steepness);
|
||||
|
||||
float snownoise_25m = mix(noise_25m, slopenoise_50m, clamp(3.0*(1.0-steepness),0.0,1.0));
|
||||
float snownoise_50m = mix(noise_50m, slopenoise_100m, clamp(3.0*(1.0-steepness),0.0,1.0));
|
||||
|
||||
// get the texels
|
||||
|
||||
|
||||
|
||||
float distortion_factor = 1.0;
|
||||
vec2 stprime;
|
||||
int flag = 1;
|
||||
int mix_flag = 1;
|
||||
float noise_term;
|
||||
float snow_alpha;
|
||||
|
||||
// Oct 27 2021:
|
||||
// Geometry is in the form of roughly rectangular 'tiles'
|
||||
// with a mesh forming a grid with regular spacing.
|
||||
// Each vertex in the mesh is given an elevation
|
||||
|
||||
// Tile dimensions in m
|
||||
// Testing: created from two float uniforms in global scope. Should be sent as a vec2
|
||||
// vec2 tile_size
|
||||
|
||||
// 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(waterline_min_steepness,waterline_max_steepness,steepness));
|
||||
fragColor = generateWaterTexel();
|
||||
fragColor.rgb += getClusteredLightsContribution(ecPosition.xyz, n, fragColor.rgb);
|
||||
|
||||
float lightArg = (terminator-yprime_alt)/100000.0;
|
||||
vec3 hazeColor = get_hazeColor(lightArg);
|
||||
|
||||
// Rayleigh color shift due to out-scattering
|
||||
float rayleigh_length = 0.5 * avisibility * (2.5 - 1.9 * air_pollution)/alt_factor(eye_alt, msl_altitude);
|
||||
float outscatter = 1.0-exp(-dist/rayleigh_length);
|
||||
fragColor.rgb = rayleigh_out_shift(fragColor.rgb,outscatter);
|
||||
|
||||
// Rayleigh color shift due to in-scattering
|
||||
|
||||
float rShade = 1.0 - 0.9 * smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt + 420000.0);
|
||||
//float lightIntensity = length(diffuse_term.rgb)/1.73 * rShade;
|
||||
float lightIntensity = length(hazeColor * effective_scattering) * rShade;
|
||||
vec3 rayleighColor = vec3 (0.17, 0.52, 0.87) * lightIntensity;
|
||||
float rayleighStrength = rayleigh_in_func(dist, air_pollution, avisibility/max(lightIntensity,0.05), eye_alt, msl_altitude);
|
||||
fragColor.rgb = mix(fragColor.rgb, rayleighColor,rayleighStrength);
|
||||
|
||||
gl_FragColor = applyHaze(fragColor, hazeColor, secondary_light, ct, hazeLayerAltitude, visibility, avisibility, dist, lightArg, mie_angle);
|
||||
|
||||
// Testing phase controls:
|
||||
if (remove_haze_and_lighting == 1)
|
||||
{
|
||||
gl_FragColor = texel;
|
||||
}
|
||||
}
|
243
Shaders/ws30-water-ALS.frag
Normal file
243
Shaders/ws30-water-ALS.frag
Normal file
|
@ -0,0 +1,243 @@
|
|||
// WS30 FRAGMENT SHADER
|
||||
|
||||
// -*-C++-*-
|
||||
#version 130
|
||||
#extension GL_EXT_texture_array : enable
|
||||
// written by Thorsten Renk, Oct 2011, based on default.frag
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// TEST PHASE TOGGLES AND CONTROLS
|
||||
//
|
||||
|
||||
// Development tools:
|
||||
// Reduce haze to almost zero, while preserving lighting. Useful for observing distant tiles.
|
||||
// Keeps the calculation overhead. This can be used for profiling.
|
||||
// Possible values: 0:Normal, 1:Reduced haze.
|
||||
const int reduce_haze_without_removing_calculation_overhead = 0;
|
||||
|
||||
// Remove haze and lighting and shows just the texture.
|
||||
// Useful for checking texture rendering and scenery.
|
||||
// The compiler will likely optimise out the haze and lighting calculations.
|
||||
// Possible values: 0:Normal, 1:Just the texture.
|
||||
const int remove_haze_and_lighting = 0;
|
||||
|
||||
// Use built-in water shader. Use for testing impact of ws30-water.frag
|
||||
const int water_shader = 1;
|
||||
|
||||
//
|
||||
// End of test phase controls
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Ambient term comes in gl_Color.rgb.
|
||||
varying vec4 light_diffuse_comp;
|
||||
varying vec3 normal;
|
||||
varying vec3 relPos;
|
||||
varying vec2 ground_tex_coord;
|
||||
|
||||
uniform sampler2D landclass;
|
||||
uniform sampler2DArray textureArray;
|
||||
|
||||
varying float yprime_alt;
|
||||
varying float mie_angle;
|
||||
varying vec4 ecPosition;
|
||||
|
||||
uniform float visibility;
|
||||
uniform float avisibility;
|
||||
uniform float scattering;
|
||||
uniform float terminator;
|
||||
uniform float terrain_alt;
|
||||
uniform float hazeLayerAltitude;
|
||||
uniform float overcast;
|
||||
uniform float eye_alt;
|
||||
uniform float cloud_self_shading;
|
||||
|
||||
// Passed from VPBTechnique, not the Effect
|
||||
// Passed from VPBTechnique, not the Effect
|
||||
uniform float fg_tileWidth;
|
||||
uniform float fg_tileHeight;
|
||||
uniform bool fg_photoScenery;
|
||||
uniform vec4 fg_dimensionsArray[128];
|
||||
uniform vec4 fg_ambientArray[128];
|
||||
uniform vec4 fg_diffuseArray[128];
|
||||
uniform vec4 fg_specularArray[128];
|
||||
uniform vec4 fg_textureLookup1[128];
|
||||
uniform vec4 fg_textureLookup2[128];
|
||||
uniform vec4 fg_materialParams3[128];
|
||||
|
||||
#define MAX_TEXTURES 8
|
||||
uniform mat4 fg_zUpTransform;
|
||||
uniform vec3 fg_modelOffset;
|
||||
|
||||
const float EarthRadius = 5800000.0;
|
||||
const float terminator_width = 200000.0;
|
||||
|
||||
float alt;
|
||||
float eShade;
|
||||
|
||||
float fog_func (in float targ, in float alt);
|
||||
vec3 get_hazeColor(in float light_arg);
|
||||
vec3 filter_combined (in vec3 color) ;
|
||||
|
||||
float shadow_func (in float x, in float y, in float noise, in float dist);
|
||||
float DotNoise2D(in vec2 coord, in float wavelength, in float fractionalMaxDotSize, in float dot_density);
|
||||
float Noise2D(in vec2 coord, in float wavelength);
|
||||
float Noise3D(in vec3 coord, in float wavelength);
|
||||
float SlopeLines2D(in vec2 coord, in vec2 gradDir, in float wavelength, in float steepness);
|
||||
float Strata3D(in vec3 coord, in float wavelength, in float variation);
|
||||
float fog_func (in float targ, in float alt);
|
||||
float rayleigh_in_func(in float dist, in float air_pollution, in float avisibility, in float eye_alt, in float vertex_alt);
|
||||
float alt_factor(in float eye_alt, in float vertex_alt);
|
||||
float light_distance_fading(in float dist);
|
||||
float fog_backscatter(in float avisibility);
|
||||
|
||||
vec3 rayleigh_out_shift(in vec3 color, in float outscatter);
|
||||
vec3 get_hazeColor(in float light_arg);
|
||||
vec3 searchlight();
|
||||
vec3 landing_light(in float offset, in float offsetv);
|
||||
vec3 filter_combined (in vec3 color) ;
|
||||
|
||||
float getShadowing();
|
||||
vec3 getClusteredLightsContribution(vec3 p, vec3 n, vec3 texel);
|
||||
vec4 generateWaterTexel();
|
||||
|
||||
// Not used
|
||||
float luminance(vec3 color)
|
||||
{
|
||||
return dot(vec3(0.212671, 0.715160, 0.072169), color);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////
|
||||
// Test-phase code:
|
||||
|
||||
// These should be sent as uniforms
|
||||
|
||||
// Tile dimensions in meters
|
||||
// vec2 tile_size = vec2(tile_width , tile_height);
|
||||
// Testing: texture coords are sent flipped right now:
|
||||
|
||||
// Note tile_size is defined in the shader include: ws30-landclass-search-functions.frag.
|
||||
// vec2 tile_size = vec2(tile_height , tile_width);
|
||||
|
||||
// From noise.frag
|
||||
float rand2D(in vec2 co);
|
||||
|
||||
// Create random landclasses without a texture lookup to stress test.
|
||||
// Each square of square_size in m is assigned a random landclass value.
|
||||
int get_random_landclass(in vec2 co, in vec2 tile_size);
|
||||
|
||||
// End Test-phase code
|
||||
////////////////////////
|
||||
|
||||
// These functions, and other function they depend on, are defined
|
||||
// in ws30-ALS-landclass-search.frag.
|
||||
|
||||
// Lookup a ground texture at a point based on the landclass at that point, without visible
|
||||
// seams at coordinate discontinuities or at landclass boundaries where texture are switched.
|
||||
// The partial derivatives of the tile_coord at the fragment is needed to adjust for
|
||||
// the stretching of different textures, so that the correct mip-map level is looked
|
||||
// up and there are no seams.
|
||||
// Texture types: 0: base texture, 1: grain texture, 2: gradient texture, 3 dot texture,
|
||||
// 4: mix texture, 5: detail texture.
|
||||
|
||||
vec4 lookup_ground_texture_array(in int texture_type, in vec2 ground_texture_coord, in int landclass_id,
|
||||
in vec4 dFdx_and_dFdy);
|
||||
|
||||
|
||||
// Look up the landclass id [0 .. 255] for this particular fragment.
|
||||
// Lookup id of any neighbouring landclass that is within the search distance.
|
||||
// Searches are performed in upto 4 directions right now, but only one landclass is looked up
|
||||
// Create a mix factor werighting the influences of nearby landclasses
|
||||
void get_landclass_id(in vec2 tile_coord, in vec4 dFdx_and_dFdy,
|
||||
out int landclass_id, out ivec4 neighbor_landclass_ids,
|
||||
out int num_unique_neighbors,out vec4 mix_factor
|
||||
);
|
||||
|
||||
|
||||
// Look up the texel of the specified texture type (e.g. grain or detail textures) for this fragment
|
||||
// and any neighbor texels, then mix.
|
||||
|
||||
vec4 get_mixed_texel(in int texture_type, in vec2 g_texture_coord,
|
||||
in int landclass_id, in int num_unique_neighbors,
|
||||
in ivec4 neighbor_texel_landclass_ids, in vec4 neighbor_mix_factors,
|
||||
in vec4 dFdx_and_dFdy
|
||||
);
|
||||
|
||||
// Determine the texel and material parameters for a particular fragment,
|
||||
// Taking into account photoscenery etc.
|
||||
void get_material(in int landclass,
|
||||
in vec2 ground_tex_coord,
|
||||
in vec4 dxdy_gc,
|
||||
out float mat_shininess,
|
||||
out vec4 mat_ambient,
|
||||
out vec4 mat_diffuse,
|
||||
out vec4 mat_specular,
|
||||
out vec4 dxdy,
|
||||
out vec2 st
|
||||
);
|
||||
|
||||
// Apply the ALS haze model to a specific fragment
|
||||
vec4 applyHaze(inout vec4 fragColor,
|
||||
inout vec3 hazeColor,
|
||||
in vec3 secondary_light,
|
||||
in float ct,
|
||||
in float hazeLayerAltitude,
|
||||
in float visibility,
|
||||
in float avisibility,
|
||||
in float dist,
|
||||
in float lightArg,
|
||||
in float mie_angle);
|
||||
|
||||
// Procedurally generate a water texel for this fragment
|
||||
vec4 generateWaterTexel();
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 shadedFogColor = vec3(0.55, 0.67, 0.88);
|
||||
// this is taken from default.frag
|
||||
float NdotL, NdotHV, fogFactor;
|
||||
vec3 n = normalize(normal);
|
||||
vec3 lightDir = gl_LightSource[0].position.xyz;
|
||||
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
|
||||
vec4 texel;
|
||||
vec4 fragColor;
|
||||
vec4 specular = vec4(0.0);
|
||||
float intensity;
|
||||
|
||||
// Material/texel properties
|
||||
float mat_shininess;
|
||||
vec2 st;
|
||||
vec4 mat_ambient, mat_diffuse, mat_specular, dxdy;
|
||||
|
||||
// This is a water fragment, so calculate the fragment color procedurally
|
||||
fragColor = generateWaterTexel();
|
||||
fragColor.rgb += getClusteredLightsContribution(ecPosition.xyz, n, fragColor.rgb);
|
||||
|
||||
// angle with horizon
|
||||
float dist = length(relPos);
|
||||
float ct = dot(vec3(0.0, 0.0, 1.0), relPos)/dist;
|
||||
|
||||
float lightArg = (terminator-yprime_alt)/100000.0;
|
||||
vec3 hazeColor = get_hazeColor(lightArg);
|
||||
gl_FragColor = applyHaze(fragColor, hazeColor, vec3(0.0), ct, hazeLayerAltitude, visibility, avisibility, dist, lightArg, mie_angle);
|
||||
|
||||
// Testing phase controls:
|
||||
if (remove_haze_and_lighting == 1)
|
||||
{
|
||||
gl_FragColor = texel;
|
||||
}
|
||||
}
|
93
Shaders/ws30-water-q1.frag
Normal file
93
Shaders/ws30-water-q1.frag
Normal file
|
@ -0,0 +1,93 @@
|
|||
// WS30 FRAGMENT SHADER
|
||||
|
||||
// -*-C++-*-
|
||||
#version 130
|
||||
#extension GL_EXT_texture_array : enable
|
||||
|
||||
varying vec3 normal;
|
||||
varying vec4 ecPosition;
|
||||
|
||||
uniform sampler2D landclass;
|
||||
uniform sampler2DArray atlas;
|
||||
uniform sampler2D perlin;
|
||||
|
||||
// Passed from VPBTechnique, not the Effect
|
||||
uniform float fg_tileWidth;
|
||||
uniform float fg_tileHeight;
|
||||
uniform bool fg_photoScenery;
|
||||
uniform vec4 fg_dimensionsArray[128];
|
||||
uniform vec4 fg_ambientArray[128];
|
||||
uniform vec4 fg_diffuseArray[128];
|
||||
uniform vec4 fg_specularArray[128];
|
||||
uniform vec4 fg_textureLookup1[128];
|
||||
uniform vec4 fg_textureLookup2[128];
|
||||
uniform mat4 fg_zUpTransform;
|
||||
uniform vec3 fg_modelOffset;
|
||||
|
||||
// See include_fog.frag
|
||||
uniform int fogType;
|
||||
vec3 fog_Func(vec3 color, int type);
|
||||
|
||||
// See Shaders/shadows-include.frag
|
||||
float getShadowing();
|
||||
|
||||
// See Shaders/clustered-include.frag
|
||||
vec3 getClusteredLightsContribution(vec3 p, vec3 n, vec3 texel);
|
||||
|
||||
void main()
|
||||
{
|
||||
float NdotL, NdotHV, fogFactor;
|
||||
vec3 lightDir = gl_LightSource[0].position.xyz;
|
||||
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
|
||||
vec4 texel;
|
||||
vec4 fragColor;
|
||||
vec4 specular = vec4(0.0);
|
||||
|
||||
// Material properties.
|
||||
// Material properties.
|
||||
vec4 mat_diffuse, mat_ambient, mat_specular;
|
||||
float mat_shininess;
|
||||
|
||||
// Simple water texture
|
||||
texel = texture(landclass, gl_TexCoord[0].st);
|
||||
|
||||
// Color Mode is always AMBIENT_AND_DIFFUSE, which means
|
||||
// using a base colour of white for ambient/diffuse,
|
||||
// rather than the material color from ambientArray/diffuseArray.
|
||||
mat_ambient = vec4(1.0,1.0,1.0,1.0);
|
||||
mat_diffuse = vec4(1.0,1.0,1.0,1.0);
|
||||
mat_specular = vec4(0.8,0.8,0.8,1.0);
|
||||
mat_shininess = 1.2;
|
||||
|
||||
|
||||
vec4 color = mat_ambient * (gl_LightModel.ambient + gl_LightSource[0].ambient);
|
||||
|
||||
// If gl_Color.a == 0, this is a back-facing polygon and the
|
||||
// normal should be reversed.
|
||||
vec3 n = (2.0 * gl_Color.a - 1.0) * normal;
|
||||
n = normalize(n);
|
||||
NdotL = dot(n, lightDir);
|
||||
|
||||
if (NdotL > 0.0) {
|
||||
float shadowmap = getShadowing();
|
||||
color += mat_diffuse * NdotL * shadowmap;
|
||||
NdotHV = max(dot(n, halfVector), 0.0);
|
||||
if (mat_shininess > 0.0)
|
||||
specular.rgb = (mat_specular.rgb
|
||||
* gl_LightSource[0].specular.rgb
|
||||
* pow(NdotHV, mat_shininess)
|
||||
* shadowmap);
|
||||
}
|
||||
color.a = mat_diffuse.a;
|
||||
|
||||
// This shouldn't be necessary, but our lighting becomes very
|
||||
// saturated. Clamping the color before modulating by the texture
|
||||
// is closer to what the OpenGL fixed function pipeline does.
|
||||
color = clamp(color, 0.0, 1.0);
|
||||
|
||||
fragColor = color * texel + specular;
|
||||
fragColor.rgb += getClusteredLightsContribution(ecPosition.xyz, n, texel.rgb);
|
||||
|
||||
fragColor.rgb = fog_Func(fragColor.rgb, fogType);
|
||||
gl_FragColor = fragColor;
|
||||
}
|
Loading…
Add table
Reference in a new issue