Rim Light question #585
Answered
by
pragma37
rosstheblenderanimator
asked this question in
Q&A
-
How to control the rim light direction with light source? |
Beta Was this translation helpful? Give feedback.
Answered by
pragma37
Sep 29, 2024
Replies: 1 comment 3 replies
-
You would need the light vector in view space and use it as the angle for the rim. #if defined(IS_MESH_SHADER) || defined(IS_SCREEN_SHADER)
#ifdef IS_MESH_SHADER
/* META
@normal: subtype=Normal; default=NORMAL;
@rim_length: default=1.0;
@length_fallof: default=1.0;
@thickness: default=0.5;
@thickness_fallof: default=0.0;
@light_groups: default=MATERIAL_LIGHT_GROUPS;
*/
#else
/* META
@normal: subtype=Normal; default=NORMAL;
@rim_length: default=1.0;
@length_fallof: default=1.0;
@thickness: default=0.5;
@thickness_fallof: default=0.0;
@light_groups: default=ivec4(1,0,0,0);
*/
#endif
vec3 NPR_rim_lights(vec3 normal, float rim_length, float length_falloff, float thickness, float thickness_falloff, ivec4 light_groups)
{
vec3 result = vec3(0,0,0);
for (int i = 0; i < LIGHTS.lights_count; i++)
{
for(int group_index = 0; group_index < 4; group_index++)
{
if(LIGHT_GROUP_INDEX(i) != light_groups[group_index])
{
continue;
}
Light L = LIGHTS.lights[i];
LitSurface LS = npr_lit_surface(POSITION, normal, ID.x, L, i, false, false);
vec3 L_vs = transform_direction(CAMERA, LS.L);
float angle = atan(L_vs.y, L_vs.x) + PI / 2.0;
float rim = rim_light(normal, angle, rim_length, length_falloff, thickness, thickness_falloff);
result += rim * LS.light_color;
}
}
return result;
}
#endif |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
rosstheblenderanimator
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You would need the light vector in view space and use it as the angle for the rim.
This is not easy to do from nodes, so here's a function that you can drop into a plugin: