1
0
Fork 0

Merge branch 'topic/shaderopt'

This commit is contained in:
Tim Moore 2010-08-14 00:13:53 +02:00
commit cc5502c509
13 changed files with 246 additions and 73 deletions

View file

@ -43,6 +43,59 @@
<extension-supported>GL_EXT_geometry_shader4</extension-supported>
</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>
<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>
<lighting>true</lighting>
<material>
@ -134,6 +187,10 @@
<type>float</type>
<value><use>quality-level</use></value>
</uniform>
<depth>
<function>lequal</function>
<write-mask type="bool">false</write-mask>
</depth>
</pass>
</technique>
<technique n="9">

View file

@ -1,14 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/material-off</name>
<name>Effects/material-diffuse</name>
<inherits-from>Effects/model-default</inherits-from>
<technique n="10">
<pass>
<program>
<vertex-shader n="0">Shaders/mode-diffuse.vert</vertex-shader>
<vertex-shader n="1">Shaders/mat-anim.vert</vertex-shader>
<fragment-shader n="0">Shaders/mat-anim.frag</fragment-shader>
<vertex-shader>Shaders/default.vert</vertex-shader>
<fragment-shader>Shaders/default.frag</fragment-shader>
</program>
<uniform>
<name>colorMode</name>
<type>int</type>
<value>1</value> <!-- DIFFUSE -->
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -4,11 +4,11 @@
<inherits-from>Effects/model-default</inherits-from>
<technique n="10">
<pass>
<program>
<vertex-shader n="0">Shaders/mode-off.vert</vertex-shader>
<vertex-shader n="1">Shaders/mat-anim.vert</vertex-shader>
<fragment-shader n="0">Shaders/mat-anim.frag</fragment-shader>
</program>
<uniform>
<name>colorMode</name>
<type>int</type>
<value>0</value> <!-- OFF -->
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -65,8 +65,8 @@
<use>vertex-program-two-side</use>
</vertex-program-two-side>
<program>
<vertex-shader>Shaders/model-default.vert</vertex-shader>
<fragment-shader>Shaders/model-default.frag</fragment-shader>
<vertex-shader>Shaders/default.vert</vertex-shader>
<fragment-shader>Shaders/default.frag</fragment-shader>
</program>
<uniform>
<name>texture</name>
@ -74,9 +74,9 @@
<value type="int">0</value>
</uniform>
<uniform>
<name>twoSideHack</name>
<type>bool</type>
<value><use>vertex-program-two-side</use></value>
<name>colorMode</name>
<type>int</type>
<value>1</value> <!-- DIFFUSE -->
</uniform>
</pass>
</technique>

View file

@ -57,6 +57,44 @@
</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>
<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>
<lighting>true</lighting>
<material>
@ -87,12 +125,22 @@
</texture-unit>
<program>
<vertex-shader>Shaders/default.vert</vertex-shader>
<fragment-shader>Shaders/terrain-default.frag</fragment-shader>
<fragment-shader>Shaders/default.frag</fragment-shader>
</program>
<uniform>
<name>texture</name>
<type>sampler-2d</type>
<value type="int">0</value></uniform>
<name>texture</name>
<type>sampler-2d</type>
<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>
</technique>
<technique n="11">

View file

@ -1,8 +1,9 @@
// -*-C++-*-
varying vec4 diffuse, constantColor;
varying vec3 normal, lightDir, halfVector;
varying float fogCoord, alpha;
// Ambient term comes in gl_Color.rgb.
varying vec4 diffuse_term;
varying vec3 normal;
varying float fogCoord;
uniform sampler2D texture;
@ -15,24 +16,28 @@ void main()
{
vec3 n, halfV;
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 fragColor;
vec4 specular = vec4(0.0);
n = normalize(normal);
if (!gl_FrontFacing)
n = -n;
// If gl_Color.a == 0, this is a back-facing polygon and the
// normal should be reversed.
n = (2.0 * gl_Color.a - 1.0) * n;
NdotL = max(dot(n, lightDir), 0.0);
if (NdotL > 0.0) {
color += diffuse * NdotL;
halfV = normalize(halfVector);
color += diffuse_term * NdotL;
halfV = halfVector;
NdotHV = max(dot(n, halfV), 0.0);
if (gl_FrontMaterial.shininess > 0.0)
specular.rgb = (gl_FrontMaterial.specular.rgb
* gl_LightSource[0].specular.rgb
* pow(NdotHV, gl_FrontMaterial.shininess));
}
color.a = alpha;
color.a = diffuse_term.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.

View file

@ -5,24 +5,51 @@
// The only light used is gl_LightSource[0], which is assumed to be
// directional.
//
// Diffuse and ambient colors come from the gl_Color. This is
// equivalent to osg::Material::AMBIENT_AND_DIFFUSE.
// Diffuse colors come from the gl_Color, ambient from the material. This is
// equivalent to osg::Material::DIFFUSE.
varying vec4 diffuse, constantColor;
varying vec3 normal, lightDir, halfVector;
varying float fogCoord, alpha;
#define MODE_OFF 0
#define MODE_DIFFUSE 1
#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()
{
vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
normal = gl_NormalMatrix * gl_Normal;
lightDir = normalize(vec3(gl_LightSource[0].position));
halfVector = normalize(gl_LightSource[0].halfVector.xyz);
diffuse = gl_Color * gl_LightSource[0].diffuse;
alpha = gl_Color.a;
constantColor = gl_FrontMaterial.emission
+ gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient);
fogCoord = abs(ecPosition.z);
vec4 ambient_color, diffuse_color;
if (colorMode == MODE_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 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);
}

View file

@ -2,7 +2,7 @@
// Shader for use with material animations
varying vec4 diffuse, constantColor, matSpecular;
varying vec3 normal, lightDir, halfVector;
varying vec3 normal;
varying float fogCoord, alpha;
uniform sampler2D texture;
@ -12,6 +12,8 @@ void main()
vec3 n, halfV;
float NdotL, NdotHV, fogFactor;
vec4 color = constantColor;
vec3 lightDir = gl_LightSource[0].position.xyz;
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
vec4 texel;
vec4 fragColor;
vec4 specular = vec4(0.0);

View file

@ -13,7 +13,7 @@ vec4 specularColor();
vec4 emissionColor();
varying vec4 diffuse, constantColor, matSpecular;
varying vec3 normal, lightDir, halfVector;
varying vec3 normal;
varying float alpha, fogCoord;
void main()
@ -23,8 +23,6 @@ void main()
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
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;
// Super hack: if diffuse material alpha is less than 1, assume a
// transparency animation is at work

View file

@ -1,10 +1,9 @@
// -*-C++-*-
varying vec4 diffuse, constantColor;
varying vec3 normal, lightDir, halfVector;
varying float fogCoord, alpha;
uniform bool twoSideHack;
// Ambient term comes in gl_Color.rgb.
varying vec4 diffuse_term;
varying vec3 normal;
varying float fogCoord;
uniform sampler2D texture;
@ -17,16 +16,19 @@ void main()
{
vec3 n, halfV;
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 fragColor;
vec4 specular = vec4(0.0);
n = normalize(normal);
if (twoSideHack && gl_Color.a == 0.0)
n = -n;
// If gl_Color.a == 0, this is a back-facing polygon and the
// normal should be reversed.
n = (2.0 * gl_Color.a - 1.0) * n;
NdotL = max(dot(n, lightDir), 0.0);
if (NdotL > 0.0) {
color += diffuse * NdotL;
color += diffuse_term * NdotL;
halfV = normalize(halfVector);
NdotHV = max(dot(n, halfV), 0.0);
if (gl_FrontMaterial.shininess > 0.0)
@ -34,7 +36,7 @@ void main()
* gl_LightSource[0].specular.rgb
* pow(NdotHV, gl_FrontMaterial.shininess));
}
color.a = alpha;
color.a = diffuse_term.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.

View file

@ -8,35 +8,48 @@
// Diffuse colors come from the gl_Color, ambient from the material. This is
// equivalent to osg::Material::DIFFUSE.
varying vec4 diffuse, constantColor;
varying vec3 normal, lightDir, halfVector;
varying float alpha, fogCoord;
#define MODE_OFF 0
#define MODE_DIFFUSE 1
#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()
{
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
vec3 ecPosition3 = vec3(gl_ModelViewMatrix * gl_Vertex) / ecPosition.w;
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
normal = gl_NormalMatrix * gl_Normal;
lightDir = normalize(vec3(gl_LightSource[0].position));
halfVector = normalize(gl_LightSource[0].halfVector.xyz);
diffuse = gl_Color * gl_LightSource[0].diffuse;
vec4 ambient_color, diffuse_color;
if (colorMode == MODE_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
// transparency animation is at work
if (gl_FrontMaterial.diffuse.a < 1.0)
alpha = gl_FrontMaterial.diffuse.a;
diffuse_term.a = gl_FrontMaterial.diffuse.a;
else
alpha = gl_Color.a;
diffuse_term.a = gl_Color.a;
// Another hack for supporting two-sided lighting without using
// gl_FrontFacing in the fragment shader.
if (twoSideHack) {
gl_FrontColor = vec4(0.0, 0.0, 0.0, 1.0);
gl_BackColor = vec4(0.0, 0.0, 0.0, 0.0);
}
constantColor = gl_FrontLightModelProduct.sceneColor
+ gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
fogCoord = abs(ecPosition3.z);
gl_FrontColor.rgb = ambient_term.rgb; gl_FrontColor.a = 1.0;
gl_BackColor.rgb = ambient_term.rgb; gl_FrontColor.a = 0.0;
fogCoord = abs(ecPosition.z / ecPosition.w);
}

View file

@ -5,7 +5,6 @@ varying vec3 normal, lightDir, halfVector;
varying float fogCoord, alpha;
uniform sampler2D texture;
uniform sampler3D noise;
float luminance(vec3 color)
{
@ -16,7 +15,10 @@ void main()
{
vec3 n, halfV;
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 fragColor;
vec4 specular = vec4(0.0);

View 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;
}