Illumination "sticking" to the object?

Discussion in 'Rendering Technology and APIs' started by VFX_Veteran, Oct 13, 2003.

  1. Humus

    Humus Crazy coder
    Veteran

    Joined:
    Feb 6, 2002
    Messages:
    3,217
    Likes Received:
    77
    Location:
    Stockholm, Sweden
    Re: Problem solved: HLSL not very intuitive.

    Just checked and it seems the inverse transpose of the view matrix isn't exposed as a standard variable in RenderMonkey, though it should be possible to just transpose inv_view_matrix. But simply using the view_matrix should work in most cases too.
     
  2. Humus

    Humus Crazy coder
    Veteran

    Joined:
    Feb 6, 2002
    Messages:
    3,217
    Likes Received:
    77
    Location:
    Stockholm, Sweden
    That's the "view-projection matrix", that is the view and projection matrix concatenated, and often called the mvp matrix.

    mvp = projection * view;

    transformed vertex is then

    tPos = mvp * inPos = projection * view * inPos

    so the vertex is first transformed by the view matrix, then by the projection matrix.
     
  3. Humus

    Humus Crazy coder
    Veteran

    Joined:
    Feb 6, 2002
    Messages:
    3,217
    Likes Received:
    77
    Location:
    Stockholm, Sweden
    The variables you see in RenderMonkey are RenderMonkey specific. The app provides those for you. The HLSL itself doesn't defined any variabled (AFAIK anyway).


    [/end of posting spree] ;)
     
  4. VFX_Veteran

    Regular

    Joined:
    Mar 9, 2002
    Messages:
    683
    Likes Received:
    234
    Re: Problem solved: HLSL not very intuitive.

    Ok, I'll try.

    When you look at those models in the viewer and rotate the models around, the only thing that is moving with respect to the lights is the specular highlight (which it's supposed to). This is correct, however, if you turn off the specular highlight, your diffuse does not follow the direction of the lights and is therefore not correct diffuse illumination (in my book).

    I'm going to continue implementing my Spline Reflection shader and it will have full diffuse illumination (that changes when the object rotates where a set of lights have been placed in the world) as well as specular illumination with respect to the viewer. I'll post my results here as soon as I'm finished..

    I've got a few more small but very conveted shaders to implement too.:) Hopefully they won't breach any NDAs and hopefully they will work..

    -M
     
  5. VFX_Veteran

    Regular

    Joined:
    Mar 9, 2002
    Messages:
    683
    Likes Received:
    234
    Re: Problem solved: HLSL not very intuitive.

    But this method becomes wrong when you don't have high grazing angles on the model. If, for example, the light is hitting the object straight on and the angle between the normal and light vector are close to zero, you get way more illumination than what you'd want.

    The best way to make a softer diffuse and control it's "roughness" is to raise NdotL to a power (just as you do with Phong or Blinn).


    -M
     
  6. darkblu

    Veteran

    Joined:
    Feb 7, 2002
    Messages:
    2,642
    Likes Received:
    22
    Re: Problem solved: HLSL not very intuitive.

    whenever the transform is ortho-normal, than is.
     
  7. mrbill

    Newcomer

    Joined:
    Feb 24, 2003
    Messages:
    36
    Likes Received:
    1
    Location:
    Marlborough, MA
    Re: Problem solved: HLSL not very intuitive.

    Two points.

    First, premultiplied light color and material color is a somewhat common case in the real-time world. ARB_vertex|fragment_program and ARB_vertex|fragment_shader (the OpenGL Shading Language) include builtin state bindings to the light color & material color products. So, maybe a bit more intuitive. (Maybe not.)

    Second, the example should be taken more generally. Particularly since the material properties often won't be uniform across a surface anyway.

    Even if you don't care about performance, I'm guessing you will care about making your shader fit. With HLSL the shader either fits, or it doesn't fit. If it doesn't fit, it doesn't run. You can break your shader into multiple passes, or you look for ways to squeeze a few instructions off your shader by pre-multiplying some values. Your choice, either (or more likely, both) will make for slightly more awkward shaders, but the tradeoff may be worth it so you can play with far more complex shaders.

    You can multiply by a transposed matrix easily:

    Code:
    // Transform position and normal from object to view
    float4 transformedPosition = mul( view_matrix, position );   // float4x4 x float4
    float3 transformedNormal   = mul( normal, inv_view_matrix ); // float4 x float4x4, note the transpose
    -mr. bill

    edit: Fixed HLSL example slightly (OpenGL Shading Language creeped in, sorry)
     
  8. VFX_Veteran

    Regular

    Joined:
    Mar 9, 2002
    Messages:
    683
    Likes Received:
    234
    Re: Problem solved: HLSL not very intuitive.

    Ooops.. Is your equation a multiply? I thought it was a cross-product since you stated it with an 'x' instead of an '*'. In that case, it makes perfect sense!:)

    Well, I'm really only fiddling with this at home. Once you guys work with Microsoft for a more expanded language, and we start to use it here, then I guess we can come back to optimizations. As it stands, I'll try to knock down a few lines of code, but I won't stress over it if the shader doesn't work.


    -M
     
  9. mrbill

    Newcomer

    Joined:
    Feb 24, 2003
    Messages:
    36
    Likes Received:
    1
    Location:
    Marlborough, MA
    Re: Problem solved: HLSL not very intuitive.

    Nah. Cross-product would be "^", dot product would be "." Ooops, wrong shading language again.

    -mr. bill
     
  10. Humus

    Humus Crazy coder
    Veteran

    Joined:
    Feb 6, 2002
    Messages:
    3,217
    Likes Received:
    77
    Location:
    Stockholm, Sweden
    Re: Problem solved: HLSL not very intuitive.

    You do realize that you rotate your viewpoint only, while the model is fixed in its position and orientation? The camera goes around, not the model.
     
  11. Humus

    Humus Crazy coder
    Veteran

    Joined:
    Feb 6, 2002
    Messages:
    3,217
    Likes Received:
    77
    Location:
    Stockholm, Sweden
    Re: Problem solved: HLSL not very intuitive.

    "Wrong" and "right" depends on your intensions. The only rule in graphics is that "if it looks good, then it is good". In some scenes Half-Lambert looks good, so it can be just about right for those. In other scenes you may want something else. Phong and Blinn aren't so much "right" either, it's just approximations too. The softness is just that the backside doesn't become completely black. You get some lighting on the backside of the model too. This way you may not need any ambient. Ambient which is also a very rude approximationg of global illumination, and may be called "wrong", but it does look very good in relation to its very cheap cost.
     
  12. VFX_Veteran

    Regular

    Joined:
    Mar 9, 2002
    Messages:
    683
    Likes Received:
    234
    Re: Problem solved: HLSL not very intuitive.

    The meaning should be the same though. Rotating or translating the camera around an object should be equivalent to moving the object or rotating it.

    -M
     
  13. VFX_Veteran

    Regular

    Joined:
    Mar 9, 2002
    Messages:
    683
    Likes Received:
    234
    Re: Problem solved: HLSL not very intuitive.

    While I understand your argument Humus, production shaders aren't implemented this way in practice (at least in the feature film production environment). Half-Lambert, as you call it, doesn't give any advantage over full Lambert with clamping. Black pixels are only due to the fact that some pixels get rendered at high angles greater than 90. Pixels usually shouldn't get rendered since N dot L over 90 degrees is not usually seen by the viewer. If there is more than one light, then the chances of black pixels are even more rare since an accumulation of light intensity is almost guaranteed to be above 0.

    The reason I call it 'wrong' is because it washes out the regular normal diffuse illumintation on the object by cranking up the intensity on the object. So trying to eliminate some artifacts by making the whole illumination calculation off and putting a bandaid on it by inducing a scalar that can bring it back down is unacceptable.
    ;)

    Btw, we don't use an ambient component in the lighting calculations.

    -M
     
  14. Humus

    Humus Crazy coder
    Veteran

    Joined:
    Feb 6, 2002
    Messages:
    3,217
    Likes Received:
    77
    Location:
    Stockholm, Sweden
    Re: Problem solved: HLSL not very intuitive.

    Moving the camera around will change the relative position of the light to the camera, while just rotating the model won't.
     
  15. Humus

    Humus Crazy coder
    Veteran

    Joined:
    Feb 6, 2002
    Messages:
    3,217
    Likes Received:
    77
    Location:
    Stockholm, Sweden
    Re: Problem solved: HLSL not very intuitive.

    Of course I don't expect Half-Lambert in movie renders, but for simple scenes like in RenderMonkey it's useful.

    "N dot L over 90 degrees" is nothing uncommon though, it's very common, in fact you have it constantly in the scene unless the camera and light is at the same position. Just view the object from behind and you have N dot L < 0, so all blackness.
     
  16. VFX_Veteran

    Regular

    Joined:
    Mar 9, 2002
    Messages:
    683
    Likes Received:
    234
    Re: Problem solved: HLSL not very intuitive.

    You are still arguing my style of coding.:) Why? I am only going to continue coding the way I do at work...


    -M
     
  17. Humus

    Humus Crazy coder
    Veteran

    Joined:
    Feb 6, 2002
    Messages:
    3,217
    Likes Received:
    77
    Location:
    Stockholm, Sweden
    No, I don't mind your coding style at all. And I don't particularly endorse half-Lambert over other lighting models. I'm not suggesting you should start using it. I'm just saying it's not neccesarily useless or "wrong".
     
Loading...

Share This Page

  • About Us

    Beyond3D has been around for over a decade and prides itself on being the best place on the web for in-depth, technically-driven discussion and analysis of 3D graphics hardware. If you love pixels and transistors, you've come to the right place!

    Beyond3D is proudly published by GPU Tools Ltd.
Loading...