aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-09-28 20:09:11 +0200
committerSven Gothel <[email protected]>2011-09-28 20:09:11 +0200
commit038002b80f6541e91a7d4559f4b04858698793e0 (patch)
treea51b14663f8921b8bc5a6b184b96bfb0aaed2c0d /src
parent22e869ae8b6a44e2f06f73b557a0b8d3bb0da49f (diff)
demo: es2 shaders: use default precision
Diffstat (limited to 'src')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/elektronenmultiplizierer_development.fp172
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.fp47
2 files changed, 106 insertions, 113 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/elektronenmultiplizierer_development.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/elektronenmultiplizierer_development.fp
index 948037e92..6c9e0485a 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/elektronenmultiplizierer_development.fp
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/elektronenmultiplizierer_development.fp
@@ -10,31 +10,27 @@
**/
#ifdef GL_ES
- #define MEDIUMP mediump
- #define HIGHP highp
- #define LOWP lowp
-#else
- #define MEDIUMP
- #define HIGHP
- #define LOWP
+ precision mediump float;
+ precision mediump sampler2D;
+ precision mediump int;
#endif
-uniform MEDIUMP int en; //effectnumber
-uniform MEDIUMP float et; //effecttime
-uniform MEDIUMP sampler2D fb; //fbotexture
-uniform MEDIUMP float br; //brightness
-uniform MEDIUMP float tm; //time
-uniform MEDIUMP vec2 resolution;//screen resolution/fbo resolution
+uniform int en; //effectnumber
+uniform float et; //effecttime
+uniform sampler2D fb; //fbotexture
+uniform float br; //brightness
+uniform float tm; //time
+uniform vec2 resolution;//screen resolution/fbo resolution
-MEDIUMP float camerafocallengthdode;
-MEDIUMP vec3 camerapositiondode;
-MEDIUMP vec2 sizedode;
-MEDIUMP vec3 backgroundcolor = vec3(0,0.6,0.46);
-MEDIUMP mat3 worldrotationxyz;
-MEDIUMP mat3 fractalplanerotationx;
-MEDIUMP mat3 fractalplanerotationy;
-MEDIUMP mat3 camerarotationdode;
-MEDIUMP vec2 oglFragCoord;
+float camerafocallengthdode;
+vec3 camerapositiondode;
+vec2 sizedode;
+vec3 backgroundcolor = vec3(0,0.6,0.46);
+mat3 worldrotationxyz;
+mat3 fractalplanerotationx;
+mat3 fractalplanerotationy;
+mat3 camerarotationdode;
+vec2 oglFragCoord;
//fractal formula used for sphreretracing/distance-estimation
//dodecahedron serpinski (knighty)
@@ -43,27 +39,27 @@ MEDIUMP vec2 oglFragCoord;
//(phi^2, 1, -phi), (-phi, phi^2, 1), (1, -phi, phi^2), (-phi*(1+phi), phi^2-1, 1+phi), (1+phi, -phi*(1+phi), phi^2-1) and x=0, y=0, z=0 planes.
//const pre-calc
-const MEDIUMP float phi = 1.618;
-const MEDIUMP float _IKVNORM_ = 1.0 / sqrt(pow(phi * (1.0 + phi), 2.0) + pow(phi * phi - 1.0, 2.0) + pow(1.0 + phi, 2.0));
-const MEDIUMP float _C1_ = phi * (1.0 + phi) * _IKVNORM_;
-const MEDIUMP float _C2_ = (phi * phi - 1.0) * _IKVNORM_;
-const MEDIUMP float _1C_ = (1.0 + phi) * _IKVNORM_;
-const MEDIUMP vec3 phi3 = vec3(0.5, 0.5 / phi, 0.5 * phi);
-const MEDIUMP vec3 c3 = vec3(_C1_, _C2_, _1C_);
+const float phi = 1.618;
+const float _IKVNORM_ = 1.0 / sqrt(pow(phi * (1.0 + phi), 2.0) + pow(phi * phi - 1.0, 2.0) + pow(1.0 + phi, 2.0));
+const float _C1_ = phi * (1.0 + phi) * _IKVNORM_;
+const float _C2_ = (phi * phi - 1.0) * _IKVNORM_;
+const float _1C_ = (1.0 + phi) * _IKVNORM_;
+const vec3 phi3 = vec3(0.5, 0.5 / phi, 0.5 * phi);
+const vec3 c3 = vec3(_C1_, _C2_, _1C_);
-MEDIUMP vec3 distancefunction(MEDIUMP vec3 w) {
+vec3 distancefunction(vec3 w) {
//!P center scale offset ...
- MEDIUMP vec3 offset;
+ vec3 offset;
if (en==6) {
offset = vec3(0.61,0.1*et,0.99);
} else {
offset = vec3(0.61,0.0,0.99);
}
//!P center scale \0/ this is awesome for fadeins !!!
- MEDIUMP float scale = 2.;
+ float scale = 2.;
w *= worldrotationxyz;
- MEDIUMP float d, t;
- MEDIUMP float md = 1000.0, cd = 0.0;
+ float d, t;
+ float md = 1000.0, cd = 0.0;
//!P iterations (8) ... 2x see below
for (int i = 0; i < 8; i++) {
w *= fractalplanerotationx;
@@ -94,27 +90,27 @@ MEDIUMP vec3 distancefunction(MEDIUMP vec3 w) {
}
//calculate ray direction fragment coordinates
-MEDIUMP vec3 raydirection(MEDIUMP vec2 pixel) {
- MEDIUMP vec2 p = (0.5*sizedode-pixel)/vec2(sizedode.x,-sizedode.y);
+vec3 raydirection(vec2 pixel) {
+ vec2 p = (0.5*sizedode-pixel)/vec2(sizedode.x,-sizedode.y);
//!P aspect ratio of dode
p.x *= sizedode.x/sizedode.y;
//!P vec3 w = vec3(0, 0, 1), vec3 v = vec3(0, 1, 0), vec3 u = vec3(1, 0, 0);
- MEDIUMP vec3 d = (p.x * vec3(1, 0, 0)+p.y * vec3(0, 1, 0)-camerafocallengthdode * vec3(0, 0, 1));
+ vec3 d = (p.x * vec3(1, 0, 0)+p.y * vec3(0, 1, 0)-camerafocallengthdode * vec3(0, 0, 1));
return normalize(camerarotationdode * d);
}
//iq's fake ambient occlusion
//http://www.iquilezles.org/www/material/nvscene2008/rwwtt.pdf
//http://www.iquilezles.org/www/articles/ao/ao.htm
-MEDIUMP float ambientocclusion(MEDIUMP vec3 p, MEDIUMP vec3 n, MEDIUMP float eps) {
- MEDIUMP float o = 1.0;
+float ambientocclusion(vec3 p, vec3 n, float eps) {
+ float o = 1.0;
//!P ao spread (10.6)
// spreads the output color intensity
eps *= 10.6;
//!P ao intensity (0.16)
- MEDIUMP float k = 0.16 / eps;
+ float k = 0.16 / eps;
//add little start distance to the surface
- MEDIUMP float d = 2.0 * eps;
+ float d = 2.0 * eps;
//!P ao iterations (5) ...
for (int i = 0; i < 5; ++i) {
o -= (d - distancefunction(p + n * d).x) * k;
@@ -125,24 +121,24 @@ MEDIUMP float ambientocclusion(MEDIUMP vec3 p, MEDIUMP vec3 n, MEDIUMP float eps
return clamp(o, 0.0, 1.0);
}
-MEDIUMP vec4 render(MEDIUMP vec2 pixel) {
- MEDIUMP vec3 ray_direction = raydirection(pixel);
+vec4 render(vec2 pixel) {
+ vec3 ray_direction = raydirection(pixel);
//!P minimum ray length (6e-5)
- MEDIUMP float ray_length = 6e-5;
- MEDIUMP vec3 ray = camerapositiondode + ray_length * ray_direction;
+ float ray_length = 6e-5;
+ vec3 ray = camerapositiondode + ray_length * ray_direction;
//!P minimum epsilon (6e-7) ...
- MEDIUMP float eps = 6e-7;
- MEDIUMP vec3 dist;
- MEDIUMP vec3 normal = vec3(0);
- MEDIUMP int steps = 0;
- MEDIUMP bool hit = false;
- MEDIUMP float minmarch = 0.0;
+ float eps = 6e-7;
+ vec3 dist;
+ vec3 normal = vec3(0);
+ int steps = 0;
+ bool hit = false;
+ float minmarch = 0.0;
//!P maxmarch = 10000.0;
- MEDIUMP float maxmarch = 25.0;
+ float maxmarch = 25.0;
//!P field of view scale = (1.0 / sqrt(1.0 + camerafocallengthdode * camerafocallengthdode))
//!P detail of surface approximation = 1.22
//!P pixelscale = (1.0 / min(sizedode.x, sizedode.y))
- MEDIUMP float epsfactor = 2.0 * (1.0 / sqrt(1.0 + camerafocallengthdode * camerafocallengthdode)) * (1.0 / min(sizedode.x, sizedode.y)) * 1.22;
+ float epsfactor = 2.0 * (1.0 / sqrt(1.0 + camerafocallengthdode * camerafocallengthdode)) * (1.0 / min(sizedode.x, sizedode.y)) * 1.22;
ray_length = minmarch;
ray = camerapositiondode + ray_length * ray_direction;
//!P max number of raymarching steps (90);
@@ -165,15 +161,15 @@ MEDIUMP vec4 render(MEDIUMP vec2 pixel) {
}
}
//\0/ there is a hit!
- MEDIUMP vec4 color = vec4(backgroundcolor,0.5);
+ vec4 color = vec4(backgroundcolor,0.5);
if (hit) {
- MEDIUMP float aof = 1.0;
+ float aof = 1.0;
if (steps < 1 || ray_length < minmarch) {
normal = normalize(ray);
} else {
//gradient in x,y and z direction for intersection point
//!P minimum normal (1.5e-7)
- MEDIUMP float e = max(eps * 0.5, 1.5e-7);
+ float e = max(eps * 0.5, 1.5e-7);
normal = normalize(vec3(
distancefunction(ray + vec3(e, 0, 0)).x - distancefunction(ray - vec3(e, 0, 0)).x,
distancefunction(ray + vec3(0, e, 0)).x - distancefunction(ray - vec3(0, e, 0)).x,
@@ -182,7 +178,7 @@ MEDIUMP vec4 render(MEDIUMP vec2 pixel) {
aof = ambientocclusion(ray, normal, eps);
}
//!P hardcoded light position vec3(-50,150,-25)
- MEDIUMP float diffuse = max(dot(normal, normalize(vec3(-50,150,-25) - ray)), 0.0);
+ float diffuse = max(dot(normal, normalize(vec3(-50,150,-25) - ray)), 0.0);
//blinn/phong specular stuff ...
//!P specular exponent (4)
//!P specularity (0.8)
@@ -196,7 +192,7 @@ MEDIUMP vec4 render(MEDIUMP vec2 pixel) {
return color;
}
-MEDIUMP mat3 xmatrixrotation(MEDIUMP float angle) {
+mat3 xmatrixrotation(float angle) {
return mat3(
vec3(1.0, 0.0, 0.0),
vec3(0.0, cos(angle), sin(angle)),
@@ -204,7 +200,7 @@ MEDIUMP mat3 xmatrixrotation(MEDIUMP float angle) {
);
}
-MEDIUMP mat3 ymatrixrotation(MEDIUMP float angle) {
+mat3 ymatrixrotation(float angle) {
return mat3(
vec3(cos(angle), 0.0, -sin(angle)),
vec3( 0.0, 1.0, 0.0),
@@ -212,23 +208,23 @@ MEDIUMP mat3 ymatrixrotation(MEDIUMP float angle) {
);
}
-MEDIUMP vec4 raymarch_orbittrap_image(MEDIUMP vec2 fragcoord) {
+vec4 raymarch_orbittrap_image(vec2 fragcoord) {
//do the matrix calculations by hand X-)
//as mat4 constructor and arithmetic assignments are
//currently broken (2010-09-21) on ATI cards i found
//a workaround using vec4 constructors wich works on
//both NVIDIA+ATI --- MAGIC. DO NOT TOUCH! -=#:-)
- MEDIUMP mat3 identitymatrix = mat3(1,0,0,0,1,0,0,0,1);
- MEDIUMP float sin_phi = sin(0.1*tm);
- MEDIUMP float cos_phi = cos(0.1*tm);
- MEDIUMP mat3 zrot = mat3(
+ mat3 identitymatrix = mat3(1,0,0,0,1,0,0,0,1);
+ float sin_phi = sin(0.1*tm);
+ float cos_phi = cos(0.1*tm);
+ mat3 zrot = mat3(
vec3( cos_phi, sin_phi, 0.0),
vec3(-sin_phi, cos_phi, 0.0),
vec3( 0.0, 0.0, 1.0)
);
- MEDIUMP vec2 position;
- MEDIUMP float fractalplanex_var;
- MEDIUMP float fractalplaney_var;
+ vec2 position;
+ float fractalplanex_var;
+ float fractalplaney_var;
position = oglFragCoord.xy;
camerafocallengthdode = 1.0;
if (en==2) {
@@ -259,16 +255,16 @@ MEDIUMP vec4 raymarch_orbittrap_image(MEDIUMP vec2 fragcoord) {
fractalplanerotationx = xmatrixrotation(fractalplanex_var)*identitymatrix;
fractalplanerotationy = xmatrixrotation(fractalplaney_var)*identitymatrix;
camerarotationdode = ymatrixrotation(3.14)*identitymatrix;
- MEDIUMP vec4 color = render(position);
+ vec4 color = render(position);
return color;
}
//----------------------------------------------------------------------------------------------------------
-MEDIUMP vec4 orbitmapping(MEDIUMP vec4 c, MEDIUMP vec2 w) {
+vec4 orbitmapping(vec4 c, vec2 w) {
//!P orbit trap scale and offset
- MEDIUMP vec2 orbittrapoffset = vec2(0.24,-0.24);
- MEDIUMP float orbittrapscale;
+ vec2 orbittrapoffset = vec2(0.24,-0.24);
+ float orbittrapscale;
if (en==0) {
//julia set ...
orbittrapscale = 0.625;
@@ -276,20 +272,20 @@ MEDIUMP vec4 orbitmapping(MEDIUMP vec4 c, MEDIUMP vec2 w) {
//mandlebrot ...
orbittrapscale = 0.325;
}
- MEDIUMP vec2 sp = 0.5 + (w / orbittrapscale - orbittrapoffset);
- MEDIUMP vec4 s = texture2D(fb, sp);
+ vec2 sp = 0.5 + (w / orbittrapscale - orbittrapoffset);
+ vec4 s = texture2D(fb, sp);
if (s.a > 0.0) {
c = mix(c, s, s.a);
}
return c;
}
-MEDIUMP vec4 orbittrap(MEDIUMP vec2 z) {
- MEDIUMP float powerjulia = 2.;
- MEDIUMP vec3 colorjulia = vec3(1.0);
- MEDIUMP vec4 color = vec4(colorjulia, 0.0);
- MEDIUMP float n = 0.0;
- MEDIUMP vec2 c;
+vec4 orbittrap(vec2 z) {
+ float powerjulia = 2.;
+ vec3 colorjulia = vec3(1.0);
+ vec4 color = vec4(colorjulia, 0.0);
+ float n = 0.0;
+ vec2 c;
if (en==0) {
//julia mode ...
//!P use offset-julia from 2.25 to 2.5
@@ -301,8 +297,8 @@ MEDIUMP vec4 orbittrap(MEDIUMP vec2 z) {
//!P max iterations for julia (128) ... 2x parameter - see below!
for (int i = 0; i<128; i++) {
n += 1.0;
- MEDIUMP float r = pow(length(z), powerjulia);
- MEDIUMP float a = powerjulia * atan(z.y, z.x);
+ float r = pow(length(z), powerjulia);
+ float a = powerjulia * atan(z.y, z.x);
z = vec2(cos(a) * r, sin(a) * r) +c;
//!P min iterations for julia (1.0) ...
if (n >= 1.0) {
@@ -314,20 +310,20 @@ MEDIUMP vec4 orbittrap(MEDIUMP vec2 z) {
}
}
//!P max iterations for julia (128.0) ...
- MEDIUMP float blend = clamp(1.0 - (n / 128.0) * 2.0, 0.0, 1.0);
+ float blend = clamp(1.0 - (n / 128.0) * 2.0, 0.0, 1.0);
color.rgb = mix(colorjulia, color.rgb, blend);
return color;
}
void main() {
- MEDIUMP vec2 sizejulia = resolution;
+ vec2 sizejulia = resolution;
sizedode = sizejulia;
oglFragCoord = gl_FragCoord.xy;
- MEDIUMP vec4 color;
+ vec4 color;
if (en==0 || en==1) {
//render 2d julia/mandelbrot
//!P camera position for julia ...
- MEDIUMP vec3 camerapositionjulia;
+ vec3 camerapositionjulia;
if (en==0) {
//julia
camerapositionjulia = vec3(-0.2,-0.515,0.095347+(et*1.75));
@@ -336,7 +332,7 @@ void main() {
camerapositionjulia = vec3(0.325895,0.049551,0.0005+et);
}
//!P absolute output size of julia orbit trap ...
- MEDIUMP vec2 z = ((oglFragCoord.xy - (sizejulia * 0.5)) / sizejulia) *
+ vec2 z = ((oglFragCoord.xy - (sizejulia * 0.5)) / sizejulia) *
vec2(sizejulia.x/sizejulia.y, 1.0) * //aspect ratio
camerapositionjulia.z +
camerapositionjulia.xy;
@@ -349,9 +345,9 @@ void main() {
} else {
//do normal rendering ...
//analog-tv distortion ...
- MEDIUMP vec2 position = oglFragCoord.xy / sizejulia.xy;
+ vec2 position = oglFragCoord.xy / sizejulia.xy;
position.y *=-1.0;
- MEDIUMP vec3 color_tv = color.rgb;
+ vec3 color_tv = color.rgb;
//contrast
color_tv = clamp(color_tv*0.5+0.5*color_tv*color_tv*1.2,0.0,1.0);
//circular vignette fade
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.fp
index 9a89381d1..e8feef2fa 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.fp
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/gears.fp
@@ -2,45 +2,42 @@
// Details see GearsES2.java
#ifdef GL_ES
- #define MEDIUMP mediump
- #define HIGHP highp
-#else
- #define MEDIUMP
- #define HIGHP
+ precision mediump float;
+ precision mediump int;
#endif
-uniform MEDIUMP vec4 color;
+uniform vec4 color;
-varying MEDIUMP vec3 normal;
-varying MEDIUMP vec4 position;
-varying MEDIUMP vec3 lightDir;
-varying MEDIUMP float attenuation;
-varying MEDIUMP vec3 cameraDir;
+varying vec3 normal;
+varying vec4 position;
+varying vec3 lightDir;
+varying float attenuation;
+varying vec3 cameraDir;
// Defining The Material Colors
-const MEDIUMP vec4 matAmbient = vec4(0.2, 0.2, 0.2, 1.0); // orig default
-const MEDIUMP vec4 matDiffuse = vec4(0.8, 0.8, 0.8, 1.0); // orig default
-// const MEDIUMP vec4 matSpecular = vec4(0.0, 0.0, 0.0, 1.0); // orig default
-const MEDIUMP vec4 matSpecular = vec4(0.8, 0.8, 0.8, 1.0);
-// const MEDIUMP float matShininess = 0.0; // orig default
-const MEDIUMP float matShininess = 0.5;
+const vec4 matAmbient = vec4(0.2, 0.2, 0.2, 1.0); // orig default
+const vec4 matDiffuse = vec4(0.8, 0.8, 0.8, 1.0); // orig default
+// const vec4 matSpecular = vec4(0.0, 0.0, 0.0, 1.0); // orig default
+const vec4 matSpecular = vec4(0.8, 0.8, 0.8, 1.0);
+// const float matShininess = 0.0; // orig default
+const float matShininess = 0.5;
void main()
{
- MEDIUMP float lambertTerm = dot(normal, lightDir);
+ float lambertTerm = dot(normal, lightDir);
- MEDIUMP vec4 ambient = color * matAmbient;
- MEDIUMP vec4 diffuse = color * lambertTerm * attenuation * matDiffuse;
- MEDIUMP vec4 specular = vec4(0.0);
+ vec4 ambient = color * matAmbient;
+ vec4 diffuse = color * lambertTerm * attenuation * matDiffuse;
+ vec4 specular = vec4(0.0);
if (lambertTerm > 0.0) {
- MEDIUMP float NdotHV;
+ float NdotHV;
/*
- MEDIUMP vec3 halfDir;
+ vec3 halfDir;
halfDir = normalize (lightDir + cameraDir);
NdotHV = max(0.0, dot(normal, halfDir));
*/
- MEDIUMP vec3 E = normalize(-position.xyz);
- MEDIUMP vec3 R = reflect(-lightDir, normal);
+ vec3 E = normalize(-position.xyz);
+ vec3 R = reflect(-lightDir, normal);
NdotHV = max(0.0, dot(R, E));
specular += color * pow(NdotHV, matShininess) * attenuation * matSpecular;