Results 1 to 5 of 5

Thread: Adding 2 vectors & normalizing result in RegCombiners using nvparse

  1. #1
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    2,833

    Adding 2 vectors & normalizing result in RegCombiners using nvparse

    I'm using a geforce3. Bear in mind I'm pretty new to nvparse (and its odd syntax).
    I have an animated 'normal' texture (tex1), and a static 'normal' texture (tex2).
    In the register combiners, I want to add a normal from tex1 to tex2, and normalise the result - then dot product this vector with the light vector (col0).
    I'm getting 'white-out' when I try this:-

    nvparse(
    "!!RC1.0 \n"
    // add normal from animated texture (tex1) onto normal from static texture (tex2)
    "{ \n"
    " rgb { \n"
    " discard = expand(tex1); \n"
    " discard = expand(tex2); \n"
    " spare0 = sum(); \n"
    " } \n"
    "} \n"

    // normalise this vector
    "{ \n"
    " rgb { \n"
    " spare1 = spare0 . spare0; \n"
    " } \n"
    "} \n"
    "{ \n"
    " rgb { \n"
    " discard = spare0; \n"
    " discard = half_bias(spare0) * unsigned_invert(spare1); \n"
    " spare0 = sum(); \n"
    " } \n"
    "} \n"

    // dot product the normalised vector with the light vector
    "{ \n"
    " rgb { \n"
    " spare1 = spare0 . expand(col0); \n"
    " } \n"
    "} \n"

    // output the dot product result directly, for testing purposes
    "out.rgb = spare1; \n"
    "out.a = unsigned_invert(zero); \n" );
    Knackered

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    San Diego, CA, USA
    Posts
    604

    Re: Adding 2 vectors & normalizing result in RegCombiners using nvparse

    Just a guess, but I think that things in register combiners are always clamped to
    [-1,1] so maybe when you add your two normals it is getting truncated.

    Try multiplying each normalmap normal by 0.5 before summing them. You could do this either by pre-multiplying the normal maps or using register combiner constants.

    -- Zeno

  3. #3
    Member Newbie
    Join Date
    May 2001
    Location
    Warsaw Poland
    Posts
    39

    Re: Adding 2 vectors & normalizing result in RegCombiners using nvparse

    I think your error comes from the fact the second normalization stage expects spare0 to be unexpanded (so that half_bias(spare0) effect is expanding and multiplying by 0.5)

    try this:

    combiner #0:
    change both expand to half_bias
    (this will do what Zeno suggested)

    combiner #2:
    discard = signed_identity(spare0)
    discard = signed_identity(spare0) * half_bias_negate(spare1)
    pare0 = sum()

    tested only on paper (i use different equotation)

  4. #4
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    2,833

    Re: Adding 2 vectors & normalizing result in RegCombiners using nvparse

    Damn, I forgot that values are clamped to (-1,1) within the combiners! I remember now, from when I used the reg combiner function calls directly....
    Why are they clamped even within a general stage? I can understand them having to be clamped before being outputed to the next stage...
    Also, why the strange syntax for addition? why can't we just write "spare0 = expand(tex1) + expand(tex2)" ?
    I'll try out your suggestions when I get back to my code...thanks for the replies chaps!
    Knackered

  5. #5
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    2,833

    Re: Adding 2 vectors & normalizing result in RegCombiners using nvparse

    Carmacksutra, I don't know if you were using psuedo code there, but if you were not, then there are no keywords (or equivelents) like "signed_identity" or "half_bias_negate" when using nvparse.
    I've got round this though, and it works rather nicely now. Thanks for all the help.
    Knackered

Similar Threads

  1. Replies: 4
    Last Post: 11-14-2009, 11:49 PM
  2. Adding yaw and pitch of two vectors?
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-17-2004, 10:04 AM
  3. Light position normalizing
    By Javac in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-14-2003, 11:49 AM
  4. Replies: 1
    Last Post: 06-23-2003, 04:48 AM
  5. Normalizing a Matrix
    By Fernando in forum OpenGL: Basic Coding
    Replies: 12
    Last Post: 06-07-2002, 08:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean