Blender V2.61 - r43446

rna_lamp.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * Contributor(s): Blender Foundation (2008).
00019  *
00020  * ***** END GPL LICENSE BLOCK *****
00021  */
00022 
00028 #include <stdlib.h>
00029 
00030 #include "RNA_define.h"
00031 #include "RNA_enum_types.h"
00032 
00033 #include "rna_internal.h"
00034 
00035 #include "DNA_lamp_types.h"
00036 #include "DNA_material_types.h"
00037 #include "DNA_texture_types.h"
00038 
00039 #include "BLI_math_base.h"
00040 
00041 #ifdef RNA_RUNTIME
00042 
00043 #include "MEM_guardedalloc.h"
00044 
00045 #include "BKE_depsgraph.h"
00046 #include "BKE_main.h"
00047 #include "BKE_texture.h"
00048 
00049 #include "ED_node.h"
00050 #include "WM_api.h"
00051 #include "WM_types.h"
00052 
00053 static void rna_Lamp_buffer_size_set(PointerRNA *ptr, int value)
00054 {
00055     Lamp *la= (Lamp*)ptr->data;
00056 
00057     CLAMP(value, 512, 10240);
00058     la->bufsize= value;
00059     la->bufsize &= (~15); /* round to multiple of 16 */
00060 }
00061 
00062 static PointerRNA rna_Lamp_sky_settings_get(PointerRNA *ptr)
00063 {
00064     return rna_pointer_inherit_refine(ptr, &RNA_LampSkySettings, ptr->id.data);
00065 }
00066 
00067 static void rna_Lamp_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00068 {
00069     Lamp *la= (Lamp*)ptr->data;
00070     rna_iterator_array_begin(iter, (void*)la->mtex, sizeof(MTex*), MAX_MTEX, 0, NULL);
00071 }
00072 
00073 static PointerRNA rna_Lamp_active_texture_get(PointerRNA *ptr)
00074 {
00075     Lamp *la= (Lamp*)ptr->data;
00076     Tex *tex;
00077 
00078     tex= give_current_lamp_texture(la);
00079     return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex);
00080 }
00081 
00082 static void rna_Lamp_active_texture_set(PointerRNA *ptr, PointerRNA value)
00083 {
00084     Lamp *la= (Lamp*)ptr->data;
00085 
00086     set_current_lamp_texture(la, value.data);
00087 }
00088 
00089 static StructRNA* rna_Lamp_refine(struct PointerRNA *ptr)
00090 {
00091     Lamp *la= (Lamp*)ptr->data;
00092 
00093     switch(la->type) {
00094         case LA_LOCAL:
00095             return &RNA_PointLamp;
00096         case LA_SUN:
00097             return &RNA_SunLamp;
00098         case LA_SPOT:
00099             return &RNA_SpotLamp;
00100         case LA_HEMI:
00101             return &RNA_HemiLamp;
00102         case LA_AREA:
00103             return &RNA_AreaLamp;
00104         default:
00105             return &RNA_Lamp;
00106     }
00107 }
00108 
00109 static void rna_Lamp_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
00110 {
00111     Lamp *la= ptr->id.data;
00112 
00113     DAG_id_tag_update(&la->id, 0);
00114     if(scene->gm.matmode == GAME_MAT_GLSL)
00115         WM_main_add_notifier(NC_LAMP|ND_LIGHTING_DRAW, la);
00116     else
00117         WM_main_add_notifier(NC_LAMP|ND_LIGHTING, la);
00118 }
00119 
00120 static void rna_Lamp_draw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
00121 {
00122     Lamp *la= ptr->id.data;
00123 
00124     DAG_id_tag_update(&la->id, 0);
00125     WM_main_add_notifier(NC_LAMP|ND_LIGHTING_DRAW, la);
00126 }
00127 
00128 static void rna_Lamp_sky_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
00129 {
00130     Lamp *la= ptr->id.data;
00131 
00132     DAG_id_tag_update(&la->id, 0);
00133     WM_main_add_notifier(NC_LAMP|ND_SKY, la);
00134 }
00135 
00136 /* only for rad/deg conversion! can remove later */
00137 static float rna_Lamp_spot_size_get(PointerRNA *ptr)
00138 {
00139     Lamp *la= ptr->id.data;
00140     return DEG2RADF(la->spotsize);
00141 }
00142 
00143 static void rna_Lamp_spot_size_set(PointerRNA *ptr, float value)
00144 {
00145     Lamp *la= ptr->id.data;
00146     la->spotsize= RAD2DEGF(value);
00147 }
00148 
00149 static void rna_Lamp_use_nodes_update(Main *blain, Scene *scene, PointerRNA *ptr)
00150 {
00151     Lamp *la= (Lamp*)ptr->data;
00152 
00153     if(la->use_nodes && la->nodetree==NULL)
00154         ED_node_shader_default(scene, &la->id);
00155     
00156     rna_Lamp_update(blain, scene, ptr);
00157 }
00158 
00159 #else
00160 
00161 EnumPropertyItem lamp_type_items[] = {
00162     {LA_LOCAL, "POINT", 0, "Point", "Omnidirectional point light source"},
00163     {LA_SUN, "SUN", 0, "Sun", "Constant direction parallel ray light source"},
00164     {LA_SPOT, "SPOT", 0, "Spot", "Directional cone light source"},
00165     {LA_HEMI, "HEMI", 0, "Hemi", "180 degree constant light source"},
00166     {LA_AREA, "AREA", 0, "Area", "Directional area light source"},
00167     {0, NULL, 0, NULL, NULL}};
00168 
00169 static void rna_def_lamp_mtex(BlenderRNA *brna)
00170 {
00171     StructRNA *srna;
00172     PropertyRNA *prop;
00173 
00174     static EnumPropertyItem prop_texture_coordinates_items[] = {
00175         {TEXCO_GLOB, "GLOBAL", 0, "Global", "Use global coordinates for the texture coordinates"},
00176         {TEXCO_VIEW, "VIEW", 0, "View", "Use view coordinates for the texture coordinates"},
00177         {TEXCO_OBJECT, "OBJECT", 0, "Object", "Use linked object's coordinates for texture coordinates"},
00178         {0, NULL, 0, NULL, NULL}};
00179 
00180     srna= RNA_def_struct(brna, "LampTextureSlot", "TextureSlot");
00181     RNA_def_struct_sdna(srna, "MTex");
00182     RNA_def_struct_ui_text(srna, "Lamp Texture Slot", "Texture slot for textures in a Lamp datablock");
00183 
00184     prop= RNA_def_property(srna, "texture_coords", PROP_ENUM, PROP_NONE);
00185     RNA_def_property_enum_sdna(prop, NULL, "texco");
00186     RNA_def_property_enum_items(prop, prop_texture_coordinates_items);
00187     RNA_def_property_ui_text(prop, "Texture Coordinates", "");
00188 
00189     prop= RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
00190     RNA_def_property_pointer_sdna(prop, NULL, "object");
00191     RNA_def_property_struct_type(prop, "Object");
00192     RNA_def_property_flag(prop, PROP_EDITABLE);
00193     RNA_def_property_ui_text(prop, "Object", "Object to use for mapping with Object texture coordinates");
00194 
00195     prop= RNA_def_property(srna, "use_map_color", PROP_BOOLEAN, PROP_NONE);
00196     RNA_def_property_boolean_sdna(prop, NULL, "mapto", LAMAP_COL);
00197     RNA_def_property_ui_text(prop, "Color", "Let the texture affect the basic color of the lamp");
00198     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00199 
00200     prop= RNA_def_property(srna, "use_map_shadow", PROP_BOOLEAN, PROP_NONE);
00201     RNA_def_property_boolean_sdna(prop, NULL, "mapto", LAMAP_SHAD);
00202     RNA_def_property_ui_text(prop, "Shadow", "Let the texture affect the shadow color of the lamp");
00203     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00204 
00205     prop= RNA_def_property(srna, "color_factor", PROP_FLOAT, PROP_NONE);
00206     RNA_def_property_float_sdna(prop, NULL, "colfac");
00207     RNA_def_property_ui_range(prop, 0, 1, 10, 3);
00208     RNA_def_property_ui_text(prop, "Color Factor", "Amount texture affects color values");
00209     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00210 
00211     prop= RNA_def_property(srna, "shadow_factor", PROP_FLOAT, PROP_NONE);
00212     RNA_def_property_float_sdna(prop, NULL, "shadowfac");
00213     RNA_def_property_ui_range(prop, 0, 1, 10, 3);
00214     RNA_def_property_ui_text(prop, "Shadow Factor", "Amount texture affects shadow");
00215     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00216 }
00217 
00218 static void rna_def_lamp_sky_settings(BlenderRNA *brna)
00219 {
00220     StructRNA *srna;
00221     PropertyRNA *prop;
00222 
00223     static EnumPropertyItem prop_skycolorspace_items[] = {
00224         {0, "SMPTE", 0, "SMPTE", ""},
00225         {1, "REC709", 0, "REC709", ""},
00226         {2, "CIE", 0, "CIE", ""},
00227         {0, NULL, 0, NULL, NULL}};
00228         
00229     srna= RNA_def_struct(brna, "LampSkySettings", NULL);
00230     RNA_def_struct_sdna(srna, "Lamp");
00231     RNA_def_struct_nested(brna, srna, "SunLamp");
00232     RNA_def_struct_ui_text(srna, "Lamp Sky Settings", "Sky related settings for a sun lamp");
00233         
00234     prop= RNA_def_property(srna, "sky_color_space", PROP_ENUM, PROP_NONE);
00235     RNA_def_property_enum_sdna(prop, NULL, "sky_colorspace");
00236     RNA_def_property_enum_items(prop, prop_skycolorspace_items);
00237     RNA_def_property_ui_text(prop, "Sky Color Space", "Color space to use for internal XYZ->RGB color conversion");
00238     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00239 
00240     prop= RNA_def_property(srna, "sky_blend_type", PROP_ENUM, PROP_NONE);
00241     RNA_def_property_enum_sdna(prop, NULL, "skyblendtype");
00242     RNA_def_property_enum_items(prop, ramp_blend_items);
00243     RNA_def_property_ui_text(prop, "Sky Blend Mode", "Blend mode for combining sun sky with world sky");
00244     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00245     
00246     /* Number values */
00247     
00248     prop= RNA_def_property(srna, "horizon_brightness", PROP_FLOAT, PROP_NONE);
00249     RNA_def_property_range(prop, 0.0f, 20.0f);
00250     RNA_def_property_ui_text(prop, "Horizon Brightness", "Horizon brightness");
00251     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00252 
00253     prop= RNA_def_property(srna, "spread", PROP_FLOAT, PROP_NONE);
00254     RNA_def_property_range(prop, 0.0f, 10.0f);
00255     RNA_def_property_ui_text(prop, "Horizon Spread", "Horizon Spread");
00256     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00257 
00258     prop= RNA_def_property(srna, "sun_brightness", PROP_FLOAT, PROP_NONE);
00259     RNA_def_property_range(prop, 0.0f, 10.0f);
00260     RNA_def_property_ui_text(prop, "Sun Brightness", "Sun brightness");
00261     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00262 
00263     prop= RNA_def_property(srna, "sun_size", PROP_FLOAT, PROP_NONE);
00264     RNA_def_property_range(prop, 0.0f, 10.0f);
00265     RNA_def_property_ui_text(prop, "Sun Size", "Sun size");
00266     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00267 
00268     prop= RNA_def_property(srna, "backscattered_light", PROP_FLOAT, PROP_NONE);
00269     RNA_def_property_range(prop, -1.0f, 1.0f);
00270     RNA_def_property_ui_text(prop, "Backscattered Light", "Backscattered light");
00271     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00272 
00273     prop= RNA_def_property(srna, "sun_intensity", PROP_FLOAT, PROP_NONE);
00274     RNA_def_property_range(prop, 0.0f, 10.0f);
00275     RNA_def_property_ui_text(prop, "Sun Intensity", "Sun intensity");
00276     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00277 
00278     prop= RNA_def_property(srna, "atmosphere_turbidity", PROP_FLOAT, PROP_NONE);
00279     RNA_def_property_float_sdna(prop, NULL, "atm_turbidity");
00280     RNA_def_property_range(prop, 1.0f, 30.0f);
00281     RNA_def_property_ui_range(prop, 2.0f, 10.0f, 1, 2);
00282     RNA_def_property_ui_text(prop, "Atmosphere Turbidity", "Sky turbidity");
00283     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00284 
00285     prop= RNA_def_property(srna, "atmosphere_inscattering", PROP_FLOAT, PROP_NONE);
00286     RNA_def_property_float_sdna(prop, NULL, "atm_inscattering_factor");
00287     RNA_def_property_range(prop, 0.0f, 1.0f);
00288     RNA_def_property_ui_text(prop, "Atmosphere Inscatter", "Scatter contribution factor");
00289     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00290 
00291     prop= RNA_def_property(srna, "atmosphere_extinction", PROP_FLOAT, PROP_NONE);
00292     RNA_def_property_float_sdna(prop, NULL, "atm_extinction_factor");
00293     RNA_def_property_range(prop, 0.0f, 1.0f);
00294     RNA_def_property_ui_text(prop, "Atmosphere Extinction", "Extinction scattering contribution factor");
00295     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00296 
00297     prop= RNA_def_property(srna, "atmosphere_distance_factor", PROP_FLOAT, PROP_NONE);
00298     RNA_def_property_float_sdna(prop, NULL, "atm_distance_factor");
00299     RNA_def_property_range(prop, 0.0f, 500.0f);
00300     RNA_def_property_ui_text(prop, "Atmosphere Distance Factor", "Multiplier to convert blender units to physical distance");
00301     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00302 
00303     prop= RNA_def_property(srna, "sky_blend", PROP_FLOAT, PROP_NONE);
00304     RNA_def_property_float_sdna(prop, NULL, "skyblendfac");
00305     RNA_def_property_range(prop, 0.0f, 2.0f);
00306     RNA_def_property_ui_text(prop, "Sky Blend", "Blend factor with sky");
00307     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00308 
00309     prop= RNA_def_property(srna, "sky_exposure", PROP_FLOAT, PROP_NONE);
00310     RNA_def_property_range(prop, 0.0f, 20.0f);
00311     RNA_def_property_ui_text(prop, "Sky Exposure", "Strength of sky shading exponential exposure correction");
00312     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00313 
00314     /* boolean */
00315     
00316     prop= RNA_def_property(srna, "use_sky", PROP_BOOLEAN, PROP_NONE);
00317     RNA_def_property_boolean_sdna(prop, NULL, "sun_effect_type", LA_SUN_EFFECT_SKY);
00318     RNA_def_property_ui_text(prop, "Sky", "Apply sun effect on sky");
00319     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00320 
00321     prop= RNA_def_property(srna, "use_atmosphere", PROP_BOOLEAN, PROP_NONE);
00322     RNA_def_property_boolean_sdna(prop, NULL, "sun_effect_type", LA_SUN_EFFECT_AP);
00323     RNA_def_property_ui_text(prop, "Atmosphere", "Apply sun effect on atmosphere");
00324     RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
00325 }
00326 
00327 static void rna_def_lamp(BlenderRNA *brna)
00328 {
00329     StructRNA *srna;
00330     PropertyRNA *prop;
00331 
00332     srna= RNA_def_struct(brna, "Lamp", "ID");
00333     RNA_def_struct_refine_func(srna, "rna_Lamp_refine");
00334     RNA_def_struct_ui_text(srna, "Lamp", "Lamp datablock for lighting a scene");
00335     RNA_def_struct_ui_icon(srna, ICON_LAMP_DATA);
00336 
00337     prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
00338     RNA_def_property_enum_items(prop, lamp_type_items);
00339     RNA_def_property_ui_text(prop, "Type", "Type of Lamp");
00340     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00341 
00342     prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_DISTANCE);
00343     RNA_def_property_float_sdna(prop, NULL, "dist");
00344     RNA_def_property_range(prop, 0, INT_MAX);
00345     RNA_def_property_ui_range(prop, 0, 1000, 1, 3);
00346     RNA_def_property_ui_text(prop, "Distance", "Falloff distance - the light is at half the original intensity at this point");
00347     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00348 
00349     prop= RNA_def_property(srna, "energy", PROP_FLOAT, PROP_NONE);
00350     RNA_def_property_ui_range(prop, 0, 10, 1, 3);
00351     RNA_def_property_ui_text(prop, "Energy", "Amount of light that the lamp emits");
00352     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00353 
00354     prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
00355     RNA_def_property_float_sdna(prop, NULL, "r");
00356     RNA_def_property_array(prop, 3);
00357     RNA_def_property_ui_text(prop, "Color", "Light color");
00358     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00359 
00360     prop= RNA_def_property(srna, "use_own_layer", PROP_BOOLEAN, PROP_NONE);
00361     RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_LAYER);
00362     RNA_def_property_ui_text(prop, "Layer", "Illuminate objects only on the same layers the lamp is on");
00363     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00364 
00365     prop= RNA_def_property(srna, "use_negative", PROP_BOOLEAN, PROP_NONE);
00366     RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_NEG);
00367     RNA_def_property_ui_text(prop, "Negative", "Cast negative light");
00368     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00369 
00370     prop= RNA_def_property(srna, "use_specular", PROP_BOOLEAN, PROP_NONE);
00371     RNA_def_property_boolean_negative_sdna(prop, NULL, "mode", LA_NO_SPEC);
00372     RNA_def_property_ui_text(prop, "Specular", "Create specular highlights");
00373     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00374 
00375     prop= RNA_def_property(srna, "use_diffuse", PROP_BOOLEAN, PROP_NONE);
00376     RNA_def_property_boolean_negative_sdna(prop, NULL, "mode", LA_NO_DIFF);
00377     RNA_def_property_ui_text(prop, "Diffuse", "Do diffuse shading");
00378     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00379 
00380     /* nodes */
00381     prop= RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
00382     RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
00383     RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node based lamps");
00384 
00385     prop= RNA_def_property(srna, "use_nodes", PROP_BOOLEAN, PROP_NONE);
00386     RNA_def_property_boolean_sdna(prop, NULL, "use_nodes", 1);
00387     RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
00388     RNA_def_property_ui_text(prop, "Use Nodes", "Use shader nodes to render the lamp");
00389     RNA_def_property_update(prop, 0, "rna_Lamp_use_nodes_update");
00390     
00391     /* common */
00392     rna_def_animdata_common(srna);
00393     
00394     /* textures */
00395     rna_def_mtex_common(brna, srna, "rna_Lamp_mtex_begin", "rna_Lamp_active_texture_get",
00396         "rna_Lamp_active_texture_set", NULL, "LampTextureSlot", "LampTextureSlots", "rna_Lamp_update");
00397 }
00398 
00399 static void rna_def_lamp_falloff(StructRNA *srna)
00400 {
00401     PropertyRNA *prop;
00402 
00403     static EnumPropertyItem prop_fallofftype_items[] = {
00404         {LA_FALLOFF_CONSTANT, "CONSTANT", 0, "Constant", ""},
00405         {LA_FALLOFF_INVLINEAR, "INVERSE_LINEAR", 0, "Inverse Linear", ""},
00406         {LA_FALLOFF_INVSQUARE, "INVERSE_SQUARE", 0, "Inverse Square", ""},
00407         {LA_FALLOFF_CURVE, "CUSTOM_CURVE", 0, "Custom Curve", ""},
00408         {LA_FALLOFF_SLIDERS, "LINEAR_QUADRATIC_WEIGHTED", 0, "Lin/Quad Weighted", ""},
00409         {0, NULL, 0, NULL, NULL}};
00410 
00411     prop= RNA_def_property(srna, "falloff_type", PROP_ENUM, PROP_NONE);
00412     RNA_def_property_enum_items(prop, prop_fallofftype_items);
00413     RNA_def_property_ui_text(prop, "Falloff Type", "Intensity Decay with distance");
00414     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00415     
00416     prop= RNA_def_property(srna, "falloff_curve", PROP_POINTER, PROP_NONE);
00417     RNA_def_property_pointer_sdna(prop, NULL, "curfalloff");
00418     RNA_def_property_ui_text(prop, "Falloff Curve", "Custom Lamp Falloff Curve");
00419     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00420 
00421     prop= RNA_def_property(srna, "use_sphere", PROP_BOOLEAN, PROP_NONE);
00422     RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_SPHERE);
00423     RNA_def_property_ui_text(prop, "Sphere", "Set light intensity to zero beyond lamp distance");
00424     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00425 
00426     prop= RNA_def_property(srna, "linear_attenuation", PROP_FLOAT, PROP_NONE);
00427     RNA_def_property_float_sdna(prop, NULL, "att1");
00428     RNA_def_property_range(prop, 0.0f, 1.0f);
00429     RNA_def_property_ui_text(prop, "Linear Attenuation", "Linear distance attenuation");
00430     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00431 
00432     prop= RNA_def_property(srna, "quadratic_attenuation", PROP_FLOAT, PROP_NONE);
00433     RNA_def_property_float_sdna(prop, NULL, "att2");
00434     RNA_def_property_range(prop, 0.0f, 1.0f);
00435     RNA_def_property_ui_text(prop, "Quadratic Attenuation", "Quadratic distance attenuation");
00436     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00437 }
00438 
00439 static void rna_def_lamp_shadow(StructRNA *srna, int spot, int area)
00440 {
00441     PropertyRNA *prop;
00442 
00443     static EnumPropertyItem prop_shadow_items[] = {
00444         {0, "NOSHADOW", 0, "No Shadow", ""},
00445         {LA_SHAD_RAY, "RAY_SHADOW", 0, "Ray Shadow", "Use ray tracing for shadow"},
00446         {0, NULL, 0, NULL, NULL}};
00447 
00448     static EnumPropertyItem prop_spot_shadow_items[] = {
00449         {0, "NOSHADOW", 0, "No Shadow", ""},
00450         {LA_SHAD_BUF, "BUFFER_SHADOW", 0, "Buffer Shadow", "Let spotlight produce shadows using shadow buffer"},
00451         {LA_SHAD_RAY, "RAY_SHADOW", 0, "Ray Shadow", "Use ray tracing for shadow"},
00452         {0, NULL, 0, NULL, NULL}};
00453 
00454     static EnumPropertyItem prop_ray_sampling_method_items[] = {
00455         {LA_SAMP_HALTON, "ADAPTIVE_QMC", 0, "Adaptive QMC", ""},
00456         {LA_SAMP_HAMMERSLEY, "CONSTANT_QMC", 0, "Constant QMC", ""},
00457         {0, NULL, 0, NULL, NULL}};
00458     
00459     static EnumPropertyItem prop_spot_ray_sampling_method_items[] = {
00460         {LA_SAMP_HALTON, "ADAPTIVE_QMC", 0, "Adaptive QMC", ""},
00461         {LA_SAMP_HAMMERSLEY, "CONSTANT_QMC", 0, "Constant QMC", ""},
00462         {LA_SAMP_CONSTANT, "CONSTANT_JITTERED", 0, "Constant Jittered", ""},
00463         {0, NULL, 0, NULL, NULL}};
00464 
00465     prop= RNA_def_property(srna, "shadow_method", PROP_ENUM, PROP_NONE);
00466     RNA_def_property_enum_bitflag_sdna(prop, NULL, "mode");
00467     RNA_def_property_enum_items(prop, (spot)? prop_spot_shadow_items: prop_shadow_items);
00468     RNA_def_property_ui_text(prop, "Shadow Method", "Method to compute lamp shadow with");
00469     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00470 
00471     prop= RNA_def_property(srna, "shadow_color", PROP_FLOAT, PROP_COLOR);
00472     RNA_def_property_float_sdna(prop, NULL, "shdwr");
00473     RNA_def_property_array(prop, 3);
00474     RNA_def_property_ui_text(prop, "Shadow Color", "Color of shadows cast by the lamp");
00475     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00476 
00477     prop= RNA_def_property(srna, "use_only_shadow", PROP_BOOLEAN, PROP_NONE);
00478     RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_ONLYSHADOW);
00479     RNA_def_property_ui_text(prop, "Only Shadow", "Cast shadows only, without illuminating objects");
00480     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00481 
00482     prop= RNA_def_property(srna, "shadow_ray_sample_method", PROP_ENUM, PROP_NONE);
00483     RNA_def_property_enum_sdna(prop, NULL, "ray_samp_method");
00484     RNA_def_property_enum_items(prop, (area)? prop_spot_ray_sampling_method_items: prop_ray_sampling_method_items);
00485     RNA_def_property_ui_text(prop, "Shadow Ray Sampling Method", "Method for generating shadow samples: Adaptive QMC is fastest, Constant QMC is less noisy but slower");
00486     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00487 
00488     prop= RNA_def_property(srna, (area)? "shadow_ray_samples_x": "shadow_ray_samples", PROP_INT, PROP_NONE);
00489     RNA_def_property_int_sdna(prop, NULL, "ray_samp");
00490     RNA_def_property_range(prop, 1, 64);
00491     RNA_def_property_ui_text(prop, (area)? "Shadow Ray Samples": "Shadow Ray Samples X","Number of samples taken extra (samples x samples)");
00492     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00493 
00494     if(area) {
00495         prop= RNA_def_property(srna, "shadow_ray_samples_y", PROP_INT, PROP_NONE);
00496         RNA_def_property_int_sdna(prop, NULL, "ray_sampy");
00497         RNA_def_property_range(prop, 1, 64);
00498         RNA_def_property_ui_text(prop, "Shadow Ray Samples Y", "Number of samples taken extra (samples x samples)");
00499         RNA_def_property_update(prop, 0, "rna_Lamp_update");
00500     }
00501 
00502     prop= RNA_def_property(srna, "shadow_adaptive_threshold", PROP_FLOAT, PROP_NONE);
00503     RNA_def_property_float_sdna(prop, NULL, "adapt_thresh");
00504     RNA_def_property_range(prop, 0.0f, 1.0f);
00505     RNA_def_property_ui_text(prop, "Shadow Adaptive Threshold", "Threshold for Adaptive Sampling (Raytraced shadows)");
00506     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00507 
00508     prop= RNA_def_property(srna, "shadow_soft_size", PROP_FLOAT, PROP_DISTANCE);
00509     RNA_def_property_float_sdna(prop, NULL, "area_size");
00510     RNA_def_property_ui_range(prop, 0, 100, 0.1, 3);
00511     RNA_def_property_ui_text(prop, "Shadow Soft Size", "Light size for ray shadow sampling (Raytraced shadows)");
00512     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00513 
00514     prop= RNA_def_property(srna, "use_shadow_layer", PROP_BOOLEAN, PROP_NONE);
00515     RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_LAYER_SHADOW);
00516     RNA_def_property_ui_text(prop, "Shadow Layer", "Objects on the same layers only cast shadows");
00517     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00518 }
00519 
00520 static void rna_def_point_lamp(BlenderRNA *brna)
00521 {
00522     StructRNA *srna;
00523 
00524     srna= RNA_def_struct(brna, "PointLamp", "Lamp");
00525     RNA_def_struct_sdna(srna, "Lamp");
00526     RNA_def_struct_ui_text(srna, "Point Lamp", "Omnidirectional point lamp");
00527     RNA_def_struct_ui_icon(srna, ICON_LAMP_POINT);
00528 
00529     rna_def_lamp_falloff(srna);
00530     rna_def_lamp_shadow(srna, 0, 0);
00531 }
00532 
00533 static void rna_def_area_lamp(BlenderRNA *brna)
00534 {
00535     StructRNA *srna;
00536     PropertyRNA *prop;
00537 
00538     static EnumPropertyItem prop_areashape_items[] = {
00539         {LA_AREA_SQUARE, "SQUARE", 0, "Square", ""},
00540         {LA_AREA_RECT, "RECTANGLE", 0, "Rectangle", ""},
00541         {0, NULL, 0, NULL, NULL}};
00542 
00543     srna= RNA_def_struct(brna, "AreaLamp", "Lamp");
00544     RNA_def_struct_sdna(srna, "Lamp");
00545     RNA_def_struct_ui_text(srna, "Area Lamp", "Directional area lamp");
00546     RNA_def_struct_ui_icon(srna, ICON_LAMP_AREA);
00547 
00548     rna_def_lamp_shadow(srna, 0, 1);
00549 
00550     prop= RNA_def_property(srna, "use_umbra", PROP_BOOLEAN, PROP_NONE);
00551     RNA_def_property_boolean_sdna(prop, NULL, "ray_samp_type", LA_SAMP_UMBRA);
00552     RNA_def_property_ui_text(prop, "Umbra", "Emphasize parts that are fully shadowed (Constant Jittered sampling)");
00553     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00554 
00555     prop= RNA_def_property(srna, "use_dither", PROP_BOOLEAN, PROP_NONE);
00556     RNA_def_property_boolean_sdna(prop, NULL, "ray_samp_type", LA_SAMP_DITHER);
00557     RNA_def_property_ui_text(prop, "Dither", "Use 2x2 dithering for sampling  (Constant Jittered sampling)");
00558     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00559 
00560     prop= RNA_def_property(srna, "use_jitter", PROP_BOOLEAN, PROP_NONE);
00561     RNA_def_property_boolean_sdna(prop, NULL, "ray_samp_type", LA_SAMP_JITTER);
00562     RNA_def_property_ui_text(prop, "Jitter", "Use noise for sampling  (Constant Jittered sampling)");
00563     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00564 
00565     prop= RNA_def_property(srna, "shape", PROP_ENUM, PROP_NONE);
00566     RNA_def_property_enum_sdna(prop, NULL, "area_shape");
00567     RNA_def_property_enum_items(prop, prop_areashape_items);
00568     RNA_def_property_ui_text(prop, "Shape", "Shape of the area lamp");
00569     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00570 
00571     prop= RNA_def_property(srna, "size", PROP_FLOAT, PROP_DISTANCE);
00572     RNA_def_property_float_sdna(prop, NULL, "area_size");
00573     RNA_def_property_ui_range(prop, 0, 100, 0.1, 3);
00574     RNA_def_property_ui_text(prop, "Size", "Size of the area of the area Lamp, X direction size for Rectangle shapes");
00575     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00576 
00577     prop= RNA_def_property(srna, "size_y", PROP_FLOAT, PROP_DISTANCE);
00578     RNA_def_property_float_sdna(prop, NULL, "area_sizey");
00579     RNA_def_property_ui_range(prop, 0, 100, 0.1, 3);
00580     RNA_def_property_ui_text(prop, "Size Y", "Size of the area of the area Lamp in the Y direction for Rectangle shapes");
00581     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00582 
00583     prop= RNA_def_property(srna, "gamma", PROP_FLOAT, PROP_NONE);
00584     RNA_def_property_float_sdna(prop, NULL, "k");
00585     RNA_def_property_ui_range(prop, 0.001, 2.0, 0.1, 3);
00586     RNA_def_property_ui_text(prop, "Gamma", "Light gamma correction value");
00587     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00588 }
00589 
00590 static void rna_def_spot_lamp(BlenderRNA *brna)
00591 {
00592     StructRNA *srna;
00593     PropertyRNA *prop;
00594 
00595     static EnumPropertyItem prop_shadbuftype_items[] = {
00596         {LA_SHADBUF_REGULAR , "REGULAR", 0, "Classical", "Classic shadow buffer"},
00597         {LA_SHADBUF_HALFWAY, "HALFWAY", 0, "Classic-Halfway", "Regular buffer, averaging the closest and 2nd closest Z value to reducing bias artifacts"},
00598         {LA_SHADBUF_IRREGULAR, "IRREGULAR", 0, "Irregular", "Irregular buffer produces sharp shadow always, but it doesn't show up for raytracing"},
00599         {LA_SHADBUF_DEEP, "DEEP", 0, "Deep", "Deep shadow buffer supports transparency and better filtering, at the cost of more memory usage and processing time"},
00600         {0, NULL, 0, NULL, NULL}};
00601 
00602     static EnumPropertyItem prop_shadbuffiltertype_items[] = {
00603         {LA_SHADBUF_BOX , "BOX", 0, "Box", "Apply the Box filter to shadow buffer samples"},
00604         {LA_SHADBUF_TENT, "TENT", 0, "Tent", "Apply the Tent Filter to shadow buffer samples"},
00605         {LA_SHADBUF_GAUSS, "GAUSS", 0, "Gauss", "Apply the Gauss filter to shadow buffer samples"},
00606         {0, NULL, 0, NULL, NULL}};
00607 
00608     static EnumPropertyItem prop_numbuffer_items[] = {
00609         {1, "BUFFERS_1", 0, "1", "Only one buffer rendered"},
00610         {4, "BUFFERS_4", 0, "4", "Render 4 buffers for better AA, this quadruples memory usage"},
00611         {9, "BUFFERS_9", 0, "9", "Render 9 buffers for better AA, this uses nine times more memory"},
00612         {0, NULL, 0, NULL, NULL}};
00613 
00614     srna= RNA_def_struct(brna, "SpotLamp", "Lamp");
00615     RNA_def_struct_sdna(srna, "Lamp");
00616     RNA_def_struct_ui_text(srna, "Spot Lamp", "Directional cone lamp");
00617     RNA_def_struct_ui_icon(srna, ICON_LAMP_SPOT);
00618 
00619     rna_def_lamp_falloff(srna);
00620     rna_def_lamp_shadow(srna, 1, 0);
00621 
00622     prop= RNA_def_property(srna, "use_square", PROP_BOOLEAN, PROP_NONE);
00623     RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_SQUARE);
00624     RNA_def_property_ui_text(prop, "Square", "Cast a square spot light shape");
00625     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00626 
00627     prop= RNA_def_property(srna, "use_halo", PROP_BOOLEAN, PROP_NONE);
00628     RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_HALO);
00629     RNA_def_property_ui_text(prop, "Halo", "Render spotlight with a volumetric halo");
00630     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00631 
00632     prop= RNA_def_property(srna, "halo_intensity", PROP_FLOAT, PROP_NONE);
00633     RNA_def_property_float_sdna(prop, NULL, "haint");
00634     RNA_def_property_ui_range(prop, 0, 5.0, 0.1, 3);
00635     RNA_def_property_ui_text(prop, "Halo Intensity", "Brightness of the spotlight's halo cone");
00636     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00637 
00638     prop= RNA_def_property(srna, "halo_step", PROP_INT, PROP_NONE);
00639     RNA_def_property_int_sdna(prop, NULL, "shadhalostep");
00640     RNA_def_property_range(prop, 0, 12);
00641     RNA_def_property_ui_text(prop, "Halo Step", "Volumetric halo sampling frequency");
00642     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00643 
00644     prop= RNA_def_property(srna, "shadow_buffer_size", PROP_INT, PROP_NONE);
00645     RNA_def_property_int_sdna(prop, NULL, "bufsize");
00646     RNA_def_property_range(prop, 512, 10240);
00647     RNA_def_property_ui_text(prop, "Shadow Buffer Size", "Resolution of the shadow buffer, higher values give crisper shadows but use more memory");
00648     RNA_def_property_int_funcs(prop, NULL, "rna_Lamp_buffer_size_set", NULL);
00649     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00650 
00651     prop= RNA_def_property(srna, "shadow_filter_type", PROP_ENUM, PROP_NONE);
00652     RNA_def_property_enum_sdna(prop, NULL, "filtertype");
00653     RNA_def_property_enum_items(prop, prop_shadbuffiltertype_items);
00654     RNA_def_property_ui_text(prop, "Shadow Filter Type", "Type of shadow filter (Buffer Shadows)");
00655     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00656 
00657     prop= RNA_def_property(srna, "shadow_sample_buffers", PROP_ENUM, PROP_NONE);
00658     RNA_def_property_enum_sdna(prop, NULL, "buffers");
00659     RNA_def_property_enum_items(prop, prop_numbuffer_items);
00660     RNA_def_property_ui_text(prop, "Shadow Sample Buffers", "Number of shadow buffers to render for better AA, this increases memory usage");
00661     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00662 
00663     prop= RNA_def_property(srna, "spot_blend", PROP_FLOAT, PROP_NONE);
00664     RNA_def_property_float_sdna(prop, NULL, "spotblend");
00665     RNA_def_property_range(prop, 0.0f ,1.0f);
00666     RNA_def_property_ui_text(prop, "Spot Blend", "The softness of the spotlight edge");
00667     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00668 
00669     prop= RNA_def_property(srna, "spot_size", PROP_FLOAT, PROP_ANGLE);
00670     // RNA_def_property_float_sdna(prop, NULL, "spotsize");
00671     RNA_def_property_range(prop, M_PI/180.0, M_PI);
00672     RNA_def_property_ui_text(prop, "Spot Size", "Angle of the spotlight beam");
00673     RNA_def_property_float_funcs(prop, "rna_Lamp_spot_size_get", "rna_Lamp_spot_size_set", NULL); /* only for deg/rad conversion */
00674     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00675 
00676     prop= RNA_def_property(srna, "show_cone", PROP_BOOLEAN, PROP_NONE);
00677     RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_SHOW_CONE);
00678     RNA_def_property_ui_text(prop, "Show Cone", "Draw transparent cone in 3D view to visualize which objects are contained in it");
00679     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00680 
00681     prop= RNA_def_property(srna, "shadow_buffer_clip_start", PROP_FLOAT, PROP_DISTANCE);
00682     RNA_def_property_float_sdna(prop, NULL, "clipsta");
00683     RNA_def_property_range(prop, 0.0f, 9999.0f);
00684     RNA_def_property_ui_text(prop, "Shadow Buffer Clip Start", "Shadow map clip start, below which objects will not generate shadows");
00685     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00686 
00687     prop= RNA_def_property(srna, "shadow_buffer_clip_end", PROP_FLOAT, PROP_DISTANCE);
00688     RNA_def_property_float_sdna(prop, NULL, "clipend");
00689     RNA_def_property_range(prop, 0.0f, 9999.0f);
00690     RNA_def_property_ui_text(prop, "Shadow Buffer Clip End", "Shadow map clip end, beyond which objects will not generate shadows");
00691     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00692 
00693     prop= RNA_def_property(srna, "shadow_buffer_bias", PROP_FLOAT, PROP_NONE);
00694     RNA_def_property_float_sdna(prop, NULL, "bias");
00695     RNA_def_property_range(prop, 0.001f, 5.0f);
00696     RNA_def_property_ui_text(prop, "Shadow Buffer Bias", "Shadow buffer sampling bias");
00697     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00698 
00699     prop= RNA_def_property(srna, "shadow_buffer_soft", PROP_FLOAT, PROP_NONE);
00700     RNA_def_property_float_sdna(prop, NULL, "soft");
00701     RNA_def_property_range(prop, 0.0f, 100.0f);
00702     RNA_def_property_ui_text(prop, "Shadow Buffer Soft", "Size of shadow buffer sampling area");
00703     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00704 
00705     prop= RNA_def_property(srna, "shadow_buffer_samples", PROP_INT, PROP_NONE);
00706     RNA_def_property_int_sdna(prop, NULL, "samp");
00707     RNA_def_property_range(prop, 1, 16);
00708     RNA_def_property_ui_text(prop, "Samples", "Number of shadow buffer samples");
00709     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00710 
00711     prop= RNA_def_property(srna, "shadow_buffer_type", PROP_ENUM, PROP_NONE);
00712     RNA_def_property_enum_sdna(prop, NULL, "buftype");
00713     RNA_def_property_enum_items(prop, prop_shadbuftype_items);
00714     RNA_def_property_ui_text(prop, "Shadow Buffer Type", "Type of shadow buffer");
00715     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00716 
00717     prop= RNA_def_property(srna, "use_auto_clip_start", PROP_BOOLEAN, PROP_NONE);
00718     RNA_def_property_boolean_sdna(prop, NULL, "bufflag", LA_SHADBUF_AUTO_START);
00719     RNA_def_property_ui_text(prop, "Autoclip Start",  "Automatic calculation of clipping-start, based on visible vertices");
00720     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00721 
00722     prop= RNA_def_property(srna, "use_auto_clip_end", PROP_BOOLEAN, PROP_NONE);
00723     RNA_def_property_boolean_sdna(prop, NULL, "bufflag", LA_SHADBUF_AUTO_END);
00724     RNA_def_property_ui_text(prop, "Autoclip End", "Automatic calculation of clipping-end, based on visible vertices");
00725     RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
00726 
00727     prop= RNA_def_property(srna, "compression_threshold", PROP_FLOAT, PROP_NONE);
00728     RNA_def_property_float_sdna(prop, NULL, "compressthresh");
00729     RNA_def_property_range(prop, 0.0f, 1.0f);
00730     RNA_def_property_ui_text(prop, "Compress", "Deep shadow map compression threshold");
00731     RNA_def_property_update(prop, 0, "rna_Lamp_update");
00732 }
00733 
00734 static void rna_def_sun_lamp(BlenderRNA *brna)
00735 {
00736     StructRNA *srna;
00737     PropertyRNA *prop;
00738 
00739     srna= RNA_def_struct(brna, "SunLamp", "Lamp");
00740     RNA_def_struct_sdna(srna, "Lamp");
00741     RNA_def_struct_ui_text(srna, "Sun Lamp", "Constant direction parallel ray lamp");
00742     RNA_def_struct_ui_icon(srna, ICON_LAMP_SUN);
00743 
00744     rna_def_lamp_shadow(srna, 0, 0);
00745 
00746     /* sky */
00747     prop= RNA_def_property(srna, "sky", PROP_POINTER, PROP_NONE);
00748     RNA_def_property_flag(prop, PROP_NEVER_NULL);
00749     RNA_def_property_struct_type(prop, "LampSkySettings");
00750     RNA_def_property_pointer_funcs(prop, "rna_Lamp_sky_settings_get", NULL, NULL, NULL);
00751     RNA_def_property_ui_text(prop, "Sky Settings", "Sky related settings for sun lamps");
00752 
00753     rna_def_lamp_sky_settings(brna);
00754 }
00755 
00756 static void rna_def_hemi_lamp(BlenderRNA *brna)
00757 {
00758     StructRNA *srna;
00759 
00760     srna= RNA_def_struct(brna, "HemiLamp", "Lamp");
00761     RNA_def_struct_sdna(srna, "Lamp");
00762     RNA_def_struct_ui_text(srna, "Hemi Lamp", "180 degree constant lamp");
00763     RNA_def_struct_ui_icon(srna, ICON_LAMP_HEMI);
00764 }
00765 
00766 void RNA_def_lamp(BlenderRNA *brna)
00767 {
00768     rna_def_lamp(brna);
00769     rna_def_point_lamp(brna);
00770     rna_def_area_lamp(brna);
00771     rna_def_spot_lamp(brna);
00772     rna_def_sun_lamp(brna);
00773     rna_def_hemi_lamp(brna);
00774     rna_def_lamp_mtex(brna);
00775 }
00776 
00777 #endif
00778