Author Topic: little 3d cube with bumpmapping.  (Read 5697 times)

0 Members and 1 Guest are viewing this topic.

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1289
  • Karma: 466
    • View Profile
    • my stuff
Re: little 3d cube with bumpmapping.
« Reply #20 on: May 27, 2013 »
an exe of your code that just does interpolated lightdir as rgb?
You can do that yourself, just change the last line in "data/spherefragments-frag.glsl" to:
Code: [Select]
gl_FragColor = vec4(nLightDir*0.5+0.5, 1.0);Ooops, I copied the normalmap-stuff from a different project and didn't even change the filename ;)

Since the interpolated light direction is in normalmap space, the resulting rgbs are probably hard to figure out.
So if you want to display other values, you can easily pass them to the rasterizer the following way:

At the top of the vertex shader (-vert.glsl) add another "varying" variable (those get interpolated and passed to the fragment shader):
Code: [Select]
varying vec4 test;And fill it with something interesting in the main:
Code: [Select]
test= normalize( (gl_ModelViewMatrix * gl_Vertex) - lightPosition );(that's the light direction in world space)

At the top of the fragment shader (-frag.glsl) add the same varying variable:
Code: [Select]
varying vec4 test;And write it into the color output:
Code: [Select]
gl_FragColor = test*0.5+0.5;
« Last Edit: May 27, 2013 by hellfire »
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1666
  • Karma: 133
    • View Profile
Re: little 3d cube with bumpmapping.
« Reply #21 on: May 27, 2013 »
ahh i never noticed the 2 shader files in there top stuff, i thought they had been build into the exe.

checking the interpolated color, im extreamly close too what you have there :).
thanks too everything you've posted over the last two normal mapping threads. me and everyone else now has a complete 101 on bumpmapping!! ill post the software version as soon as ive added the specular,

cheers mate!
« Last Edit: May 27, 2013 by ninogenio »
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1666
  • Karma: 133
    • View Profile
Re: little 3d cube with bumpmapping.
« Reply #22 on: May 27, 2013 »
well after a few hours of head scratching tonight and playing around.
i think i finally have the diffuse component correct  :). there is probably still a few things not quite right but its close.

does opengl perspective correct the direction interpolation. im wondering if im possibly losing a bit of precision because im just affine mapping them atm.
« Last Edit: May 27, 2013 by ninogenio »
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1289
  • Karma: 466
    • View Profile
    • my stuff
Re: little 3d cube with bumpmapping.
« Reply #23 on: May 27, 2013 »
Looks nice and seems correct to me.
All vertex attributes are interpolated perspectively correct by the GPU.
In the times of Voodoo1 rgba was interpolated linearly across the polygon, don't know when exactly they scrapped that.
At this scale I doubt it makes much of a difference for the interpolated vectors, though.
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1666
  • Karma: 133
    • View Profile
Re: little 3d cube with bumpmapping.
« Reply #24 on: May 28, 2013 »
thanks hellfire,

you were right it wasnt really interpolation issues, my surface normals were not aligning properly with the faces of the cube so as it rotated the started pointing in the wrong directions, when i added specular it really showed this up bad.

ive fixed that and added specular highlights i think it looks pretty cool now  :).

also got rid of lots of the commented out code inside. and incorporated the specular and diffuse into the triangle routine for a bit of a speed bump. some of the dark areas get specular atm but thats just down too dist att i think its quite a trivial thing.

again thanks 10000% mate!!
« Last Edit: May 28, 2013 by ninogenio »
Challenge Trophies Won: