Login  Register

Re: JOGL 2 - BumpMap with Shader

Posted by Sven Gothel on Nov 12, 2012; 7:54pm
URL: https://forum.jogamp.org/JOGL-2-BumpMap-with-Shader-tp4026889p4026901.html

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
If your above list of CPU side actions (read: Java code statements) is complete,
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