Merge branch 'topic/shaderopt'
This commit is contained in:
commit
cc5502c509
13 changed files with 246 additions and 73 deletions
|
@ -43,6 +43,59 @@
|
||||||
<extension-supported>GL_EXT_geometry_shader4</extension-supported>
|
<extension-supported>GL_EXT_geometry_shader4</extension-supported>
|
||||||
</and>
|
</and>
|
||||||
</predicate>
|
</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>
|
||||||
|
<alpha-test><use>transparent</use></alpha-test>
|
||||||
|
<shade-model>smooth</shade-model>
|
||||||
|
<cull-face>back</cull-face>
|
||||||
|
<render-bin>
|
||||||
|
<bin-number>-1</bin-number>
|
||||||
|
<bin-name>RenderBin</bin-name>
|
||||||
|
</render-bin>
|
||||||
|
<texture-unit>
|
||||||
|
<unit>1</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>
|
||||||
|
<program>
|
||||||
|
<vertex-shader>Shaders/landmass-g.vert</vertex-shader>
|
||||||
|
<geometry-shader>Shaders/landmass.geom</geometry-shader>
|
||||||
|
<fragment-shader>Shaders/terrain-nocolor.frag</fragment-shader>
|
||||||
|
<geometry-vertices-out type="int">18</geometry-vertices-out>
|
||||||
|
<geometry-input-type>triangles</geometry-input-type>
|
||||||
|
<geometry-output-type>triangle-strip</geometry-output-type>
|
||||||
|
<attribute>
|
||||||
|
<name>tangent</name>
|
||||||
|
<index>6</index>
|
||||||
|
</attribute>
|
||||||
|
<attribute>
|
||||||
|
<name>binormal</name>
|
||||||
|
<index>7</index>
|
||||||
|
</attribute>
|
||||||
|
</program>
|
||||||
|
<uniform>
|
||||||
|
<name>texture</name>
|
||||||
|
<type>sampler-2d</type>
|
||||||
|
<value type="int">1</value>
|
||||||
|
</uniform>
|
||||||
|
<uniform>
|
||||||
|
<name>canopy_height</name>
|
||||||
|
<type>float</type>
|
||||||
|
<value><use>canopy-height</use></value>
|
||||||
|
</uniform>
|
||||||
|
<color-mask type="vec4d">0 0 0 0</color-mask>
|
||||||
|
</pass>
|
||||||
<pass>
|
<pass>
|
||||||
<lighting>true</lighting>
|
<lighting>true</lighting>
|
||||||
<material>
|
<material>
|
||||||
|
@ -134,6 +187,10 @@
|
||||||
<type>float</type>
|
<type>float</type>
|
||||||
<value><use>quality-level</use></value>
|
<value><use>quality-level</use></value>
|
||||||
</uniform>
|
</uniform>
|
||||||
|
<depth>
|
||||||
|
<function>lequal</function>
|
||||||
|
<write-mask type="bool">false</write-mask>
|
||||||
|
</depth>
|
||||||
</pass>
|
</pass>
|
||||||
</technique>
|
</technique>
|
||||||
<technique n="9">
|
<technique n="9">
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PropertyList>
|
<PropertyList>
|
||||||
<name>Effects/material-off</name>
|
<name>Effects/material-diffuse</name>
|
||||||
<inherits-from>Effects/model-default</inherits-from>
|
<inherits-from>Effects/model-default</inherits-from>
|
||||||
<technique n="10">
|
<technique n="10">
|
||||||
<pass>
|
<pass>
|
||||||
<program>
|
<program>
|
||||||
<vertex-shader n="0">Shaders/mode-diffuse.vert</vertex-shader>
|
<vertex-shader>Shaders/default.vert</vertex-shader>
|
||||||
<vertex-shader n="1">Shaders/mat-anim.vert</vertex-shader>
|
<fragment-shader>Shaders/default.frag</fragment-shader>
|
||||||
<fragment-shader n="0">Shaders/mat-anim.frag</fragment-shader>
|
|
||||||
</program>
|
</program>
|
||||||
|
<uniform>
|
||||||
|
<name>colorMode</name>
|
||||||
|
<type>int</type>
|
||||||
|
<value>1</value> <!-- DIFFUSE -->
|
||||||
|
</uniform>
|
||||||
</pass>
|
</pass>
|
||||||
</technique>
|
</technique>
|
||||||
</PropertyList>
|
</PropertyList>
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
<inherits-from>Effects/model-default</inherits-from>
|
<inherits-from>Effects/model-default</inherits-from>
|
||||||
<technique n="10">
|
<technique n="10">
|
||||||
<pass>
|
<pass>
|
||||||
<program>
|
<uniform>
|
||||||
<vertex-shader n="0">Shaders/mode-off.vert</vertex-shader>
|
<name>colorMode</name>
|
||||||
<vertex-shader n="1">Shaders/mat-anim.vert</vertex-shader>
|
<type>int</type>
|
||||||
<fragment-shader n="0">Shaders/mat-anim.frag</fragment-shader>
|
<value>0</value> <!-- OFF -->
|
||||||
</program>
|
</uniform>
|
||||||
</pass>
|
</pass>
|
||||||
</technique>
|
</technique>
|
||||||
</PropertyList>
|
</PropertyList>
|
||||||
|
|
|
@ -65,8 +65,8 @@
|
||||||
<use>vertex-program-two-side</use>
|
<use>vertex-program-two-side</use>
|
||||||
</vertex-program-two-side>
|
</vertex-program-two-side>
|
||||||
<program>
|
<program>
|
||||||
<vertex-shader>Shaders/model-default.vert</vertex-shader>
|
<vertex-shader>Shaders/default.vert</vertex-shader>
|
||||||
<fragment-shader>Shaders/model-default.frag</fragment-shader>
|
<fragment-shader>Shaders/default.frag</fragment-shader>
|
||||||
</program>
|
</program>
|
||||||
<uniform>
|
<uniform>
|
||||||
<name>texture</name>
|
<name>texture</name>
|
||||||
|
@ -74,9 +74,9 @@
|
||||||
<value type="int">0</value>
|
<value type="int">0</value>
|
||||||
</uniform>
|
</uniform>
|
||||||
<uniform>
|
<uniform>
|
||||||
<name>twoSideHack</name>
|
<name>colorMode</name>
|
||||||
<type>bool</type>
|
<type>int</type>
|
||||||
<value><use>vertex-program-two-side</use></value>
|
<value>1</value> <!-- DIFFUSE -->
|
||||||
</uniform>
|
</uniform>
|
||||||
</pass>
|
</pass>
|
||||||
</technique>
|
</technique>
|
||||||
|
|
|
@ -57,6 +57,44 @@
|
||||||
</or>
|
</or>
|
||||||
</and>
|
</and>
|
||||||
</predicate>
|
</predicate>
|
||||||
|
<pass>
|
||||||
|
<lighting>true</lighting>
|
||||||
|
<material>
|
||||||
|
<ambient><use>material/ambient</use></ambient>
|
||||||
|
<diffuse><use>material/diffuse</use></diffuse>
|
||||||
|
<specular><use>material/specular</use></specular>
|
||||||
|
<emissive><use>material/emissive</use></emissive>
|
||||||
|
<shininess><use>material/shininess</use></shininess>
|
||||||
|
<color-mode>ambient-and-diffuse</color-mode>
|
||||||
|
</material>
|
||||||
|
<alpha-test><use>transparent</use></alpha-test>
|
||||||
|
<shade-model>smooth</shade-model>
|
||||||
|
<cull-face>back</cull-face>
|
||||||
|
<render-bin>
|
||||||
|
<bin-number>-1</bin-number>
|
||||||
|
<bin-name>RenderBin</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>
|
||||||
|
<program>
|
||||||
|
<vertex-shader>Shaders/default.vert</vertex-shader>
|
||||||
|
<fragment-shader>Shaders/terrain-nocolor.frag</fragment-shader>
|
||||||
|
</program>
|
||||||
|
<uniform>
|
||||||
|
<name>texture</name>
|
||||||
|
<type>sampler-2d</type>
|
||||||
|
<value type="int">0</value>
|
||||||
|
</uniform>
|
||||||
|
<color-mask type="vec4d">0 0 0 0</color-mask>
|
||||||
|
</pass>
|
||||||
<pass>
|
<pass>
|
||||||
<lighting>true</lighting>
|
<lighting>true</lighting>
|
||||||
<material>
|
<material>
|
||||||
|
@ -87,12 +125,22 @@
|
||||||
</texture-unit>
|
</texture-unit>
|
||||||
<program>
|
<program>
|
||||||
<vertex-shader>Shaders/default.vert</vertex-shader>
|
<vertex-shader>Shaders/default.vert</vertex-shader>
|
||||||
<fragment-shader>Shaders/terrain-default.frag</fragment-shader>
|
<fragment-shader>Shaders/default.frag</fragment-shader>
|
||||||
</program>
|
</program>
|
||||||
<uniform>
|
<uniform>
|
||||||
<name>texture</name>
|
<name>texture</name>
|
||||||
<type>sampler-2d</type>
|
<type>sampler-2d</type>
|
||||||
<value type="int">0</value></uniform>
|
<value type="int">0</value>
|
||||||
|
</uniform>
|
||||||
|
<uniform>
|
||||||
|
<name>colorMode</name>
|
||||||
|
<type>int</type>
|
||||||
|
<value>2</value> <!-- AMBIENT_AND_DIFFUSE -->
|
||||||
|
</uniform>
|
||||||
|
<depth>
|
||||||
|
<function>lequal</function>
|
||||||
|
<write-mask type="bool">false</write-mask>
|
||||||
|
</depth>
|
||||||
</pass>
|
</pass>
|
||||||
</technique>
|
</technique>
|
||||||
<technique n="11">
|
<technique n="11">
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// -*-C++-*-
|
// -*-C++-*-
|
||||||
|
|
||||||
varying vec4 diffuse, constantColor;
|
// Ambient term comes in gl_Color.rgb.
|
||||||
varying vec3 normal, lightDir, halfVector;
|
varying vec4 diffuse_term;
|
||||||
varying float fogCoord, alpha;
|
varying vec3 normal;
|
||||||
|
varying float fogCoord;
|
||||||
|
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
|
|
||||||
|
@ -15,24 +16,28 @@ void main()
|
||||||
{
|
{
|
||||||
vec3 n, halfV;
|
vec3 n, halfV;
|
||||||
float NdotL, NdotHV, fogFactor;
|
float NdotL, NdotHV, fogFactor;
|
||||||
vec4 color = constantColor;
|
vec4 color = gl_Color;
|
||||||
|
vec3 lightDir = gl_LightSource[0].position.xyz;
|
||||||
|
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
|
||||||
vec4 texel;
|
vec4 texel;
|
||||||
vec4 fragColor;
|
vec4 fragColor;
|
||||||
vec4 specular = vec4(0.0);
|
vec4 specular = vec4(0.0);
|
||||||
n = normalize(normal);
|
n = normalize(normal);
|
||||||
if (!gl_FrontFacing)
|
// If gl_Color.a == 0, this is a back-facing polygon and the
|
||||||
n = -n;
|
// normal should be reversed.
|
||||||
|
|
||||||
|
n = (2.0 * gl_Color.a - 1.0) * n;
|
||||||
NdotL = max(dot(n, lightDir), 0.0);
|
NdotL = max(dot(n, lightDir), 0.0);
|
||||||
if (NdotL > 0.0) {
|
if (NdotL > 0.0) {
|
||||||
color += diffuse * NdotL;
|
color += diffuse_term * NdotL;
|
||||||
halfV = normalize(halfVector);
|
halfV = halfVector;
|
||||||
NdotHV = max(dot(n, halfV), 0.0);
|
NdotHV = max(dot(n, halfV), 0.0);
|
||||||
if (gl_FrontMaterial.shininess > 0.0)
|
if (gl_FrontMaterial.shininess > 0.0)
|
||||||
specular.rgb = (gl_FrontMaterial.specular.rgb
|
specular.rgb = (gl_FrontMaterial.specular.rgb
|
||||||
* gl_LightSource[0].specular.rgb
|
* gl_LightSource[0].specular.rgb
|
||||||
* pow(NdotHV, gl_FrontMaterial.shininess));
|
* pow(NdotHV, gl_FrontMaterial.shininess));
|
||||||
}
|
}
|
||||||
color.a = alpha;
|
color.a = diffuse_term.a;
|
||||||
// This shouldn't be necessary, but our lighting becomes very
|
// This shouldn't be necessary, but our lighting becomes very
|
||||||
// saturated. Clamping the color before modulating by the texture
|
// saturated. Clamping the color before modulating by the texture
|
||||||
// is closer to what the OpenGL fixed function pipeline does.
|
// is closer to what the OpenGL fixed function pipeline does.
|
||||||
|
|
|
@ -5,24 +5,51 @@
|
||||||
// The only light used is gl_LightSource[0], which is assumed to be
|
// The only light used is gl_LightSource[0], which is assumed to be
|
||||||
// directional.
|
// directional.
|
||||||
//
|
//
|
||||||
// Diffuse and ambient colors come from the gl_Color. This is
|
// Diffuse colors come from the gl_Color, ambient from the material. This is
|
||||||
// equivalent to osg::Material::AMBIENT_AND_DIFFUSE.
|
// equivalent to osg::Material::DIFFUSE.
|
||||||
|
|
||||||
varying vec4 diffuse, constantColor;
|
#define MODE_OFF 0
|
||||||
varying vec3 normal, lightDir, halfVector;
|
#define MODE_DIFFUSE 1
|
||||||
varying float fogCoord, alpha;
|
#define MODE_AMBIENT_AND_DIFFUSE 2
|
||||||
|
|
||||||
|
// The constant term of the lighting equation that doesn't depend on
|
||||||
|
// the surface normal is passed in gl_{Front,Back}Color. The alpha
|
||||||
|
// component is set to 1 for front, 0 for back in order to work around
|
||||||
|
// bugs with gl_FrontFacing in the fragment shader.
|
||||||
|
varying vec4 diffuse_term;
|
||||||
|
varying vec3 normal;
|
||||||
|
varying float fogCoord;
|
||||||
|
uniform int colorMode;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
|
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
|
||||||
gl_Position = ftransform();
|
gl_Position = ftransform();
|
||||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||||
normal = gl_NormalMatrix * gl_Normal;
|
normal = gl_NormalMatrix * gl_Normal;
|
||||||
lightDir = normalize(vec3(gl_LightSource[0].position));
|
vec4 ambient_color, diffuse_color;
|
||||||
halfVector = normalize(gl_LightSource[0].halfVector.xyz);
|
if (colorMode == MODE_DIFFUSE) {
|
||||||
diffuse = gl_Color * gl_LightSource[0].diffuse;
|
diffuse_color = gl_Color;
|
||||||
alpha = gl_Color.a;
|
ambient_color = gl_FrontMaterial.ambient;
|
||||||
constantColor = gl_FrontMaterial.emission
|
} else if (colorMode == MODE_AMBIENT_AND_DIFFUSE) {
|
||||||
+ gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient);
|
diffuse_color = gl_Color;
|
||||||
fogCoord = abs(ecPosition.z);
|
ambient_color = gl_Color;
|
||||||
|
} else {
|
||||||
|
diffuse_color = gl_FrontMaterial.diffuse;
|
||||||
|
ambient_color = gl_FrontMaterial.ambient;
|
||||||
|
}
|
||||||
|
diffuse_term = diffuse_color * gl_LightSource[0].diffuse;
|
||||||
|
vec4 constant_term = gl_FrontMaterial.emission + ambient_color *
|
||||||
|
(gl_LightModel.ambient + gl_LightSource[0].ambient);
|
||||||
|
// Super hack: if diffuse material alpha is less than 1, assume a
|
||||||
|
// transparency animation is at work
|
||||||
|
if (gl_FrontMaterial.diffuse.a < 1.0)
|
||||||
|
diffuse_term.a = gl_FrontMaterial.diffuse.a;
|
||||||
|
else
|
||||||
|
diffuse_term.a = gl_Color.a;
|
||||||
|
// Another hack for supporting two-sided lighting without using
|
||||||
|
// gl_FrontFacing in the fragment shader.
|
||||||
|
gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0;
|
||||||
|
gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0;
|
||||||
|
fogCoord = abs(ecPosition.z / ecPosition.w);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
// Shader for use with material animations
|
// Shader for use with material animations
|
||||||
varying vec4 diffuse, constantColor, matSpecular;
|
varying vec4 diffuse, constantColor, matSpecular;
|
||||||
varying vec3 normal, lightDir, halfVector;
|
varying vec3 normal;
|
||||||
varying float fogCoord, alpha;
|
varying float fogCoord, alpha;
|
||||||
|
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
|
@ -12,6 +12,8 @@ void main()
|
||||||
vec3 n, halfV;
|
vec3 n, halfV;
|
||||||
float NdotL, NdotHV, fogFactor;
|
float NdotL, NdotHV, fogFactor;
|
||||||
vec4 color = constantColor;
|
vec4 color = constantColor;
|
||||||
|
vec3 lightDir = gl_LightSource[0].position.xyz;
|
||||||
|
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
|
||||||
vec4 texel;
|
vec4 texel;
|
||||||
vec4 fragColor;
|
vec4 fragColor;
|
||||||
vec4 specular = vec4(0.0);
|
vec4 specular = vec4(0.0);
|
||||||
|
|
|
@ -13,7 +13,7 @@ vec4 specularColor();
|
||||||
vec4 emissionColor();
|
vec4 emissionColor();
|
||||||
|
|
||||||
varying vec4 diffuse, constantColor, matSpecular;
|
varying vec4 diffuse, constantColor, matSpecular;
|
||||||
varying vec3 normal, lightDir, halfVector;
|
varying vec3 normal;
|
||||||
varying float alpha, fogCoord;
|
varying float alpha, fogCoord;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
@ -23,8 +23,6 @@ void main()
|
||||||
gl_Position = ftransform();
|
gl_Position = ftransform();
|
||||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||||
normal = gl_NormalMatrix * gl_Normal;
|
normal = gl_NormalMatrix * gl_Normal;
|
||||||
lightDir = normalize(vec3(gl_LightSource[0].position));
|
|
||||||
halfVector = normalize(gl_LightSource[0].halfVector.xyz);
|
|
||||||
diffuse = diffuseColor() * gl_LightSource[0].diffuse;
|
diffuse = diffuseColor() * gl_LightSource[0].diffuse;
|
||||||
// Super hack: if diffuse material alpha is less than 1, assume a
|
// Super hack: if diffuse material alpha is less than 1, assume a
|
||||||
// transparency animation is at work
|
// transparency animation is at work
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
// -*-C++-*-
|
// -*-C++-*-
|
||||||
|
|
||||||
varying vec4 diffuse, constantColor;
|
// Ambient term comes in gl_Color.rgb.
|
||||||
varying vec3 normal, lightDir, halfVector;
|
varying vec4 diffuse_term;
|
||||||
varying float fogCoord, alpha;
|
varying vec3 normal;
|
||||||
|
varying float fogCoord;
|
||||||
uniform bool twoSideHack;
|
|
||||||
|
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
|
|
||||||
|
@ -17,16 +16,19 @@ void main()
|
||||||
{
|
{
|
||||||
vec3 n, halfV;
|
vec3 n, halfV;
|
||||||
float NdotL, NdotHV, fogFactor;
|
float NdotL, NdotHV, fogFactor;
|
||||||
vec4 color = constantColor;
|
vec4 color = gl_FrontLightModelProduct.sceneColor + gl_Color;
|
||||||
|
vec3 lightDir = gl_LightSource[0].position.xyz;
|
||||||
|
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
|
||||||
vec4 texel;
|
vec4 texel;
|
||||||
vec4 fragColor;
|
vec4 fragColor;
|
||||||
vec4 specular = vec4(0.0);
|
vec4 specular = vec4(0.0);
|
||||||
n = normalize(normal);
|
n = normalize(normal);
|
||||||
if (twoSideHack && gl_Color.a == 0.0)
|
// If gl_Color.a == 0, this is a back-facing polygon and the
|
||||||
n = -n;
|
// normal should be reversed.
|
||||||
|
n = (2.0 * gl_Color.a - 1.0) * n;
|
||||||
NdotL = max(dot(n, lightDir), 0.0);
|
NdotL = max(dot(n, lightDir), 0.0);
|
||||||
if (NdotL > 0.0) {
|
if (NdotL > 0.0) {
|
||||||
color += diffuse * NdotL;
|
color += diffuse_term * NdotL;
|
||||||
halfV = normalize(halfVector);
|
halfV = normalize(halfVector);
|
||||||
NdotHV = max(dot(n, halfV), 0.0);
|
NdotHV = max(dot(n, halfV), 0.0);
|
||||||
if (gl_FrontMaterial.shininess > 0.0)
|
if (gl_FrontMaterial.shininess > 0.0)
|
||||||
|
@ -34,7 +36,7 @@ void main()
|
||||||
* gl_LightSource[0].specular.rgb
|
* gl_LightSource[0].specular.rgb
|
||||||
* pow(NdotHV, gl_FrontMaterial.shininess));
|
* pow(NdotHV, gl_FrontMaterial.shininess));
|
||||||
}
|
}
|
||||||
color.a = alpha;
|
color.a = diffuse_term.a;
|
||||||
// This shouldn't be necessary, but our lighting becomes very
|
// This shouldn't be necessary, but our lighting becomes very
|
||||||
// saturated. Clamping the color before modulating by the texture
|
// saturated. Clamping the color before modulating by the texture
|
||||||
// is closer to what the OpenGL fixed function pipeline does.
|
// is closer to what the OpenGL fixed function pipeline does.
|
||||||
|
|
|
@ -8,35 +8,48 @@
|
||||||
// Diffuse colors come from the gl_Color, ambient from the material. This is
|
// Diffuse colors come from the gl_Color, ambient from the material. This is
|
||||||
// equivalent to osg::Material::DIFFUSE.
|
// equivalent to osg::Material::DIFFUSE.
|
||||||
|
|
||||||
varying vec4 diffuse, constantColor;
|
#define MODE_OFF 0
|
||||||
varying vec3 normal, lightDir, halfVector;
|
#define MODE_DIFFUSE 1
|
||||||
varying float alpha, fogCoord;
|
#define MODE_AMBIENT_AND_DIFFUSE 2
|
||||||
|
|
||||||
uniform bool twoSideHack;
|
// The ambient term of the lighting equation that doesn't depend on
|
||||||
|
// the surface normal is passed in gl_{Front,Back}Color. The alpha
|
||||||
|
// component is set to 1 for front, 0 for back in order to work around
|
||||||
|
// bugs with gl_FrontFacing in the fragment shader.
|
||||||
|
varying vec4 diffuse_term;
|
||||||
|
varying vec3 normal;
|
||||||
|
varying float fogCoord;
|
||||||
|
|
||||||
|
uniform int colorMode;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
|
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
|
||||||
vec3 ecPosition3 = vec3(gl_ModelViewMatrix * gl_Vertex) / ecPosition.w;
|
|
||||||
gl_Position = ftransform();
|
gl_Position = ftransform();
|
||||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||||
normal = gl_NormalMatrix * gl_Normal;
|
normal = gl_NormalMatrix * gl_Normal;
|
||||||
lightDir = normalize(vec3(gl_LightSource[0].position));
|
vec4 ambient_color, diffuse_color;
|
||||||
halfVector = normalize(gl_LightSource[0].halfVector.xyz);
|
if (colorMode == MODE_DIFFUSE) {
|
||||||
diffuse = gl_Color * gl_LightSource[0].diffuse;
|
diffuse_color = gl_Color;
|
||||||
|
ambient_color = gl_FrontMaterial.ambient;
|
||||||
|
} else if (colorMode == MODE_AMBIENT_AND_DIFFUSE) {
|
||||||
|
diffuse_color = gl_Color;
|
||||||
|
ambient_color = gl_Color;
|
||||||
|
} else {
|
||||||
|
diffuse_color = gl_FrontMaterial.diffuse;
|
||||||
|
ambient_color = gl_FrontMaterial.ambient;
|
||||||
|
}
|
||||||
|
diffuse_term = diffuse_color * gl_LightSource[0].diffuse;
|
||||||
|
vec4 ambient_term = ambient_color * gl_LightSource[0].ambient;
|
||||||
// Super hack: if diffuse material alpha is less than 1, assume a
|
// Super hack: if diffuse material alpha is less than 1, assume a
|
||||||
// transparency animation is at work
|
// transparency animation is at work
|
||||||
if (gl_FrontMaterial.diffuse.a < 1.0)
|
if (gl_FrontMaterial.diffuse.a < 1.0)
|
||||||
alpha = gl_FrontMaterial.diffuse.a;
|
diffuse_term.a = gl_FrontMaterial.diffuse.a;
|
||||||
else
|
else
|
||||||
alpha = gl_Color.a;
|
diffuse_term.a = gl_Color.a;
|
||||||
// Another hack for supporting two-sided lighting without using
|
// Another hack for supporting two-sided lighting without using
|
||||||
// gl_FrontFacing in the fragment shader.
|
// gl_FrontFacing in the fragment shader.
|
||||||
if (twoSideHack) {
|
gl_FrontColor.rgb = ambient_term.rgb; gl_FrontColor.a = 1.0;
|
||||||
gl_FrontColor = vec4(0.0, 0.0, 0.0, 1.0);
|
gl_BackColor.rgb = ambient_term.rgb; gl_FrontColor.a = 0.0;
|
||||||
gl_BackColor = vec4(0.0, 0.0, 0.0, 0.0);
|
fogCoord = abs(ecPosition.z / ecPosition.w);
|
||||||
}
|
|
||||||
constantColor = gl_FrontLightModelProduct.sceneColor
|
|
||||||
+ gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
|
|
||||||
fogCoord = abs(ecPosition3.z);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ varying vec3 normal, lightDir, halfVector;
|
||||||
varying float fogCoord, alpha;
|
varying float fogCoord, alpha;
|
||||||
|
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
uniform sampler3D noise;
|
|
||||||
|
|
||||||
float luminance(vec3 color)
|
float luminance(vec3 color)
|
||||||
{
|
{
|
||||||
|
@ -16,7 +15,10 @@ void main()
|
||||||
{
|
{
|
||||||
vec3 n, halfV;
|
vec3 n, halfV;
|
||||||
float NdotL, NdotHV, fogFactor;
|
float NdotL, NdotHV, fogFactor;
|
||||||
vec4 color = constantColor;
|
vec4 color = gl_FrontMaterial.emission
|
||||||
|
+ gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient);
|
||||||
|
vec3 lightDir = gl_LightSource[0].position.xyz;
|
||||||
|
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
|
||||||
vec4 texel;
|
vec4 texel;
|
||||||
vec4 fragColor;
|
vec4 fragColor;
|
||||||
vec4 specular = vec4(0.0);
|
vec4 specular = vec4(0.0);
|
||||||
|
|
15
Shaders/terrain-nocolor.frag
Normal file
15
Shaders/terrain-nocolor.frag
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// -*-C++-*-
|
||||||
|
uniform sampler2D texture;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
|
||||||
|
vec4 texel;
|
||||||
|
vec4 fragColor;
|
||||||
|
|
||||||
|
texel = texture2D(texture, gl_TexCoord[0].st);
|
||||||
|
fragColor = color * texel;
|
||||||
|
|
||||||
|
gl_FragColor = fragColor;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue