BGE: Bringing over the dynamic lamp properties fixes from Cucumber (thanks to Daniel...
authorMitchell Stokes <mogurijin@gmail.com>
Mon, 23 Jul 2012 20:24:35 +0000 (20:24 +0000)
committerMitchell Stokes <mogurijin@gmail.com>
Mon, 23 Jul 2012 20:24:35 +0000 (20:24 +0000)
  * distance
  * lin_attenuation
  * quad_attenuation
  * spotsize
  * spotblend

source/blender/gpu/GPU_material.h
source/blender/gpu/intern/gpu_material.c
source/gameengine/Ketsji/KX_Light.cpp

index 7f5ae0ba2a12e391399e67c2f9a464167f6adfe6..a725ff4385d6fa953a9fa979fd5b3dd93201043d 100644 (file)
@@ -173,6 +173,11 @@ typedef enum GPUDynamicType {
        GPU_DYNAMIC_SAMPLER_2DBUFFER = 12,
        GPU_DYNAMIC_SAMPLER_2DIMAGE = 13,
        GPU_DYNAMIC_SAMPLER_2DSHADOW = 14,
+       GPU_DYNAMIC_LAMP_DISTANCE = 15,
+       GPU_DYNAMIC_LAMP_ATT1 = 16,
+       GPU_DYNAMIC_LAMP_ATT2 = 17,
+       GPU_DYNAMIC_LAMP_SPOTSIZE = 18,
+       GPU_DYNAMIC_LAMP_SPOTBLEND = 19,
 } GPUDynamicType;
 
 typedef enum GPUDataType {
@@ -231,6 +236,8 @@ void GPU_lamp_shadow_buffer_unbind(GPULamp *lamp);
 
 void GPU_lamp_update(GPULamp *lamp, int lay, int hide, float obmat[][4]);
 void GPU_lamp_update_colors(GPULamp *lamp, float r, float g, float b, float energy);
+void GPU_lamp_update_distance(GPULamp *lamp, float distance, float att1, float att2);
+void GPU_lamp_update_spot(GPULamp *lamp, float spotsize, float spotblend);
 int GPU_lamp_shadow_layer(GPULamp *lamp);
 
 #ifdef __cplusplus
index 0fad5e47445897f9db8613ce9aa8b59c6245d1af..557d8dbe237207257bee3e89dd2b818ce8c84861 100644 (file)
@@ -117,6 +117,7 @@ struct GPULamp {
        float dynimat[4][4];
 
        float spotsi, spotbl, k;
+       float dyndist, dynatt1, dynatt2;
        float dist, att1, att2;
        float shadow_color[3];
 
@@ -413,13 +414,13 @@ static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNode
                        case LA_FALLOFF_CONSTANT:
                                break;
                        case LA_FALLOFF_INVLINEAR:
-                               GPU_link(mat, "lamp_falloff_invlinear", GPU_uniform(&lamp->dist), *dist, &visifac);
+                               GPU_link(mat, "lamp_falloff_invlinear", GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), *dist, &visifac);
                                break;
                        case LA_FALLOFF_INVSQUARE:
-                               GPU_link(mat, "lamp_falloff_invsquare", GPU_uniform(&lamp->dist), *dist, &visifac);
+                               GPU_link(mat, "lamp_falloff_invsquare", GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), *dist, &visifac);
                                break;
                        case LA_FALLOFF_SLIDERS:
-                               GPU_link(mat, "lamp_falloff_sliders", GPU_uniform(&lamp->dist), GPU_uniform(&lamp->att1), GPU_uniform(&lamp->att2), *dist, &visifac);
+                               GPU_link(mat, "lamp_falloff_sliders", GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), GPU_dynamic_uniform(&lamp->att1, GPU_DYNAMIC_LAMP_ATT1, lamp->ob), GPU_dynamic_uniform(&lamp->att2, GPU_DYNAMIC_LAMP_ATT2, lamp->ob), *dist, &visifac);
                                break;
                        case LA_FALLOFF_CURVE:
                                {
@@ -427,13 +428,13 @@ static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNode
                                        int size;
 
                                        curvemapping_table_RGBA(lamp->curfalloff, &array, &size);
-                                       GPU_link(mat, "lamp_falloff_curve", GPU_uniform(&lamp->dist), GPU_texture(size, array), *dist, &visifac);
+                                       GPU_link(mat, "lamp_falloff_curve", GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), GPU_texture(size, array), *dist, &visifac);
                                }
                                break;
                }
 
                if (lamp->mode & LA_SPHERE)
-                       GPU_link(mat, "lamp_visibility_sphere", GPU_uniform(&lamp->dist), *dist, visifac, &visifac);
+                       GPU_link(mat, "lamp_visibility_sphere", GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), *dist, visifac, &visifac);
 
                if (lamp->type == LA_SPOT) {
                        if (lamp->mode & LA_SQUARE) {
@@ -445,7 +446,7 @@ static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNode
                                GPU_link(mat, "lamp_visibility_spot_circle", GPU_dynamic_uniform(lamp->dynvec, GPU_DYNAMIC_LAMP_DYNVEC, lamp->ob), *lv, &inpr);
                        }
                        
-                       GPU_link(mat, "lamp_visibility_spot", GPU_uniform(&lamp->spotsi), GPU_uniform(&lamp->spotbl), inpr, visifac, &visifac);
+                       GPU_link(mat, "lamp_visibility_spot", GPU_dynamic_uniform(&lamp->spotsi, GPU_DYNAMIC_LAMP_SPOTSIZE, lamp->ob), GPU_dynamic_uniform(&lamp->spotbl, GPU_DYNAMIC_LAMP_SPOTSIZE, lamp->ob), inpr, visifac, &visifac);
                }
 
                GPU_link(mat, "lamp_visibility_clamp", visifac, &visifac);
@@ -1570,6 +1571,19 @@ void GPU_lamp_update_colors(GPULamp *lamp, float r, float g, float b, float ener
        lamp->col[2]= b* lamp->energy;
 }
 
+void GPU_lamp_update_distance(GPULamp *lamp, float distance, float att1, float att2)
+{
+       lamp->dist = distance;
+       lamp->att1 = att1;
+       lamp->att2 = att2;
+}
+
+void GPU_lamp_update_spot(GPULamp *lamp, float spotsize, float spotblend)
+{
+       lamp->spotsi= cos(M_PI*spotsize/360.0);
+       lamp->spotbl= (1.0f - lamp->spotsi)*spotblend;
+}
+
 static void gpu_lamp_from_blender(Scene *scene, Object *ob, Object *par, Lamp *la, GPULamp *lamp)
 {
        float temp, angle, pixsize, wsize;
index 5922e97aaf44d9cc908cf39209424162ae4bb860..512dc4b931b84d43031ad35773227a4b0ca42e46 100644 (file)
@@ -67,10 +67,13 @@ KX_LightObject::KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks,
 KX_LightObject::~KX_LightObject()
 {
        GPULamp *lamp;
+       Lamp *la = (Lamp*)GetBlenderObject()->data;
 
        if ((lamp = GetGPULamp())) {
                float obmat[4][4] = {{0}};
                GPU_lamp_update(lamp, 0, 0, obmat);
+               GPU_lamp_update_distance(lamp, la->dist, la->att1, la->att2);
+               GPU_lamp_update_spot(lamp, la->spotsize, la->spotblend);
        }
 
        m_rendertools->RemoveLight(&m_lightobj);
@@ -206,6 +209,8 @@ void KX_LightObject::Update()
                GPU_lamp_update(lamp, m_lightobj.m_layer, 0, obmat);
                GPU_lamp_update_colors(lamp, m_lightobj.m_red, m_lightobj.m_green, 
                        m_lightobj.m_blue, m_lightobj.m_energy);
+               GPU_lamp_update_distance(lamp, m_lightobj.m_distance, m_lightobj.m_att1, m_lightobj.m_att2);
+               GPU_lamp_update_spot(lamp, m_lightobj.m_spotsize, m_lightobj.m_spotblend);
        }
 }