aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-10-22 18:54:19 +0200
committerSven Gothel <[email protected]>2012-10-22 18:54:19 +0200
commit5bdd283a9c3d0c656c859d499476173e2f609839 (patch)
tree7763f7eed5faaa3ab2b1bca5bf23cb9528e4f5fe /src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders
parent40d01bef2a1db44533472c37961aabbef68de644 (diff)
FixedFuncPipeline GL_POINTS: Fix gl_PointSize (attribute data format), Add GL_POINT_SOFT and dist/fade attenuation (Adding basic POINT unit tests)
gl_PointSize (and all other uniform array elems) was not propagated due to wrong usage of GLUniformData component param. Due to efficiency, we use vec4[2] now and #defines in shader to easy readability. GL_POINT_SOFT uses gl_PointCoord to determnine inside/outside circle position while adding a seam of 10% in/out. This almost matches 'other' implementations and gives a nice smooth circle. !GL_POINT_SOFT produces a proper square (billboard). Point-Vertex shader takes dist/fade attentuation into account.
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders')
-rw-r--r--src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.fp29
-rw-r--r--src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.vp25
-rw-r--r--src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/mgl_uniform.glsl15
3 files changed, 56 insertions, 13 deletions
diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.fp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.fp
index beca47bc1..6185e96ef 100644
--- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.fp
+++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.fp
@@ -6,11 +6,34 @@
#include mgl_uniform.glsl
#include mgl_varying.glsl
+// #define TEST 1
+
void main (void)
{
- // FIXME: Since gl_Points must be 1.0 (otherwise no points)
- // don't see reason for fetching texture color.
- // gl_FragColor = frontColor * texture2D(mgl_Texture0, gl_PointCoord);
gl_FragColor = frontColor;
+
+ if( pointSmooth > 0.5 ) {
+ // smooth (AA)
+ const float border = 0.90; // take/give 10% for AA
+
+ // origin to 0/0, [-1/-1 .. 1/1]
+ vec2 pointPos = 2.0 * gl_PointCoord - 1.0 ;
+ float r = length( pointPos ); // one-circle sqrt(x * x + y * y), range: in-circle [0..1], out >1
+ float r1 = 1.0 - ( step(border, r) * 10.0 * ( r - border ) ) ; // [0..1]
+ #ifndef TEST
+ if( r1 < 0.0 ) {
+ discard;
+ }
+ #endif
+
+ #ifndef TEST
+ gl_FragColor.a *= r1;
+ #else
+ gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
+ gl_FragColor.r = r1 < 0.0 ? 1.0 : 0.0;
+ gl_FragColor.g = r > 1.0 ? 1.0 : 0.0;
+ gl_FragColor.b = r > border ? 1.0 : 0.0;
+ #endif
+ }
}
diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.vp b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.vp
index 6d6a3a982..64732dc9e 100644
--- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.vp
+++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/shaders/FixedFuncPoints.vp
@@ -9,17 +9,26 @@
void main(void)
{
- if(mgl_ColorEnabled>0) {
- frontColor=mgl_Color;
+ if( mgl_ColorEnabled > 0 ) {
+ frontColor = mgl_Color;
} else {
- frontColor=mgl_ColorStatic;
+ frontColor = mgl_ColorStatic;
}
- // FIXME: ES2 .. doesn't work, but even on desktop
- // no big points!
- // gl_PointSize = mgl_PointParams1[0];
- gl_PointSize = 1.0;
+ vec4 eyeCoord = mgl_PMVMatrix[1] * mgl_Vertex;
+ gl_Position = mgl_PMVMatrix[0] * eyeCoord;
- gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * vec4(mgl_Vertex.xyz, 1.0);
+ float dist = distance(eyeCoord, vec4(0.0, 0.0, 0.0, 1.0));
+ float atten = sqrt( 1.0 / ( pointDistanceConstantAtten +
+ ( pointDistanceLinearAtten +
+ pointDistanceQuadraticAtten * dist
+ ) * dist
+ )
+ );
+ float size = clamp(pointSize * atten, pointSizeMin, pointSizeMax);
+ gl_PointSize = max(size, pointFadeThresholdSize);
+
+ float fade = min(size, pointFadeThresholdSize) / pointFadeThresholdSize;
+ frontColor.a *= fade * fade;
}
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 fd24a953d..5029e4bd8 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
@@ -11,8 +11,19 @@ uniform LOWP int mgl_ColorEnabled;
uniform vec4 mgl_ColorStatic;
uniform LOWP int mgl_AlphaTestFunc;
uniform float mgl_AlphaTestRef;
-uniform MEDIUMP float mgl_PointParams1[4]; // sz, smooth, attnMinSz, attnMaxSz
-uniform MEDIUMP float mgl_PointParams2[4]; // attnCoeff(3), attnAlphaTs
+
+// [0].rgba: size, smooth, attnMinSz, attnMaxSz
+// [1].rgba: attnCoeff(3), attnFadeTs
+uniform MEDIUMP vec4 mgl_PointParams[2];
+
+#define pointSize (mgl_PointParams[0].r)
+#define pointSmooth (mgl_PointParams[0].g)
+#define pointSizeMin (mgl_PointParams[0].b)
+#define pointSizeMax (mgl_PointParams[0].a)
+#define pointDistanceConstantAtten (mgl_PointParams[1].r)
+#define pointDistanceLinearAtten (mgl_PointParams[1].g)
+#define pointDistanceQuadraticAtten (mgl_PointParams[1].b)
+#define pointFadeThresholdSize (mgl_PointParams[1].a)
// uniform LOWP int mgl_CullFace; // ES2 supports CullFace implicit ..
#if MAX_TEXTURE_UNITS > 0