Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: nv25 highlights

  1. #1
    Intern Newbie
    Join Date
    Nov 2002
    Location
    Denmark
    Posts
    48

    nv25 highlights

    Hi.

    I am trying to implement a simple phong model with a gf4.

    The diffuse part of it is working fine.

    However, I'm having some problems getting the specular part to work.

    My initial idea was to do it like this

    unit 1: normalize H
    unit 2: lookup normal from bumpmap
    unit 3: Exponentiate via a dot3(unit 1, unit 2) and an exponent texture.

    So, when i looked at it, DOT_PRODUCT_TEXTURE_1D, seemed like the thing to use, but now it appears that the input to one side of the dot product must be the coordinates bound to the unit.

    Is it possible to do dot(normalize(H),bumpnormal), and use it to lookup in a texture?
    If, can anyone hint me what to use?

    I am using Cg, not that it seems to simplify matters, at least in this case.

    Jonas

  2. #2
    Junior Member Newbie
    Join Date
    Nov 2002
    Location
    UK
    Posts
    17

    Re: nv25 highlights

    <pimpage>
    I'm writing a chapter in ShaderX2 that is related to this subject
    (albeit in DirectX)
    It also deals with doing per-pixel specular power maps for ps.1.1 level hardware.
    </pimpage>

    The technique I present in the chapter constructs a 'light space' matrix that has it's y axis aligned with the half vector, with the other 2 axes forming an orthonormal basis (they are also consistently interpolatable). The per-pixel normal can then be transformed from tangent space into light space using the equivalent of the DirectX texm3x3tex instruction (with 2 texm3x3pad instructions). The cube map that is looked up has a specular highlight in the +ve y direction. The specular highlight can be of any specular power though as it's just a texture.

    This means that you get a normalised (due to cube map lookup), arbitrarily high exponent specular bump mapping pass with no banding artifacts (you don't use arithmetic instructions to do the exponentiation).

    If you don't need the half vector to be normalised, then just use what you suggested. If you do want it normalised, but don't want to do the light space cube map stuff, then you'll have to raise to a power using arithmetic instructions. This'll probably give you banding for high exponent values.

    HTH

    Matt Halpin

  3. #3
    Intern Newbie
    Join Date
    Nov 2002
    Location
    Denmark
    Posts
    48

    Re: nv25 highlights

    I dont quite get it.
    at least not all of it.

    The technique I present in the chapter constructs a 'light space' matrix that has it's y axis aligned with the half vector, with the other 2 axes forming an orthonormal basis (they are also consistently interpolatable). The per-pixel normal can then be transformed from tangent space into light space using the equivalent of the DirectX texm3x3tex instruction (with 2 texm3x3pad instructions). The cube map that is looked up has a specular highlight in the +ve y direction. The specular highlight can be of any specular power though as it's just a texture.
    So is the point that you are only using one of the cubemap faces, and abuse the lookup method for cubemaps?
    I dont quite get it, any chance you could elaborate a bit more?
    How do you construct the two orthogonal axes?

    guess I have to think it over a bit more.

    Jonas

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: nv25 highlights

    Try turning on GL_NORMAL_MAP texgen on one unit and binding that to your diffuse solution (potentially, use the texture coordinate matrix to collapse to a 1D look-up texture) and GL_REFLECTION_MAP texgen on one unit and binding that to your specular solution (same thing there with collapsing 3D texture coordinate to 1D texture).

    You'll need to modulate with color in a separate pass if you only have two units. If you have three or more, you can do diffuse color on the first unit, modulate with diffuse light in the second, and add specular light in the third.

    Note that REFLECTION_MAP and the half-angle vector behave slightly differently (WRT compression in the eye-to-light axis) but you can usually make up for this in your cube map.
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  5. #5
    Intern Newbie
    Join Date
    Nov 2002
    Location
    Denmark
    Posts
    48

    Re: nv25 highlights

    jwatte:

    I dont quite get what you mean.

    I need to exponentiate the result of dot(normalize(half),bumpnormal), to get the specular part....
    in the fragment program, that is.

    Jonas

    [This message has been edited by jonasmr (edited 05-02-2003).]

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: nv25 highlights

    jonas,

    Bind a pre-exponentiated cube map to the texture target which you map as REFLECTION_MAP.

    If you need per-pixel exponentiation, then it won't work, of course.
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  7. #7
    Intern Newbie
    Join Date
    Nov 2002
    Location
    Denmark
    Posts
    48

    Re: nv25 highlights

    Originally posted by jwatte:
    jonas,

    If you need per-pixel exponentiation, then it won't work, of course.
    I wanted perpixel..
    all this trouble for this silly card.



    thanks, Jonas

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: nv25 highlights

    I was fuzzy.

    My suggestion computes per-pixel lighting, and exponentiates per pixel. The only quantity you do not get per pixel is an exponent MAP, i e, where the exponent is "12" for one pixel, but "36" for the pixel between it (i e, difference in shinyness encoded in a map).

    In fact, it seems you don't have enough dependent reads or general combiners on a GF4 to do per-pixel exponent. It's of course simple using ARB_fragment_shader ;-)
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  9. #9
    Intern Newbie
    Join Date
    Nov 2002
    Location
    Denmark
    Posts
    48

    Re: nv25 highlights

    Okay, I dont get it then

    What is the diffuse solution/specular solution?

    How does the reflection map create the specular highlight?.

    I just dont get it.. maybe I'm missing something fundamentally, but perhaps you could point direct me to some samples using the technique.. if they exist, that is.

    Jonas

  10. #10
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: nv25 highlights

    I put this in our engine at work for a prototype, when we played around with different lighting models. Can't show you that ;-)

    Specular highlights are, basically, just the light reflecting in the surface. Thus, if you paint a cube map with a round white fuzzy dot in the middle of one section, and rotate this cube map such that the dot is where the light should be, relative to the object, then REFLECTION_MAP will give you specular lighting onto the object.

    Same thing for diffuse, except the cube map should be rather more white (and half black).

    Once you've gotten this to work, if all you use is round dots, then you can use the texture matrix to collapse the cube map coordinates onto a 1D texture, orienting the matrix to point the "light" direction along the "s" coordinate in texture space. At that point, the "s" value is basically "cos phi" in the lighting equation, and you can put in whatever value you want in each texel, for what you want your lighting to be at that angle.
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •