From 861616bf693b78b070ada6cbc6aa79eb807fdde8 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 13 Mar 2016 02:00:12 +0100 Subject: Full Inverse-Quadratic-Equation Lamp Falloff MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds a new `falloff_type` ('Inverse Coefficients') for Lamps in Blender-Internal and GLSL. The current falloff modes use a formula like this inverse-square one: `I = E × (D^2 / (D^2 + Q × r^2))` While such a formula is simple for 3D-artists to use, it's algebraically cumbersome to work with. Game-designers authoring their own shaders could benefit much more by having direct control of falloff-coefficients: `I = E × (1.0 / (coefC + coefL × r + coefQ × r^2))` In this mode, the `distance` parameter is unused (except for 'Sphere' mode); instead relying on the designer to mathematically-model the falloff-behavior. The UI has been patched like so: {F153843} Reviewers: brecht, psy-fi Reviewed By: psy-fi Subscribers: brita_, antidote, campbellbarton, psy-fi Differential Revision: https://developer.blender.org/D1194 --- source/blender/render/intern/include/render_types.h | 1 + source/blender/render/intern/source/convertblender.c | 3 +++ source/blender/render/intern/source/shadeoutput.c | 11 ++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) (limited to 'source/blender/render/intern') diff --git a/source/blender/render/intern/include/render_types.h b/source/blender/render/intern/include/render_types.h index ed83cfec764..cef3a073084 100644 --- a/source/blender/render/intern/include/render_types.h +++ b/source/blender/render/intern/include/render_types.h @@ -569,6 +569,7 @@ typedef struct LampRen { short falloff_type; float ld1, ld2; + float coeff_const, coeff_lin, coeff_quad; struct CurveMapping *curfalloff; /* copied from Lamp, to decouple more rendering stuff */ diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 64fd56715c7..ccf54cb6bcd 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -3801,6 +3801,9 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) lar->falloff_type = la->falloff_type; lar->ld1= la->att1; lar->ld2= la->att2; + lar->coeff_const= la->coeff_const; + lar->coeff_lin= la->coeff_lin; + lar->coeff_quad= la->coeff_quad; lar->curfalloff = curvemapping_copy(la->curfalloff); if (lar->curfalloff) { diff --git a/source/blender/render/intern/source/shadeoutput.c b/source/blender/render/intern/source/shadeoutput.c index 71b409dbba7..9dec2698720 100644 --- a/source/blender/render/intern/source/shadeoutput.c +++ b/source/blender/render/intern/source/shadeoutput.c @@ -1188,7 +1188,7 @@ float lamp_get_visibility(LampRen *lar, const float co[3], float lv[3], float *d return 1.0f; } else { - float visifac= 1.0f; + float visifac= 1.0f, visifac_r; sub_v3_v3v3(lv, co, lar->co); mul_v3_fl(lv, 1.0f / (*dist = len_v3(lv))); @@ -1223,6 +1223,15 @@ float lamp_get_visibility(LampRen *lar, const float co[3], float lv[3], float *d if (lar->ld2>0.0f) visifac*= lar->distkw/(lar->distkw+lar->ld2*dist[0]*dist[0]); break; + case LA_FALLOFF_INVCOEFFICIENTS: + visifac_r = lar->coeff_const + + lar->coeff_lin * dist[0] + + lar->coeff_quad * dist[0] * dist[0]; + if (visifac_r > 0.0) + visifac = 1.0 / visifac_r; + else + visifac = 0.0; + break; case LA_FALLOFF_CURVE: /* curvemapping_initialize is called from #add_render_lamp */ visifac = curvemapping_evaluateF(lar->curfalloff, 0, dist[0]/lar->dist); -- cgit v1.2.3