Added relief code to new effects and shaders
This commit is contained in:
parent
0ff2d597f5
commit
8e645e61f5
5 changed files with 250 additions and 17 deletions
|
@ -23,8 +23,22 @@
|
|||
<wrap-t>repeat</wrap-t>
|
||||
<internal-format>normalized</internal-format>
|
||||
</texture>
|
||||
<texture n="5">
|
||||
<image>Textures.high/Terrain/forest-relief.png</image>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>repeat</wrap-s>
|
||||
<wrap-t>repeat</wrap-t>
|
||||
<internal-format>normalized</internal-format>
|
||||
</texture>
|
||||
<snow-level><use>/sim/rendering/snow-level-m</use></snow-level>
|
||||
<depth-factor type="float">0.01</depth-factor>
|
||||
<canopy-height type="float">15.0</canopy-height>
|
||||
<quality-level><use>/sim/rendering/quality-level</use></quality-level>
|
||||
</parameters>
|
||||
<generate>
|
||||
<tangent type="int">6</tangent>
|
||||
<binormal type="int">7</binormal>
|
||||
</generate>
|
||||
<technique n="9">
|
||||
<predicate>
|
||||
<and>
|
||||
|
@ -97,10 +111,27 @@
|
|||
<use>texture[4]/internal-format</use>
|
||||
</internal-format>
|
||||
</texture-unit>
|
||||
|
||||
<texture-unit>
|
||||
<unit>5</unit>
|
||||
<image><use>texture[5]/image</use></image>
|
||||
<filter><use>texture[5]/filter</use></filter>
|
||||
<wrap-s><use>texture[5]/wrap-s</use></wrap-s>
|
||||
<wrap-t><use>texture[5]/wrap-t</use></wrap-t>
|
||||
<internal-format>
|
||||
<use>texture[5]/internal-format</use>
|
||||
</internal-format>
|
||||
</texture-unit>
|
||||
<program>
|
||||
<vertex-shader>Shaders/forest.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/forest.frag</fragment-shader>
|
||||
<attribute>
|
||||
<name>tangent</name>
|
||||
<index>6</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>binormal</name>
|
||||
<index>7</index>
|
||||
</attribute>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>NoiseTex</name>
|
||||
|
@ -122,11 +153,26 @@
|
|||
<type>sampler-1d</type>
|
||||
<value type="int">3</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>NormalTex</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">5</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>depth_factor</name>
|
||||
<type>float</type>
|
||||
<value><use>depth-factor</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>snowlevel</name>
|
||||
<type>float</type>
|
||||
<value><use>snow-level</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>quality_level</name>
|
||||
<type>float</type>
|
||||
<value><use>quality-level</use></value>
|
||||
</uniform>
|
||||
</pass>
|
||||
</technique>
|
||||
</PropertyList>
|
||||
|
|
|
@ -23,8 +23,22 @@
|
|||
<wrap-t>repeat</wrap-t>
|
||||
<internal-format>normalized</internal-format>
|
||||
</texture>
|
||||
<texture n="5">
|
||||
<image>Textures.high/Terrain/forest-relief.png</image>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>repeat</wrap-s>
|
||||
<wrap-t>repeat</wrap-t>
|
||||
<internal-format>normalized</internal-format>
|
||||
</texture>
|
||||
<snow-level><use>/sim/rendering/snow-level-m</use></snow-level>
|
||||
<depth-factor type="float">0.01</depth-factor>
|
||||
<canopy-height type="float">15.0</canopy-height>
|
||||
<quality-level><use>/sim/rendering/quality-level</use></quality-level>
|
||||
</parameters>
|
||||
<generate>
|
||||
<tangent type="int">6</tangent>
|
||||
<binormal type="int">7</binormal>
|
||||
</generate>
|
||||
<technique n="9">
|
||||
<predicate>
|
||||
<and>
|
||||
|
@ -97,10 +111,27 @@
|
|||
<use>texture[4]/internal-format</use>
|
||||
</internal-format>
|
||||
</texture-unit>
|
||||
|
||||
<texture-unit>
|
||||
<unit>5</unit>
|
||||
<image><use>texture[5]/image</use></image>
|
||||
<filter><use>texture[5]/filter</use></filter>
|
||||
<wrap-s><use>texture[5]/wrap-s</use></wrap-s>
|
||||
<wrap-t><use>texture[5]/wrap-t</use></wrap-t>
|
||||
<internal-format>
|
||||
<use>texture[5]/internal-format</use>
|
||||
</internal-format>
|
||||
</texture-unit>
|
||||
<program>
|
||||
<vertex-shader>Shaders/forest.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/forest.frag</fragment-shader>
|
||||
<attribute>
|
||||
<name>tangent</name>
|
||||
<index>6</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>binormal</name>
|
||||
<index>7</index>
|
||||
</attribute>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>NoiseTex</name>
|
||||
|
@ -122,11 +153,26 @@
|
|||
<type>sampler-1d</type>
|
||||
<value type="int">3</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>NormalTex</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">5</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>depth_factor</name>
|
||||
<type>float</type>
|
||||
<value><use>depth-factor</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>snowlevel</name>
|
||||
<type>float</type>
|
||||
<value><use>snow-level</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>quality_level</name>
|
||||
<type>float</type>
|
||||
<value><use>quality-level</use></value>
|
||||
</uniform>
|
||||
</pass>
|
||||
</technique>
|
||||
</PropertyList>
|
||||
|
|
|
@ -23,8 +23,22 @@
|
|||
<wrap-t>repeat</wrap-t>
|
||||
<internal-format>normalized</internal-format>
|
||||
</texture>
|
||||
<texture n="5">
|
||||
<image>Textures.high/Terrain/forest-relief.png</image>
|
||||
<filter>linear-mipmap-linear</filter>
|
||||
<wrap-s>repeat</wrap-s>
|
||||
<wrap-t>repeat</wrap-t>
|
||||
<internal-format>normalized</internal-format>
|
||||
</texture>
|
||||
<snow-level><use>/sim/rendering/snow-level-m</use></snow-level>
|
||||
<depth-factor type="float">0.01</depth-factor>
|
||||
<canopy-height type="float">15.0</canopy-height>
|
||||
<quality-level><use>/sim/rendering/quality-level</use></quality-level>
|
||||
</parameters>
|
||||
<generate>
|
||||
<tangent type="int">6</tangent>
|
||||
<binormal type="int">7</binormal>
|
||||
</generate>
|
||||
<technique n="9">
|
||||
<predicate>
|
||||
<and>
|
||||
|
@ -97,10 +111,27 @@
|
|||
<use>texture[4]/internal-format</use>
|
||||
</internal-format>
|
||||
</texture-unit>
|
||||
|
||||
<texture-unit>
|
||||
<unit>5</unit>
|
||||
<image><use>texture[5]/image</use></image>
|
||||
<filter><use>texture[5]/filter</use></filter>
|
||||
<wrap-s><use>texture[5]/wrap-s</use></wrap-s>
|
||||
<wrap-t><use>texture[5]/wrap-t</use></wrap-t>
|
||||
<internal-format>
|
||||
<use>texture[5]/internal-format</use>
|
||||
</internal-format>
|
||||
</texture-unit>
|
||||
<program>
|
||||
<vertex-shader>Shaders/forest.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/forest.frag</fragment-shader>
|
||||
<attribute>
|
||||
<name>tangent</name>
|
||||
<index>6</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>binormal</name>
|
||||
<index>7</index>
|
||||
</attribute>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>NoiseTex</name>
|
||||
|
@ -122,11 +153,26 @@
|
|||
<type>sampler-1d</type>
|
||||
<value type="int">3</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>NormalTex</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">5</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>depth_factor</name>
|
||||
<type>float</type>
|
||||
<value><use>depth-factor</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>snowlevel</name>
|
||||
<type>float</type>
|
||||
<value><use>snow-level</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>quality_level</name>
|
||||
<type>float</type>
|
||||
<value><use>quality-level</use></value>
|
||||
</uniform>
|
||||
</pass>
|
||||
</technique>
|
||||
</PropertyList>
|
||||
|
|
|
@ -1,23 +1,90 @@
|
|||
#version 120
|
||||
|
||||
varying vec4 rawpos;
|
||||
varying vec4 rawpos;
|
||||
varying vec4 ecPosition;
|
||||
varying vec3 VTangent;
|
||||
varying vec3 VBinormal;
|
||||
varying vec3 VNormal;
|
||||
varying vec3 Normal;
|
||||
varying float bump;
|
||||
|
||||
uniform sampler3D NoiseTex;
|
||||
uniform sampler2D SampleTex;
|
||||
uniform sampler1D ColorsTex;
|
||||
uniform sampler2D SampleTex2;
|
||||
uniform sampler2D NormalTex;
|
||||
uniform float depth_factor;
|
||||
|
||||
uniform float quality_level; // From /sim/rendering/quality-level
|
||||
uniform float snowlevel; // From /sim/rendering/snow-level-m
|
||||
|
||||
const float scale = 1.0;
|
||||
int linear_search_steps = 10;
|
||||
|
||||
float ray_intersect(sampler2D reliefMap, vec2 dp, vec2 ds)
|
||||
{
|
||||
|
||||
float size = 1.0 / float(linear_search_steps);
|
||||
float depth = 0.0;
|
||||
float best_depth = 1.0;
|
||||
|
||||
for(int i = 0; i < linear_search_steps - 1; ++i)
|
||||
{
|
||||
depth += size;
|
||||
float t = texture2D(reliefMap, dp + ds * depth).a;
|
||||
if(best_depth > 0.996)
|
||||
if(depth >= t)
|
||||
best_depth = depth;
|
||||
}
|
||||
depth = best_depth;
|
||||
|
||||
const int binary_search_steps = 5;
|
||||
|
||||
for(int i = 0; i < binary_search_steps; ++i)
|
||||
{
|
||||
size *= 0.5;
|
||||
float t = texture2D(reliefMap, dp + ds * depth).a;
|
||||
if(depth >= t)
|
||||
{
|
||||
best_depth = depth;
|
||||
depth -= 2.0 * size;
|
||||
}
|
||||
depth += size;
|
||||
}
|
||||
|
||||
return(best_depth);
|
||||
}
|
||||
|
||||
|
||||
void main (void)
|
||||
{
|
||||
|
||||
if ( quality_level >= 3.5 ) {
|
||||
linear_search_steps = 20;
|
||||
}
|
||||
vec2 uv, dp, ds;
|
||||
vec3 N;
|
||||
float d;
|
||||
if ( bump > 0.9 && quality_level >= 2.0 )
|
||||
{
|
||||
vec3 V = normalize(ecPosition.xyz);
|
||||
float a = dot(VNormal, -V);
|
||||
vec2 s = vec2(dot(V, VTangent), dot(V, VBinormal));
|
||||
s *= depth_factor / a;
|
||||
ds = s;
|
||||
dp = gl_TexCoord[0].st;
|
||||
d = ray_intersect(NormalTex, dp, ds);
|
||||
|
||||
uv = dp + ds * d;
|
||||
N = texture2D(NormalTex, uv).xyz * 2.0 - 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
uv = gl_TexCoord[0].st;
|
||||
N = vec3(0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
|
||||
vec4 basecolor = texture2D(SampleTex, rawpos.xy*0.000144);
|
||||
vec4 basecolor2 = texture2D(SampleTex2, rawpos.xy*0.000144);
|
||||
|
||||
|
@ -89,13 +156,32 @@ void main (void)
|
|||
c1 = mix(c1, c5, clamp(0.65, -n, 0.6));
|
||||
}
|
||||
|
||||
N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal);
|
||||
vec3 l = gl_LightSource[0].position.xyz;
|
||||
vec3 diffuse = gl_Color.rgb * max(0.0, dot(N, l));
|
||||
float shadow_factor = 1.0;
|
||||
|
||||
vec4 constantColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
// Shadow
|
||||
if ( quality_level >= 3.0 ) {
|
||||
dp += ds * d;
|
||||
vec3 sl = normalize( vec3( dot( l, VTangent ), dot( l, VBinormal ), dot( -l, VNormal ) ) );
|
||||
ds = sl.xy * depth_factor / sl.z;
|
||||
dp -= ds * d;
|
||||
float dl = ray_intersect(NormalTex, dp, ds);
|
||||
if ( dl < d - 0.05 )
|
||||
shadow_factor = dot( constantColor.xyz, vec3( 1.0, 1.0, 1.0 ) ) * 0.25;
|
||||
}
|
||||
// end shadow
|
||||
|
||||
|
||||
|
||||
//old snow
|
||||
//c1 = mix(c1, clamp(n+nvL[2]*4.1+vec4(0.1, 0.1, nvL[2]*2.2, 1.0), 0.7, 1.0), smoothstep(snowlevel+300.0, snowlevel+360.0, (rawpos.z)+nvL[1]*3000.0));
|
||||
|
||||
vec3 diffuse = gl_Color.rgb * max(0.4, dot(VNormal, gl_LightSource[0].position.xyz));
|
||||
vec4 ambient_light = gl_LightSource[0].diffuse * vec4(diffuse, 1.0);
|
||||
//diffuse = gl_Color.rgb * max(0.4, dot(VNormal, gl_LightSource[0].position.xyz));
|
||||
vec4 ambient_light = gl_LightSource[0].diffuse * shadow_factor * vec4(diffuse, 1.0);
|
||||
|
||||
c1 *= ambient_light;
|
||||
vec4 finalColor = c1;
|
||||
|
|
|
@ -1,19 +1,28 @@
|
|||
#version 120
|
||||
varying vec4 rawpos;
|
||||
varying vec4 ecPosition;
|
||||
varying vec3 VNormal;
|
||||
varying vec3 VTangent;
|
||||
varying vec3 VBinormal;
|
||||
varying vec3 Normal;
|
||||
varying vec4 constantColor;
|
||||
varying float bump;
|
||||
|
||||
varying vec4 rawpos;
|
||||
varying vec4 ecPosition;
|
||||
varying vec3 VNormal;
|
||||
varying vec3 Normal;
|
||||
attribute vec3 tangent;
|
||||
attribute vec3 binormal;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
|
||||
rawpos = gl_Vertex;
|
||||
ecPosition = gl_ModelViewMatrix * gl_Vertex;
|
||||
VNormal = normalize(gl_NormalMatrix * gl_Normal);
|
||||
ecPosition = gl_ModelViewMatrix * rawpos;
|
||||
Normal = normalize(gl_Normal);
|
||||
|
||||
gl_FrontColor = gl_Color;
|
||||
VNormal = gl_NormalMatrix * gl_Normal;
|
||||
VTangent = gl_NormalMatrix * tangent;
|
||||
VBinormal = gl_NormalMatrix * binormal;
|
||||
bump = 1.0;
|
||||
|
||||
gl_FrontColor = gl_Color;
|
||||
constantColor = gl_FrontMaterial.emission
|
||||
+ gl_FrontColor * (gl_LightModel.ambient + gl_LightSource[0].ambient);
|
||||
gl_Position = ftransform();
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue