attribute vec3 position; attribute vec3 normal; attribute vec2 texcoord; uniform mat4 modelViewProjectionMatrix; uniform mat4 modelViewMatrix; uniform mat4 modelViewMatrixInverse; uniform mat4 normalMatrix; uniform vec3 chromaticDispertion; uniform float bias; uniform float scale; uniform float power; uniform float a; uniform float b; uniform float c; uniform float d; uniform float tdelta; uniform float pdelta; varying vec3 t; varying vec3 tr; varying vec3 tg; varying vec3 tb; varying float rfac; vec3 cart2sphere(vec3 p) { float r = pow(p.x*p.x + p.y*p.y + p.z*p.z, 0.5); float theta = acos(p.z/r); float phi = atan(p.y, p.x); return vec3(r, theta, phi); } vec3 rose(vec3 p) { float rho = a + b * cos(c * p.y + tdelta) * cos(d * p.z + pdelta); float x = rho * cos(p.z) * cos(p.y); float y = rho * cos(p.z) * sin(p.y); float z = rho * sin(p.z); return vec3(x, y, z); } vec3 rose_normal(vec3 p) { /* convert cartesian position to spherical coordinates */ vec3 base = cart2sphere(p); /* add a little to phi */ vec3 td = base + vec3(0.0, 0.01, 0.0); /* add a little to theta */ vec3 pd = base + vec3(0.0, 0.0, 0.01); /* convert back to cartesian coordinates */ vec3 br = rose(base); vec3 bt = rose(td); vec3 bp = rose(pd); return normalize(cross(bt - br, bp - br)); } void main() { mat3 mvm3=mat3( modelViewMatrix[0].x, modelViewMatrix[0].y, modelViewMatrix[0].z, modelViewMatrix[1].x, modelViewMatrix[1].y, modelViewMatrix[1].z, modelViewMatrix[2].x, modelViewMatrix[2].y, modelViewMatrix[2].z ); vec3 fragNormal = mvm3*rose_normal(position); gl_Position = modelViewProjectionMatrix*vec4(rose(cart2sphere(position)), 1.0); vec3 incident = normalize((modelViewMatrix * vec4(rose(cart2sphere(position)), 1.0)).xyz); t = reflect(incident, fragNormal)*mvm3; tr = refract(incident, fragNormal, chromaticDispertion.x)*mvm3; tg = refract(incident, fragNormal, chromaticDispertion.y)*mvm3; tb = refract(incident, fragNormal, chromaticDispertion.z)*mvm3; rfac = bias + scale * pow(0.5+0.5*dot(incident, fragNormal), power); } #ifdef GL_ES precision highp float; #endif uniform samplerCube cube; varying vec3 t; varying vec3 tr; varying vec3 tg; varying vec3 tb; varying float rfac; void main() { vec4 ref = textureCube(cube, t); vec4 ret = vec4(1.0); ret.r = textureCube(cube, tr).r; ret.g = textureCube(cube, tg).g; ret.b = textureCube(cube, tb).b; gl_FragColor = ret * rfac + ref * (1.0 - rfac); }