diff options
author | Sven Gothel <[email protected]> | 2012-10-12 15:10:29 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-10-12 15:10:29 +0200 |
commit | e3ee1e25276760cba5db0333301d3ba19d62dd69 (patch) | |
tree | 0d7a01e14de75132856e77b619837b1887d5456a /src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders | |
parent | da258d10d4e929bb2993e7a0329ad32d079fd731 (diff) |
Enhance FixedFuncPipeline: Multi-Texture, Tex-Env, Alpha-Test, Lighting (fix, incomplete still), ShaderSelectionMode, Fix default values
Besides the above mentioned additional features towards completness of the FFP emu,
the ShaderSelectionMode allows fixating a shader program configuration,
i.e. AUTO switch (default) or choosing a static shader program to avoid heavy program switches
incl. uniform/attribute updates.
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders')
8 files changed, 186 insertions, 43 deletions
diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.fp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.fp index 408ff7251..bd7f2bdb2 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.fp +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColor.fp @@ -3,14 +3,21 @@ #include mgl_uniform.glsl #include mgl_varying.glsl +#include mgl_alphatest.fp + void main (void) { - if( mgl_CullFace > 0 && - ( ( mgl_CullFace == 1 && gl_FrontFacing ) || - ( mgl_CullFace == 2 && !gl_FrontFacing ) || - ( mgl_CullFace == 3 ) ) ) { - discard; + HIGHP vec4 color = frontColor; + + if( mgl_CullFace > 0 && + ( ( MGL_FRONT == mgl_CullFace && gl_FrontFacing ) || + ( MGL_BACK == mgl_CullFace && !gl_FrontFacing ) || + ( MGL_FRONT_AND_BACK == mgl_CullFace ) ) ) { + DISCARD(color); + } + if( mgl_AlphaTestFunc > 0 ) { + alphaTest(color); } - gl_FragColor = frontColor; + gl_FragColor = color; } diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorLight.vp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorLight.vp index 7ce1eedcf..0b5519355 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorLight.vp +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorLight.vp @@ -50,16 +50,18 @@ void main(void) } } } - ambient *= mgl_FrontMaterial.ambient; - diffuse *= mgl_FrontMaterial.diffuse; - specular *= mgl_FrontMaterial.specular; - if(mgl_ColorEnabled>0) { frontColor=mgl_Color; } else { frontColor=mgl_ColorStatic; } if( lightEnabled ) { + // light-ambient + global-ambient + // ( mgl_LightSource[0..n].ambient * mgl_FrontMaterial.ambient ) + ( mgl_LightModel.ambient * mgl_FrontMaterial.ambient ) + ambient = ( ambient + mgl_LightModel.ambient ) * mgl_FrontMaterial.ambient; + diffuse *= mgl_FrontMaterial.diffuse; + specular *= mgl_FrontMaterial.specular; + frontColor *= ambient + diffuse + specular; } diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorTexture.fp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorTexture.fp index 86e6ace73..edaa00a57 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorTexture.fp +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncColorTexture.fp @@ -6,42 +6,98 @@ #include mgl_uniform.glsl #include mgl_varying.glsl -vec4 getTexColor(in sampler2D tex, in int idx) { - vec4 coord; - if(idx==0) { - coord= mgl_TexCoords[0]; - } else if(idx==1) { - coord= mgl_TexCoords[1]; - } else if(idx==2) { - coord= mgl_TexCoords[2]; - } else if(idx==3) { - coord= mgl_TexCoords[3]; - } else if(idx==4) { - coord= mgl_TexCoords[4]; - } else if(idx==5) { - coord= mgl_TexCoords[5]; - } else if(idx==6) { - coord= mgl_TexCoords[6]; - } else { - coord= mgl_TexCoords[7]; +#include mgl_alphatest.fp + +const HIGHP float gamma = 1.5; // FIXME +const HIGHP vec3 igammav = vec3(1.0 / gamma); // FIXME +const vec4 texEnvColor = vec4(0.0); // FIXME + +const HIGHP vec4 zerov4 = vec4(0.0); +const HIGHP vec4 onev4 = vec4(1.0); + +void calcTexColor(inout vec4 color, vec4 texColor, in int texFormat, in int texEnvMode) { + if(MGL_MODULATE == texEnvMode) { // default + if( 4 == texFormat ) { + color *= texColor; + } else { + color.rgb *= texColor.rgb; + } + } else if(MGL_REPLACE == texEnvMode) { + if( 4 == texFormat ) { + color = texColor; + } else { + color.rgb = texColor.rgb; + } + } else if(MGL_ADD == texEnvMode) { + if( 4 == texFormat ) { + color += texColor; + } else { + color.rgb += texColor.rgb; + } + } else if(MGL_BLEND == texEnvMode) { + color.rgb = mix(color.rgb, texEnvColor.rgb, texColor.rgb); + if( 4 == texFormat ) { + color.a *= texColor.a; + } + } else if(MGL_DECAL == texEnvMode) { + if( 4 == texFormat ) { + color.rgb = mix(color.rgb, texColor.rgb, texColor.a); + } else { + color.rgb = texColor.rgb; + } } - return texture2D(tex, coord.st); + color = clamp(color, zerov4, onev4); } void main (void) -{ - if( mgl_CullFace > 0 && - ( ( mgl_CullFace == 1 && gl_FrontFacing ) || - ( mgl_CullFace == 2 && !gl_FrontFacing ) || - ( mgl_CullFace == 3 ) ) ) { - discard; - } - - vec4 texColor = getTexColor(mgl_ActiveTexture,mgl_ActiveTextureIdx); +{ + HIGHP vec4 color = frontColor; - if(length(texColor.rgb)>0.0) { - gl_FragColor = vec4(frontColor.rgb*texColor.rgb, frontColor.a) ; + if( mgl_CullFace > 0 && + ( ( MGL_FRONT == mgl_CullFace && gl_FrontFacing ) || + ( MGL_BACK == mgl_CullFace && !gl_FrontFacing ) || + ( MGL_FRONT_AND_BACK == mgl_CullFace ) ) ) { + DISCARD(color); } else { - gl_FragColor = frontColor; + int texEnv = 0; + + if( 0 != mgl_TextureEnabled[0] ) { + calcTexColor(color, texture2D(mgl_Texture0, mgl_TexCoords[0].st), mgl_TexFormat[0], mgl_TexEnvMode[0]); + } + if( 0 != mgl_TextureEnabled[1] ) { + calcTexColor(color, texture2D(mgl_Texture1, mgl_TexCoords[1].st), mgl_TexFormat[1], mgl_TexEnvMode[1]); + } + if( 0 != mgl_TextureEnabled[2] ) { + calcTexColor(color, texture2D(mgl_Texture2, mgl_TexCoords[2].st), mgl_TexFormat[2], mgl_TexEnvMode[2]); + } + if( 0 != mgl_TextureEnabled[3] ) { + calcTexColor(color, texture2D(mgl_Texture3, mgl_TexCoords[3].st), mgl_TexFormat[3], mgl_TexEnvMode[3]); + } + if( 0 != mgl_TextureEnabled[4] ) { + calcTexColor(color, texture2D(mgl_Texture4, mgl_TexCoords[4].st), mgl_TexFormat[4], mgl_TexEnvMode[4]); + } + if( 0 != mgl_TextureEnabled[5] ) { + calcTexColor(color, texture2D(mgl_Texture5, mgl_TexCoords[5].st), mgl_TexFormat[5], mgl_TexEnvMode[5]); + } + if( 0 != mgl_TextureEnabled[6] ) { + calcTexColor(color, texture2D(mgl_Texture6, mgl_TexCoords[6].st), mgl_TexFormat[6], mgl_TexEnvMode[6]); + } + if( 0 != mgl_TextureEnabled[7] ) { + calcTexColor(color, texture2D(mgl_Texture7, mgl_TexCoords[7].st), mgl_TexFormat[7], mgl_TexEnvMode[7]); + } + if( mgl_AlphaTestFunc > 0 ) { + alphaTest(color); + } } + + gl_FragColor = color; + /** + // simple alpha check + if (color.a != 0.0) { + gl_FragColor = vec4(pow(color.rgb, igammav), color.a); + } else { + // discard; // freezes NV tegra2 compiler + gl_FragColor = color; + } */ } + diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_alphatest.fp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_alphatest.fp new file mode 100644 index 000000000..2b64cdeb8 --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_alphatest.fp @@ -0,0 +1,33 @@ + +void alphaTest(inout vec4 color) { + if( MGL_GREATER == mgl_AlphaTestFunc ) { + if ( color.a <= mgl_AlphaTestRef ) { + DISCARD(color); + } + } else if( MGL_LESS == mgl_AlphaTestFunc ) { + if ( color.a >= mgl_AlphaTestRef ) { + DISCARD(color); + } + } else if( MGL_LEQUAL == mgl_AlphaTestFunc ) { + if ( color.a > mgl_AlphaTestRef ) { + DISCARD(color); + } + } else if( MGL_GEQUAL == mgl_AlphaTestFunc ) { + if ( color.a < mgl_AlphaTestRef ) { + DISCARD(color); + } + } else if( MGL_EQUAL == mgl_AlphaTestFunc ) { + if ( abs( color.a - mgl_AlphaTestRef ) > EPSILON ) { + DISCARD(color); + } + } else if( MGL_NOTEQUAL == mgl_AlphaTestFunc ) { + if ( abs( color.a - mgl_AlphaTestRef ) <= EPSILON ) { + DISCARD(color); + } + } else if( MGL_NEVER == mgl_AlphaTestFunc ) { + DISCARD(color); + } /* else if( MGL_ALWAYS == mgl_AlphaTestFunc ) { + // NOP + } */ +} + diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_const.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_const.glsl index 1a464a1cb..d45b593e2 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_const.glsl +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_const.glsl @@ -7,4 +7,33 @@ const LOWP int MAX_TEXTURE_UNITS = 8; // <=gl_MaxTextureImageUnits const LOWP int MAX_LIGHTS = 8; +const HIGHP float EPSILON = 0.0000001; // FIXME: determine proper hw-precision + +// discard freezes NV tegra2 compiler (STILL TRUE?) +// #define DISCARD(c) (c.a = 0.0) +#define DISCARD(c) discard + +// Texture Environment / Multi Texturing +#define MGL_ADD 1 +#define MGL_MODULATE 2 +#define MGL_DECAL 3 +#define MGL_BLEND 4 +#define MGL_REPLACE 5 +#define MGL_COMBINE 6 + +// Alpha Test +#define MGL_NEVER 1 +#define MGL_LESS 2 +#define MGL_EQUAL 3 +#define MGL_LEQUAL 4 +#define MGL_GREATER 5 +#define MGL_NOTEQUAL 6 +#define MGL_GEQUAL 7 +#define MGL_ALWAYS 8 + +// Cull Face +#define MGL_FRONT 1 +#define MGL_BACK 2 +#define MGL_FRONT_AND_BACK 3 + #endif // mgl_const_glsl diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_lightdef.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_lightdef.glsl index 98e214139..deaf95408 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_lightdef.glsl +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_lightdef.glsl @@ -1,6 +1,9 @@ #ifndef mgl_lightdef_glsl #define mgl_lightdef_glsl +struct mgl_LightModelParameters { + vec4 ambient; +}; struct mgl_LightSourceParameters { vec4 ambient; vec4 diffuse; diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl index 4c4000dfa..aeaa1314d 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl @@ -9,9 +9,21 @@ uniform HIGHP mat4 mgl_PMVMatrix[4]; // P, Mv, Mvi and Mvit (transpose(inverse(ModelView)) == normalMatrix) uniform LOWP int mgl_ColorEnabled; uniform HIGHP vec4 mgl_ColorStatic; +uniform LOWP int mgl_AlphaTestFunc; +uniform HIGHP float mgl_AlphaTestRef; +uniform LOWP int mgl_TextureEnabled[MAX_TEXTURE_UNITS]; uniform LOWP int mgl_TexCoordEnabled[MAX_TEXTURE_UNITS]; -uniform sampler2D mgl_ActiveTexture; -uniform LOWP int mgl_ActiveTextureIdx; +uniform LOWP int mgl_TexEnvMode[MAX_TEXTURE_UNITS]; +uniform LOWP int mgl_TexFormat[MAX_TEXTURE_UNITS]; +uniform sampler2D mgl_Texture0; +uniform sampler2D mgl_Texture1; +uniform sampler2D mgl_Texture2; +uniform sampler2D mgl_Texture3; +uniform sampler2D mgl_Texture4; +uniform sampler2D mgl_Texture5; +uniform sampler2D mgl_Texture6; +uniform sampler2D mgl_Texture7; +uniform sampler2D mgl_Texture8; uniform LOWP int mgl_CullFace; #endif // mgl_uniform_glsl diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform_light.glsl b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform_light.glsl index 0dedb5d5d..5b34fd9cf 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform_light.glsl +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform_light.glsl @@ -9,6 +9,7 @@ uniform LOWP int mgl_LightsEnabled[MAX_LIGHTS]; +uniform mgl_LightModelParameters mgl_LightModel; uniform mgl_LightSourceParameters mgl_LightSource[MAX_LIGHTS]; uniform mgl_MaterialParameters mgl_FrontMaterial; |