1
0
Fork 0

First iteration of the urban effect with relief mapping. Relief map by HB-Gral.

This commit is contained in:
fredb 2010-03-12 22:25:19 +00:00
parent b00cfd84a8
commit c9236ad565
6 changed files with 214 additions and 0 deletions

90
Effects/urban.eff Normal file
View file

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/urban</name>
<inherits-from>Effects/terrain-default</inherits-from>
<parameters>
<texture n="2">
<image>Textures.high/Terrain/city1-relief.png</image>
<filter>linear-mipmap-linear</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
<internal-format>normalized</internal-format>
</texture>
</parameters>
<technique n="9">
<predicate>
<and>
<property>/sim/rendering/urban-shader</property>
<property>/sim/rendering/shader-effects</property>
<or>
<less-equal>
<value type="float">2.0</value>
<glversion/>
</less-equal>
<and>
<extension-supported>GL_ARB_shader_objects</extension-supported>
<extension-supported>GL_ARB_shading_language_100</extension-supported>
<extension-supported>GL_ARB_vertex_shader</extension-supported>
<extension-supported>GL_ARB_fragment_shader</extension-supported>
</and>
</or>
</and>
</predicate>
<pass>
<lighting>true</lighting>
<material>
<ambient><use>material/ambient</use></ambient>
<diffuse><use>material/diffuse</use></diffuse>
<specular><use>material/specular</use></specular>
<color-mode>ambient-and-diffuse</color-mode>
</material>
<blend><use>transparent</use></blend>
<alpha-test><use>transparent</use></alpha-test>
<shade-model>smooth</shade-model>
<cull-face>back</cull-face>
<render-bin>
<bin-number><use>render-bin/bin-number</use></bin-number>
<bin-name><use>render-bin/bin-name</use></bin-name>
</render-bin>
<texture-unit>
<unit>0</unit>
<image><use>texture[0]/image</use></image>
<filter><use>texture[0]/filter</use></filter>
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
<internal-format>
<use>texture[0]/internal-format</use>
</internal-format>
</texture-unit>
<texture-unit>
<unit>1</unit>
<image><use>texture[2]/image</use></image>
<filter><use>texture[2]/filter</use></filter>
<wrap-s><use>texture[2]/wrap-s</use></wrap-s>
<wrap-t><use>texture[2]/wrap-t</use></wrap-t>
<internal-format>
<use>texture[2]/internal-format</use>
</internal-format>
</texture-unit>
<program>
<vertex-shader>Shaders/urban.vert</vertex-shader>
<fragment-shader>Shaders/urban.frag</fragment-shader>
</program>
<uniform>
<name>BaseTex</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>NormalTex</name>
<type>sampler-2d</type>
<value type="int">1</value>
</uniform>
<uniform>
<name>depth_factor</name>
<type>float</type>
<value type="float">0.005</value>
</uniform>
</pass>
</technique>
</PropertyList>

85
Shaders/urban.frag Normal file
View file

@ -0,0 +1,85 @@
#version 120
varying vec4 rawpos;
varying vec4 ecPosition;
varying vec3 VNormal;
varying vec3 VTangent;
varying vec3 VBinormal;
varying vec3 Normal;
varying vec4 constantColor;
uniform sampler2D BaseTex;
uniform sampler2D NormalTex;
uniform float depth_factor;
const float scale = 1.0;
float ray_intersect(sampler2D reliefMap, vec2 dp, vec2 ds)
{
const int linear_search_steps = 10;
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)
{
vec3 V = normalize(ecPosition.xyz);
vec3 s = vec3(dot(V, VTangent), dot(V, VBinormal), dot(VNormal, V));
vec2 ds = s.xy * depth_factor / s.z;
vec2 dp = gl_TexCoord[0].st;
float d = ray_intersect(NormalTex, dp, ds);
vec2 uv = dp + ds * d;
vec3 N = texture2D(NormalTex, uv).xyz * 2.0 - 1.0;
float fogFactor;
float fogCoord = ecPosition.z;
const float LOG2 = 1.442695;
fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord * LOG2);
fogFactor = clamp(fogFactor, 0.0, 1.0);
vec4 c1 = texture2D(BaseTex, uv);
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));
vec4 ambient_light = constantColor + gl_LightSource[0].diffuse * vec4(diffuse, 1.0);
c1 *= ambient_light;
vec4 finalColor = c1;
if(gl_Fog.density == 1.0)
fogFactor=1.0;
gl_FragColor = mix(gl_Fog.color ,finalColor, fogFactor);
}

26
Shaders/urban.vert Normal file
View file

@ -0,0 +1,26 @@
varying vec4 rawpos;
varying vec4 ecPosition;
varying vec3 VNormal;
varying vec3 Normal;
varying vec3 VTangent;
varying vec3 VBinormal;
varying vec4 constantColor;
void main(void)
{
rawpos = gl_Vertex;
ecPosition = gl_ModelViewMatrix * gl_Vertex;
VNormal = normalize(gl_NormalMatrix * gl_Normal);
Normal = normalize(gl_Normal);
vec3 t = normalize(cross(gl_Normal, vec3(1.0,0.0,0.0)));
VTangent = gl_NormalMatrix * t;
vec3 b = normalize(cross(gl_Normal,t));
VBinormal = gl_NormalMatrix * b;
gl_FrontColor = gl_Color;
constantColor = gl_FrontMaterial.emission
+ gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient);
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
}

View file

@ -261,6 +261,15 @@
<command>dialog-apply</command> <command>dialog-apply</command>
</binding> </binding>
</checkbox> </checkbox>
<checkbox>
<halign>left</halign>
<label>Urban effects</label>
<property>/sim/rendering/urban-shader</property>
<binding>
<command>dialog-apply</command>
</binding>
</checkbox>
</group> </group>
</group> </group>
</group> </group>

View file

@ -871,9 +871,12 @@ Shared parameters for various materials.
</condition> </condition>
<name>BuiltUpCover</name> <name>BuiltUpCover</name>
<name>Urban</name> <name>Urban</name>
<effect>Effects/urban</effect>
<texture>Terrain/city1.png</texture> <texture>Terrain/city1.png</texture>
<!--
<texture>Terrain/city2.png</texture> <texture>Terrain/city2.png</texture>
<texture>Terrain/city3.png</texture> <texture>Terrain/city3.png</texture>
-->
<xsize>1024</xsize> <xsize>1024</xsize>
<ysize>1024</ysize> <ysize>1024</ysize>
<light-coverage>100000.0</light-coverage> <light-coverage>100000.0</light-coverage>

View file

@ -136,6 +136,7 @@ Started September 2000 by David Megginson, david@megginson.com
<crop-shader userarchive="y">0</crop-shader> <crop-shader userarchive="y">0</crop-shader>
<landmass-shader userarchive="y">0</landmass-shader> <landmass-shader userarchive="y">0</landmass-shader>
<water-shader userarchive="y">0</water-shader> <water-shader userarchive="y">0</water-shader>
<urban-shader userarchive="y">0</urban-shader>
</rendering> </rendering>
<model-hz type="int">120</model-hz> <model-hz type="int">120</model-hz>
<navdb> <navdb>