diff options
author | Sven Gothel <[email protected]> | 2011-04-23 06:12:10 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-04-23 06:12:10 +0200 |
commit | 48201a6ea6471eb5951edb735b36156ab3410a15 (patch) | |
tree | b22314430e78ee9269f4fcb358b9b5a7dc8d1de7 /src/jogl/classes/jogamp/graph/curve/opengl/shader | |
parent | 54f58c0cb990eb2b4fc8c3be785cc47bde575f37 (diff) |
Refactored graph: Reduce/remove data copy/recreation; Shader cleanup
- Pass the current GL context object where it's required
- Introduce RenderState (which has ShaderState) to acquire/change shader related data (Region)
- Shader Cleanup: User import for common stuff; use req. version
- Reduce/remove data copy/recreation in *Region implementation
- UI/RIButton: Use defaults I like :)
Diffstat (limited to 'src/jogl/classes/jogamp/graph/curve/opengl/shader')
9 files changed, 168 insertions, 66 deletions
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java b/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java new file mode 100644 index 000000000..9fe084522 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java @@ -0,0 +1,18 @@ +package jogamp.graph.curve.opengl.shader; + +public class AttributeNames { + /** The vertices index in an OGL object + */ + public static final int VERTEX_ATTR_IDX = 1; // 0 is a generic special 0 .. + public static final String VERTEX_ATTR_NAME = "gca_Vertices"; + + /** The Texture Coord index in an OGL object + */ + public static final int TEXCOORD_ATTR_IDX = 2; + public static final String TEXCOORD_ATTR_NAME = "gca_TexCoords"; + + /** The color index in an OGL object + */ + public static final int COLOR_ATTR_IDX = 3; + public static final String COLOR_ATTR_NAME = "gca_Colors"; +} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java new file mode 100644 index 000000000..2e04278ca --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java @@ -0,0 +1,10 @@ +package jogamp.graph.curve.opengl.shader; + +public class UniformNames { + public static final String gcu_PMVMatrix = "gcu_PMVMatrix"; // gcu_PMVMatrix[3]; // P, Mv, and Mvi + public static final String gcu_ColorStatic = "gcu_ColorStatic"; + public static final String gcu_Alpha = "gcu_Alpha"; + public static final String gcu_P1Y = "gcu_P1Y"; + public static final String gcu_Strength = "gcu_Strength"; + public static final String gcu_TextureUnit = "gcu_TextureUnit"; +} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl new file mode 100644 index 000000000..e5ae2b42e --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl @@ -0,0 +1,12 @@ + +#ifndef attributes_glsl +#define attributes_glsl + +#include precision.glsl + +attribute HIGHP vec3 gca_Vertices; +attribute HIGHP vec2 gca_TexCoords; +//attribute HIGHP vec4 gca_Colors; +//attribute HIGHP vec3 gca_Normals; + +#endif // attributes_glsl diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl new file mode 100644 index 000000000..4cb41c903 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl @@ -0,0 +1,10 @@ + +#ifndef consts_glsl +#define consts_glsl + +#include precision.glsl + +const LOWP int MAX_TEXTURE_UNITS = 8; // <= gl_MaxTextureImageUnits +// const LOWP int MAX_LIGHTS = 8; + +#endif // consts_glsl diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp index 166937f7f..fca3bcc04 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.fp @@ -1,93 +1,93 @@ //Copyright 2010 JogAmp Community. All rights reserved. -//#version 100 -uniform float p1y; -uniform float g_alpha; -uniform vec3 g_color; -uniform float a_strength; +#ifdef GL_ES + #version 100 +#else + #version 130 +#endif -varying vec2 v_texCoord; +#include uniforms.glsl +#include attributes.glsl +#include varyings.glsl -vec3 b_color = vec3(0.0, 0.0, 0.0); - -uniform sampler2D texture; -vec4 weights = vec4(0.075, 0.06, 0.045, 0.025); +const vec3 b_color = vec3(0.0, 0.0, 0.0); +const vec4 weights = vec4(0.075, 0.06, 0.045, 0.025); void main (void) { - vec2 rtex = vec2(abs(v_texCoord.x),abs(v_texCoord.y)); - vec3 c = g_color; + vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y)); + vec3 c = gcu_ColorStatic.rgb; float alpha = 0.0; - if((v_texCoord.x == 0.0) && (v_texCoord.y == 0.0)){ - alpha = g_alpha; + if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)){ + alpha = gcu_Alpha; } - else if((v_texCoord.x >= 5.0)){ - vec2 dfx = dFdx(v_texCoord); - vec2 dfy = dFdy(v_texCoord); + else if((gcv_TexCoord.x >= 5.0)){ + vec2 dfx = dFdx(gcv_TexCoord); + vec2 dfy = dFdy(gcv_TexCoord); - vec2 size = 1.0/textureSize(texture,0); //version 130 + vec2 size = 1.0/textureSize(gcu_TextureUnit,0); //version 130 - FIXME: replace with uniform value rtex -= 5.0; - vec4 t = texture2D(texture, rtex)* 0.18; + vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18; - t += texture2D(texture, rtex + size*(vec2(1, 0)))*weights.x; - t += texture2D(texture, rtex - size*(vec2(1, 0)))*weights.x; - t += texture2D(texture, rtex + size*(vec2(0, 1)))*weights.x; - t += texture2D(texture, rtex - size*(vec2(0, 1)))*weights.x; + t += texture2D(gcu_TextureUnit, rtex + size*(vec2(1, 0)))*weights.x; + t += texture2D(gcu_TextureUnit, rtex - size*(vec2(1, 0)))*weights.x; + t += texture2D(gcu_TextureUnit, rtex + size*(vec2(0, 1)))*weights.x; + t += texture2D(gcu_TextureUnit, rtex - size*(vec2(0, 1)))*weights.x; - t += texture2D(texture, rtex + 2.0*size*(vec2(1, 0))) *weights.y; - t += texture2D(texture, rtex - 2.0*size*(vec2(1, 0)))*weights.y; - t += texture2D(texture, rtex + 2.0*size*(vec2(0, 1)))*weights.y; - t += texture2D(texture, rtex - 2.0*size*(vec2(0, 1)))*weights.y; + t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(1, 0)))*weights.y; + t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(1, 0)))*weights.y; + t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(0, 1)))*weights.y; + t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(0, 1)))*weights.y; - t += texture2D(texture, rtex + 3.0*size*(vec2(1, 0))) *weights.z; - t += texture2D(texture, rtex - 3.0*size*(vec2(1, 0)))*weights.z; - t += texture2D(texture, rtex + 3.0*size*(vec2(0, 1)))*weights.z; - t += texture2D(texture, rtex - 3.0*size*(vec2(0, 1)))*weights.z; + t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(1, 0)))*weights.z; + t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(1, 0)))*weights.z; + t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(0, 1)))*weights.z; + t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(0, 1)))*weights.z; - t += texture2D(texture, rtex + 4.0*size*(vec2(1, 0))) *weights.w; - t += texture2D(texture, rtex - 4.0*size*(vec2(1, 0)))*weights.w; - t += texture2D(texture, rtex + 4.0*size*(vec2(0, 1)))*weights.w; - t += texture2D(texture, rtex - 4.0*size*(vec2(0, 1)))*weights.w; + t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(1, 0)))*weights.w; + t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(1, 0)))*weights.w; + t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(0, 1)))*weights.w; + t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(0, 1)))*weights.w; if(t.w == 0.0){ discard; } c = t.xyz; - alpha = g_alpha* t.w; + alpha = gcu_Alpha * t.w; } /////////////////////////////////////////////////////////// - else if ((v_texCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)){ - vec2 dtx = dFdx(rtex); - vec2 dty = dFdy(rtex); + else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)){ + vec2 dtx = dFdx(rtex); + vec2 dty = dFdy(rtex); - rtex.y -= 0.1; + rtex.y -= 0.1; - if(rtex.y < 0.0) { - if(v_texCoord.y < 0.0) - discard; - else{ - rtex.y = 0.0; - } - } + if(rtex.y < 0.0) { + if(gcv_TexCoord.y < 0.0) + discard; + else{ + rtex.y = 0.0; + } + } - vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x)); - float position = rtex.y - (rtex.x * (1.0 - rtex.x)); - float d = position/(length(f)); + vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x)); + float position = rtex.y - (rtex.x * (1.0 - rtex.x)); + float d = position/(length(f)); - float a = (0.5 - d * sign(v_texCoord.y)); + float a = (0.5 - d * sign(gcv_TexCoord.y)); if (a >= 1.0) { - alpha = g_alpha; + alpha = gcu_Alpha; } - else if (a <= 0.0) { - alpha = 0.0;//discard; - } - else { - alpha = g_alpha*a; - mix(b_color,g_color, a); + else if (a <= 0.0) { + alpha = 0.0;//discard; + } + else { + alpha = gcu_Alpha * a; + mix(b_color,gcu_ColorStatic.rgb, a); } } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp index bc9ecb41e..298dce7ef 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01.vp @@ -1,13 +1,17 @@ -//#version 100 +//Copyright 2010 JogAmp Community. All rights reserved. -uniform mat4 mgl_PMVMatrix[2]; -attribute vec4 v_position; -attribute vec2 texCoord; +#ifdef GL_ES + #version 100 +#else + #version 110 +#endif -varying vec2 v_texCoord; +#include uniforms.glsl +#include attributes.glsl +#include varyings.glsl void main(void) { - gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * v_position; - v_texCoord = texCoord.st; -}
\ No newline at end of file + gl_Position = gcu_PMVMatrix[0] * gcu_PMVMatrix[1] * vec4(gca_Vertices, 1); + gcv_TexCoord = gca_TexCoords; +} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/precision.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/precision.glsl new file mode 100644 index 000000000..1ac4ed8e9 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/precision.glsl @@ -0,0 +1,14 @@ +#ifndef precision_glsl +#define precision_glsl + +#ifdef GL_ES + #define MEDIUMP mediump + #define HIGHP highp + #define LOWP lowp +#else + #define MEDIUMP + #define HIGHP + #define LOWP +#endif + +#endif // precision_glsl diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl new file mode 100644 index 000000000..677c7324f --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl @@ -0,0 +1,21 @@ + +#ifndef uniforms_glsl +#define uniforms_glsl + +#include precision.glsl + +// #include consts.glsl + +uniform HIGHP mat4 gcu_PMVMatrix[3]; // P, Mv, and Mvi +uniform HIGHP vec3 gcu_ColorStatic; +uniform HIGHP float gcu_Alpha; +uniform HIGHP float gcu_P1Y; +uniform HIGHP float gcu_Strength; +uniform sampler2D gcu_TextureUnit; + +// uniform HIGHP mat3 gcu_NormalMatrix; // transpose(inverse(ModelView)).3x3 +// uniform LOWP int gcu_ColorEnabled; +// uniform LOWP int gcu_TexCoordEnabled[MAX_TEXTURE_UNITS]; +// uniform LOWP int gcu_CullFace; + +#endif // uniforms_glsl diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl new file mode 100644 index 000000000..e70c25266 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl @@ -0,0 +1,13 @@ + +#ifndef varyings_glsl +#define varyings_glsl + +#include precision.glsl + +#include consts.glsl + +varying vec4 gcv_FrontColor; +varying vec2 gcv_TexCoord; + +#endif // varyings_glsl + |