Permalink
Browse files

AO start + shaderoptimalisations +camFIx

  • Loading branch information...
1 parent 8d73389 commit bb47e1f498ebc071a95dda9e17d0bc38c4b38cde @neuroprod committed Jan 10, 2012
View
@@ -400,8 +400,8 @@
if(lock==1){
- tempzoom =zoom;
-
+ tempzoom =zoom *zoom*-1 ;
+ cout << "start "<< zoom << " " << tempzoom <<endl;
centerMatrix.setTranslation( -model->center.x, -model->center.y, -model->center.z);
worldMatrix.makeIdentityMatrix();
worldMatrix.preMult(zoomMatrix);
@@ -468,36 +468,37 @@
}
float dx = maxx-minx;
float dy =maxy-miny;
- zoomf =sqrt( (dx*dx)+(dy*dy) )/(4.0 * tan(45.0/360.0 *3.1415));
+ zoomf =sqrtf ( (dx*dx)+(dy*dy) )/(4.0 * tan(45.0/360.0 *3.1415));
tempzoom *=zoomf;
if (lock!=0){
worldMatrix.makeIdentityMatrix();
zoomMatrix.makeIdentityMatrix();
- zoomMatrix.translate(0.0,0,tempzoom*tempzoom*-1 );
+ zoomMatrix.translate(0.0,0,tempzoom );
worldMatrix.preMult(zoomMatrix);
worldMatrix.preMult( normalMatrix);
worldMatrix.preMult(centerMatrix);
return;
}
if (!dotween)
{
- currentCenterX =-model->center.x;
+ currentCenterX =-model->center.x;
currentCenterY =-model->center.y;
currentCenterZ =-model->center.z;
centerMatrix.setTranslation( -model->center.x, -model->center.y, -model->center.z);
- zoom =tempzoom ;
+ zoom =tempzoom;
isDirty =true;
+ cout << "noTween\n";
}else
{
npTween mijnTween;
mijnTween.init(this,NP_EASE_OUT_SINE,400,0);
-
+ cout << "Tween "<< tempzoom <<endl;
mijnTween.addProperty(&currentCenterX,-model->center.x);
mijnTween.addProperty(&currentCenterY,-model->center.y);
mijnTween.addProperty(&currentCenterZ,-model->center.z );
- mijnTween.addProperty(&zoom,tempzoom );
+ mijnTween.addProperty(&zoom,sqrtf(-tempzoom)*-1);
makeCallBack(Camera,setComplete,call );
mijnTween.addEventListener( NP_TWEEN_COMPLETE , call);
@@ -53,6 +53,7 @@ class CubeRenderer
GLuint textureDepth;
GLint uWorldMatrixDepth;
GLint uPerspectiveMatrixDepth;
+ GLint uNormalMatrixDepth;
GLint uMinDepth;
GLint uDepthRange;
@@ -551,13 +551,15 @@
glBindAttribLocation(programDepth, ATTRIB_VERTEX, "position");
-
+ glBindAttribLocation(programDepth, ATTRIB_NORMAL, "normal");
pLoader->linkProgram();
delete pLoader;
glUseProgram(programDepth);
uWorldMatrixDepth= glGetUniformLocation(programDepth, "worldMatrix");
uPerspectiveMatrixDepth= glGetUniformLocation(programDepth, "perspectiveMatrix");
+ uNormalMatrixDepth= glGetUniformLocation(programDepth, "normalMatrix");
+
uDepthRange= glGetUniformLocation(programDepth, "depthRange");
uMinDepth= glGetUniformLocation(programDepth, "minDepth");
@@ -742,7 +744,7 @@
void CubeRenderer::prepForAODraw()
{
- glBindTexture(GL_TEXTURE_2D, textureBlur2);
+ glBindTexture(GL_TEXTURE_2D, textureBlur);
useAO =false;
}
@@ -752,13 +754,13 @@
model->camera->setDepthRange();
- OpenGLErrorChek::chek("beforerrr");
+
glEnable (GL_DEPTH_TEST);
glViewport(0,vpY, vpW, vpH);
glBindFramebuffer(GL_FRAMEBUFFER, sampleFramebuffer);
/// glBindFramebuffer(GL_FRAMEBUFFER,fboDepth);
- // glClearColor(0.0, 0.0, 0.0, 0.0);
+ glClearColor(0.0, 1.0, 0.0,1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
@@ -767,6 +769,7 @@
glUniformMatrix4fv(uWorldMatrixDepth, 1,0, camera->worldMatrix.getPtr());
glUniformMatrix4fv(uPerspectiveMatrixDepth, 1, 0, camera->perspectiveMatrix.getPtr());
+ glUniformMatrix4fv(uNormalMatrixDepth, 1, 0, camera->normalMatrix.getPtr());
glUniform1f(uMinDepth, model->camera->minDepth);
glUniform1f(uDepthRange,- model->camera->depthRange);
@@ -776,6 +779,11 @@
glEnableVertexAttribArray(ATTRIB_VERTEX);
glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 12,(GLvoid*) (sizeof(float) * 0));
+ glEnableVertexAttribArray(ATTRIB_NORMAL);
+ glVertexAttribPointer(ATTRIB_NORMAL, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 12,(GLvoid*) (sizeof(float) * 3));
+
+
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,indexBuffer);
glDrawElements(GL_TRIANGLES, 36* cubeHandler->cubes.size(), GL_UNSIGNED_SHORT, (void*)0);
@@ -831,8 +839,8 @@
glDrawArrays(GL_TRIANGLES, 0, 6);
-
-
+ glClearColor(0.0, 0.0, 0.0, 0.0);
+ return;
glBindFramebuffer(GL_FRAMEBUFFER, fboBlur2);
@@ -7,42 +7,101 @@
//
-varying mediump vec3 uvVarying;
+varying mediump vec2 uvVarying;
uniform sampler2D texture;
- mediump vec2 pos;
-
- mediump vec4 tempColor;
+const highp float totStrength = 1.38;
+const highp float strength = 2.8;
+const highp float offset = 30.0;
+const highp float falloff = 0.1;
+const highp float rad = 0.02;
+
+const highp float invSamples = 1.0/20.0;
+
void main()
{
-
- mediump vec4 sourceColor = texture2D(texture, uvVarying.xy);
+
+ mediump vec4 sourceColor = texture2D(texture, uvVarying);
+ highp vec3 pSphere[30];
- mediump float blurColor =0.0 ;
+ pSphere[0] = vec3(-0.010735935, 0.01647018, 0.0062425877);
+ pSphere[1] = vec3(-0.06533369, 0.3647007, -0.13746321);
+ pSphere[2] = vec3(-0.6539235, -0.016726388, -0.53000957);
+ pSphere[3] = vec3(0.40958285, 0.0052428036, -0.5591124);
+ pSphere[4] = vec3(-0.1465366, 0.09899267, 0.15571679);
+ pSphere[5] = vec3(-0.44122112, -0.5458797, 0.04912532);
+ pSphere[6] = vec3(0.03755566, -0.10961345, -0.33040273);
+ pSphere[7] =vec3(0.019100213, 0.29652783, 0.066237666);
+ pSphere[8] =vec3(0.8765323, 0.011236004, 0.28265962);
+ pSphere[9] =vec3(0.29264435, -0.40794238, 0.15964167);
- mediump vec2 temp = uvVarying.xy;
-
+ pSphere[10] = vec3(0.010735935, 0.01647018, 0.0062425877);
+ pSphere[11] = vec3(0.06533369, 0.3647007, -0.13746321);
+ pSphere[12] = vec3(0.6539235, -0.016726388, -0.53000957);
+ pSphere[13] = vec3(-0.40958285, 0.0052428036, -0.5591124);
+ pSphere[14] = vec3(0.1465366, 0.09899267, 0.15571679);
+ pSphere[15] = vec3(0.44122112, -0.5458797, 0.04912532);
+ pSphere[16] = vec3(-0.03755566, -0.10961345, -0.33040273);
+ pSphere[17] =vec3(-0.019100213, 0.29652783, 0.066237666);
+ pSphere[18] =vec3(-0.8765323, 0.011236004, 0.28265962);
+ pSphere[19] =vec3(-0.29264435, -0.40794238, 0.15964167);
- for (mediump float i =-10.0;i<10.0;i++)
- {
-
-
- pos = vec2(temp.x +(i*0.002),temp.y) ;
- tempColor =texture2D(texture,pos );
-
- blurColor += tempColor.x*0.05;
-
- }
-
+ /*
+ pSphere[20] = vec3(-0.010735935, 0.01647018, -0.0062425877);
+ pSphere[21] = vec3(-0.06533369, 0.3647007, 0.13746321);
+ pSphere[22] = vec3(-0.6539235, -0.016726388, 0.53000957);
+ pSphere[23] = vec3(0.40958285, 0.0052428036, 0.5591124);
+ pSphere[24] = vec3(-0.1465366, 0.09899267, -0.15571679);
+ pSphere[25] = vec3(-0.44122112, -0.5458797, -0.04912532);
+ pSphere[26] = vec3(0.03755566, -0.10961345, 0.33040273);
+ pSphere[27] =vec3(0.019100213, 0.29652783, -0.066237666);
+ pSphere[28] =vec3(0.8765323, 0.011236004, -0.28265962);
+ pSphere[29] =vec3(0.29264435, -0.40794238, -0.15964167);
+ */
+ //highp vec3 fres = normalize((texture2D(rnm,uv*offset).xyz*2.0) - vec3(1.0));
+ highp vec3 fres = vec3(0.0,0.0,1.0);//make random
+ highp vec4 currentPixelSample = texture2D(texture,uvVarying);
- gl_FragColor =vec4 ( blurColor, sourceColor.y, 0.0 ,sourceColor.a);
-
-
-
+ highp float currentPixelDepth =1.0- currentPixelSample.a;
+
+ // current fragment coords in screen space
+ highp vec3 ep = vec3(uvVarying,currentPixelDepth);
+ // get the normal of current fragment
+ highp vec3 norm = currentPixelSample.xyz;
+
+ highp float bl = 0.0;
+ // adjust for the depth ( not shure if this is good..)
+ highp float radD = rad/currentPixelDepth;
+
+ //vec3 ray, se, occNorm;
+ highp float occluderDepth;
+ highp float depthDifference;
+ highp vec4 occluderFragment;
+ highp vec3 ray;
+
+
+
+ for(int i=0; i<20;++i)
+ {
+ // get a vector (randomized inside of a sphere with radius 1.0) from a texture and reflect it
+ ray = radD*reflect(pSphere[i],fres);
+
+ // get the depth of the occluder fragment
+ occluderFragment = texture2D(texture ,ep.xy + sign(dot(ray,norm) )*ray.xy);
+ // if depthDifference is negative = occluder is behind current fragment
+ depthDifference = currentPixelDepth-(1.0-occluderFragment.a);
+
+ // calculate the difference between the normals as a weight
+ // the falloff equation, starts at falloff and is kind of 1/x^2 falling
+ bl += step(falloff,depthDifference)*(1.0-dot(occluderFragment.xyz,norm))*(1.0-smoothstep(falloff,strength,depthDifference));
+ }
+
+ // output the result
+ gl_FragColor =vec4(0.0,0.0,0.0,bl*invSamples);
}
@@ -11,7 +11,7 @@ attribute vec3 uv;
uniform mat4 worldMatrix;
-varying vec3 uvVarying;
+varying vec2 uvVarying;
@@ -21,7 +21,4 @@ void main()
gl_Position =worldMatrix*position;
uvVarying.x=uv.x;
uvVarying.y=1.0-uv.y;
-
-
-
-}
+ }
@@ -9,7 +9,7 @@
-varying mediump vec3 colorVarying;
+varying mediump vec4 colorVarying;
void main()
@@ -18,7 +18,7 @@ void main()
- gl_FragColor = vec4(colorVarying,1.0);
+ gl_FragColor = colorVarying;
@@ -7,12 +7,17 @@
//
attribute vec4 position;
+attribute vec4 normal;
+
+
+uniform mat4 normalMatrix;
uniform mat4 worldMatrix;
uniform mat4 perspectiveMatrix;
uniform float minDepth;
uniform float depthRange;
-varying vec3 colorVarying;
+
+varying vec4 colorVarying;
void main()
{
@@ -24,11 +29,12 @@ void main()
vec4 worldSpace = worldMatrix*position;
gl_Position =perspectiveMatrix*worldSpace;
+ vec4 N = normalMatrix *normal;
float d = 1.0-(worldSpace.z+minDepth )/depthRange;
-
+
- colorVarying = vec3(d,d,d);
+ colorVarying = vec4(N.xyz,d);
}
@@ -8,49 +8,16 @@
-varying mediump vec3 normalVarying;
-varying lowp vec3 colorVarying;
-varying highp vec3 lightDir;
-varying highp vec3 lightDir2;
-varying highp vec3 eyeVec;
+varying lowp vec4 colorVarying;
+
void main()
{
- highp float lambertTerm = abs(dot(lightDir,normalVarying ))*0.4+clamp(dot(lightDir2,normalVarying ),0.0,1.0)*0.9;
-
- lambertTerm +=1.0;
- lambertTerm *=0.5;
- gl_FragColor =vec4(colorVarying*clamp(lambertTerm,0.0,1.0),1.0);
-
-
- highp vec3 R = reflect(-lightDir2, normalVarying );
- highp float p =max(dot( eyeVec,R ), 0.0);
- highp float specular = pow (p,20.0);
- gl_FragColor+=specular*0.2;
-
- /*
-
- highp float lambertTerm = clamp(dot(lightDir,normalVarying ),0.0,1.0)*0.8+clamp(dot(lightDir2,normalVarying ),0.0,1.0)*0.4;
-
-
-
- highp vec3 R = reflect(-lightDir, normalVarying );
- highp float p =max(dot( eyeVec,R ), 0.0);
- highp float specular = pow (p,4.0);
-
-
- highp vec3 R2 = reflect(-lightDir2, normalVarying );
- highp float p2 =max(dot( eyeVec,R2 ), 0.0);
- highp float specular2 = pow (p2,4.0);
-
-
- lambertTerm =clamp(lambertTerm,0.0,1.0)*0.65+0.35;
-
- gl_FragColor =vec4(colorVarying*lambertTerm,1.0);
+
+ gl_FragColor =colorVarying;
- gl_FragColor+=specular*0.2+specular2*0.3;
+
- */
}
Oops, something went wrong.

0 comments on commit bb47e1f

Please sign in to comment.