Hi,
I have implemented with success with success the BumpMap Dot3 with vertex, calculating TBN with CPU... Now I'm trying to implement the bumpMap effect with Shader. I have weird results. Looks like I displayed only normalMap... Here is my Vertex Shader: varying vec3 LightDir; varying vec3 EyeDir; uniform vec3 LightPosition; attribute vec3 Tangent; void main() { EyeDir = vec3(gl_ModelViewMatrix * gl_Vertex); gl_Position = ftransform(); gl_TexCoord[0] = gl_MultiTexCoord0; vec3 n = normalize(gl_NormalMatrix * gl_Normal); vec3 t = normalize(gl_NormalMatrix * Tangent); vec3 b = cross(n, t); vec3 v; v.x = dot(LightPosition, t); v.y = dot(LightPosition, b); v.z = dot(LightPosition, n); LightDir = normalize(v); v.x = dot(EyeDir, t); v.y = dot(EyeDir, b); v.z = dot(EyeDir, n); EyeDir = normalize(v); } My Fragment Shader varying vec3 LightDir; varying vec3 EyeDir; uniform vec3 SurfaceColor; // = (0.7, 0.6, 0.18) uniform float BumpDensity; // = 16.0 uniform float BumpSize; // = 0.15 uniform float SpecularFactor; // = 0.5 void main() { vec3 litColor; vec2 c = BumpDensity * gl_TexCoord[0].st; vec2 p = fract(c) - vec2(0.5); float d, f; d = p.x * p.x + p.y * p.y; f = 1.0 / sqrt(d + 1.0); if (d >= BumpSize) { p = vec2(0.0); f = 1.0; } vec3 normDelta = vec3(p.x, p.y, 1.0) * f; litColor = SurfaceColor * max(dot(normDelta, LightDir), 0.0); vec3 reflectDir = reflect(LightDir, normDelta); float spec = max(dot(EyeDir, reflectDir), 0.0); spec = pow(spec, 6.0) spec *= SpecularFactor; litColor = min(litColor + spec, vec3(1.0)); gl_FragColor = vec4(litColor, 1.0); } When I draw my scene : 1 - enable shader 2 - bind the texture 3 - bind the normalMap 4 - glUniform1i(texture_location, 0) 5 - glUniform1i(normalMap_location, 1) 6 - draw my VBO 7 - disable shader Any ideas where I'm wrong ? |
Administrator
|
Hi
A similar feature is implemented in JMonkeyEngine 3.0, I ported its renderer to JOGL 2.0 some weeks ago, maybe you should have a look at it. Are you sure you use valid locations? Don't forget to avoid putting "\0" when trying to retrieve the location of an attribute or a uniform.
Julien Gouesse | Personal blog | Website
|
What do you means with valid location ?
Here is my cod to draw : gl.glPushMatrix(); gl.glTranslated(4f, 0f, 0f); mesh.getShader().enabled(); gl.glActiveTexture(GL2.GL_TEXTURE1); normalMap.bind(); // Specify that our texture normalMap_location, is on texture unit 1 gl.glUniform1i(normalMap_location, 1); gl.glActiveTexture(GL2.GL_TEXTURE0); texture.bind(); // Specify that our texture texture_location, is on texture unit 0 gl.glUniform1i(texture_location, 0); drawObject(); mesh.getShader().disabled(); gl.glPopMatrix(); There my init : this.texture_location = gl.glGetUniformLocation(mesh.getShader() .getShaderProgramID(), "tex"); this.normalMap_location = gl.glGetUniformLocation(mesh.getShader() .getShaderProgramID(), "normalMap"); My Texture are com.jogamp.opengl.util.texture.Texture |
Administrator
|
Does glGetUniformLocation return something greater than -1?
Julien Gouesse | Personal blog | Website
|
Yes texture = 0
normalMap = 1 |
Administrator
|
In reply to this post by greatdonking
On 11/12/2012 04:32 PM, GreatDonKing [via jogamp] wrote:
> Hi, > I have implemented with success with success the BumpMap Dot3 with vertex, > calculating TBN with CPU... > > Now I'm trying to implement the bumpMap effect with Shader. I have weird results. > Looks like I displayed only normalMap... If you would like to add a little demo to our unit tests / demos inside JOGL (so we can test and see) - I would like to look at it. In the meantime, you may want to look at GearsES2's shader, gears.vp/fp in our JOGL src/test/.. tree. It uses a normal map for vertex lighting, not a height map for amplification though. Maybe it helps a bit. .. more below. > > Here is my Vertex Shader: > varying vec3 LightDir; > varying vec3 EyeDir; > > uniform vec3 LightPosition; > > attribute vec3 Tangent; > > void main() > { > EyeDir = vec3(gl_ModelViewMatrix * gl_Vertex); > gl_Position = ftransform(); > gl_TexCoord[0] = gl_MultiTexCoord0; > > vec3 n = normalize(gl_NormalMatrix * gl_Normal); > vec3 t = normalize(gl_NormalMatrix * Tangent); > vec3 b = cross(n, t); > > vec3 v; > v.x = dot(LightPosition, t); > v.y = dot(LightPosition, b); > v.z = dot(LightPosition, n); > LightDir = normalize(v); > > v.x = dot(EyeDir, t); > v.y = dot(EyeDir, b); > v.z = dot(EyeDir, n); > EyeDir = normalize(v); > } > > My Fragment Shader > varying vec3 LightDir; > varying vec3 EyeDir; > > uniform vec3 SurfaceColor; // = (0.7, 0.6, 0.18) > uniform float BumpDensity; // = 16.0 > > uniform float BumpSize; // = 0.15 > uniform float SpecularFactor; // = 0.5 > > void main() > { > vec3 litColor; > vec2 c = BumpDensity * gl_TexCoord[0].st; > vec2 p = fract(c) - vec2(0.5); > > float d, f; > d = p.x * p.x + p.y * p.y; > f = 1.0 / sqrt(d + 1.0); > > if (d >= BumpSize) > { p = vec2(0.0); f = 1.0; } > > vec3 normDelta = vec3(p.x, p.y, 1.0) * f; > litColor = SurfaceColor * max(dot(normDelta, LightDir), 0.0); > vec3 reflectDir = reflect(LightDir, normDelta); > > float spec = max(dot(EyeDir, reflectDir), 0.0); > spec = pow(spec, 6.0) > spec *= SpecularFactor; > litColor = min(litColor + spec, vec3(1.0)); > > gl_FragColor = vec4(litColor, 1.0); > } > > When I draw my scene : > 1 - enable shader > 2 - bind the texture > 3 - bind the normalMap > 4 - glUniform1i(texture_location, 0) > 5 - glUniform1i(normalMap_location, 1) > 6 - draw my VBO > 7 - disable shader it surely doesn't match your shader code (uniforms, ..). Please look at GearsES2 .. and make sure all attributes / uniforms are being set by the CPU side w/ right type! Would be best to make a small unit test out of it like GearsES2 and contribute to our JOGL unit test. ~Sven > > Any ideas where I'm wrong ? signature.asc (907 bytes) Download Attachment |
Could you please give the complete link ?
I will study this example :) |
Administrator
|
On 11/12/2012 10:29 PM, greatdonking [via jogamp] wrote:
> Could you please give the complete link ? > I will study this example :) > This is Xerxes ES2 demo, only using standard OpenGL calls: <http://jogamp.org/git/?p=jogl-demos.git;a=blob;f=src/demos/es2/RawGL2ES2demo.java;hb=HEAD> (Not normal/height mapping related, but for you to see how to map uniform/attributes w/o using further JOGL utilities) GearsES2 is a bit more complex, and it's Java code uses JOGL GLSL utils for easy coding: <http://jogamp.org/git/?p=jogl.git;a=blob;f=src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java;hb=HEAD> You can find the shader source code here: <http://jogamp.org/git/?p=jogl.git;a=tree;f=src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader;hb=HEAD> So it's all in our git repos .. ~Sven signature.asc (907 bytes) Download Attachment |
I will update my jars with the latest ones.
I used GL2 in my project, what is your recommendation ? |
Administrator
|
Just use the most fitted profile for your project.
Julien Gouesse | Personal blog | Website
|
I use GL2 but what about GL3 or GLE2ES2 ?
|
This post was updated on .
2012-11-13 14:56, greatdonking [via jogamp] skrev:
> I use GL2 but what about GL3 or GL2ES2 ? > Using NEWT (GLWindow) and GL2ES2 profile will make you application most portable across devices, JogAmp uses the GL2ES2 profile for all the applet and JNLP webstart demos. Application using GL2ES2 will work on traditional OpenGL GL2 desktop, ARM Linux GL ES 2 desktop, MeeGo GL ES 2 mobile, Android GL ES 2 mobile and tablets. |
Free forum by Nabble | Edit this page |