ashwin.sudhir Posted January 21, 2012 Share Posted January 21, 2012 To implement a rim lighting shader (relative to camera angle) we need access to the normal and camera vector in the same co-ordinate space. Which variables should we use in the shader for world space normal and camera direction (or some other shared space) ? Link to comment
alexei.garbuzenko Posted January 21, 2012 Share Posted January 21, 2012 There is already Phong-Rim lighting implemented in Unigine. In vertex shader camera projection space is used, so camera position is (0,0,0), so -vertex.xyz is equal to camera direction. Variable normal contains vertex normal in the same space. Look at common/vertex_base_light_world.h and meshes/fragment_base_light.h shaders. Link to comment
ashwin.sudhir Posted January 23, 2012 Author Share Posted January 23, 2012 Thanks alexei, I used fragment_base_light as the reference. Here's the code in case it's useful to someone half rim = pow( 1.f - abs( dot( normalize( camera_direction ), normal ) ), rim_power ) * rim_intensity; One caveat is that camera_direction doesn't seem to be normalized. Link to comment
manguste Posted February 6, 2012 Share Posted February 6, 2012 One caveat is that camera_direction doesn't seem to be normalized. Not quite sure what you mean by that, as in Unigine shaders camera_direction is normalized, check common/fragment_base_shading.h. Link to comment
ashwin.sudhir Posted February 6, 2012 Author Share Posted February 6, 2012 core/shaders/default/meshes/fragment_base_light.h #elif DIRECT3D9 #include <core/shaders/default/meshes/fragment_base_sample.h>#ifdef PHONG_RIM || !QUALITY_MEDIUM half3 camera_direction = IN.texcoord_2.xyz; Without normalizing I get half rim = pow( 1.f - abs( dot( camera_direction, normal ) ), rim_power ) * rim_intensity; After normalizing I get half rim = pow( 1.f - abs( dot( normalize( camera_direction ), normal ) ), rim_power ) * rim_intensity; Link to comment
manguste Posted February 14, 2012 Share Posted February 14, 2012 Ah, Ok, it's clear now :) Link to comment
Recommended Posts