69b22c555ab6cb316baf96682e1459607e5ba161
[blender.git] / release / scripts / ui / properties_data_lamp.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from rna_prop_ui import PropertyPanel
22
23 narrowui = bpy.context.user_preferences.view.properties_width_check
24
25
26 class LAMP_MT_sunsky_presets(bpy.types.Menu):
27     bl_label = "Sun & Sky Presets"
28     preset_subdir = "sunsky"
29     preset_operator = "script.execute_preset"
30     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
31     draw = bpy.types.Menu.draw_preset
32
33
34 class DataButtonsPanel():
35     bl_space_type = 'PROPERTIES'
36     bl_region_type = 'WINDOW'
37     bl_context = "data"
38
39
40 class DATA_PT_preview(DataButtonsPanel, bpy.types.Panel):
41     bl_label = "Preview"
42     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
43
44     @staticmethod
45     def poll(context):
46         engine = context.scene.render.engine
47         return context.lamp and (engine in __class__.COMPAT_ENGINES)
48
49     def draw(self, context):
50         self.layout.template_preview(context.lamp)
51
52 class DATA_PT_context_lamp(DataButtonsPanel, bpy.types.Panel):
53     bl_label = ""
54     bl_show_header = False
55     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
56
57     @staticmethod
58     def poll(context):
59         engine = context.scene.render.engine
60         return context.lamp and (engine in __class__.COMPAT_ENGINES)
61
62     def draw(self, context):
63         layout = self.layout
64
65         ob = context.object
66         lamp = context.lamp
67         space = context.space_data
68         wide_ui = context.region.width > narrowui
69
70         if wide_ui:
71             split = layout.split(percentage=0.65)
72             if ob:
73                 split.template_ID(ob, "data")
74                 split.separator()
75             elif lamp:
76                 split.template_ID(space, "pin_id")
77                 split.separator()
78         else:
79             if ob:
80                 layout.template_ID(ob, "data")
81             elif lamp:
82                 layout.template_ID(space, "pin_id")
83
84
85 class DATA_PT_custom_props_lamp(DataButtonsPanel, PropertyPanel, bpy.types.Panel):
86     _context_path = "object.data"
87     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
88
89     @staticmethod
90     def poll(context):
91         engine = context.scene.render.engine
92         return context.lamp and (engine in __class__.COMPAT_ENGINES)
93
94
95 class DATA_PT_lamp(DataButtonsPanel, bpy.types.Panel):
96     bl_label = "Lamp"
97     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
98
99     @staticmethod
100     def poll(context):
101         engine = context.scene.render.engine
102         return context.lamp and (engine in __class__.COMPAT_ENGINES)
103
104     def draw(self, context):
105         layout = self.layout
106
107         lamp = context.lamp
108         wide_ui = context.region.width > narrowui
109
110         if wide_ui:
111             layout.prop(lamp, "type", expand=True)
112         else:
113             layout.prop(lamp, "type", text="")
114
115         split = layout.split()
116
117         col = split.column()
118         sub = col.column()
119         sub.prop(lamp, "color", text="")
120         sub.prop(lamp, "energy")
121
122         if lamp.type in ('POINT', 'SPOT'):
123             sub.label(text="Falloff:")
124             sub.prop(lamp, "falloff_type", text="")
125             sub.prop(lamp, "distance")
126
127             if lamp.falloff_type == 'LINEAR_QUADRATIC_WEIGHTED':
128                 col.label(text="Attenuation Factors:")
129                 sub = col.column(align=True)
130                 sub.prop(lamp, "linear_attenuation", slider=True, text="Linear")
131                 sub.prop(lamp, "quadratic_attenuation", slider=True, text="Quadratic")
132
133             col.prop(lamp, "sphere")
134
135         if lamp.type == 'AREA':
136             col.prop(lamp, "distance")
137             col.prop(lamp, "gamma")
138
139         if wide_ui:
140             col = split.column()
141         col.prop(lamp, "negative")
142         col.prop(lamp, "layer", text="This Layer Only")
143         col.prop(lamp, "specular")
144         col.prop(lamp, "diffuse")
145
146
147 class DATA_PT_sunsky(DataButtonsPanel, bpy.types.Panel):
148     bl_label = "Sky & Atmosphere"
149     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
150
151     @staticmethod
152     def poll(context):
153         lamp = context.lamp
154         engine = context.scene.render.engine
155         return (lamp and lamp.type == 'SUN') and (engine in __class__.COMPAT_ENGINES)
156
157     def draw(self, context):
158         layout = self.layout
159
160         lamp = context.lamp.sky
161         wide_ui = context.region.width > narrowui
162
163         row = layout.row(align=True)
164         row.prop(lamp, "use_sky")
165         row.menu("LAMP_MT_sunsky_presets", text=bpy.types.LAMP_MT_sunsky_presets.bl_label)
166         row.operator("lamp.sunsky_preset_add", text="", icon="ZOOMIN")
167
168         row = layout.row()
169         row.active = lamp.use_sky or lamp.use_atmosphere
170         row.prop(lamp, "atmosphere_turbidity", text="Turbidity")
171
172         split = layout.split()
173
174         col = split.column()
175         col.active = lamp.use_sky
176         col.label(text="Blending:")
177         sub = col.column()
178         sub.prop(lamp, "sky_blend_type", text="")
179         sub.prop(lamp, "sky_blend", text="Factor")
180
181         col.label(text="Color Space:")
182         sub = col.column()
183         sub.row().prop(lamp, "sky_color_space", expand=True)
184         sub.prop(lamp, "sky_exposure", text="Exposure")
185
186         if wide_ui:
187             col = split.column()
188         col.active = lamp.use_sky
189         col.label(text="Horizon:")
190         sub = col.column()
191         sub.prop(lamp, "horizon_brightness", text="Brightness")
192         sub.prop(lamp, "spread", text="Spread")
193
194         col.label(text="Sun:")
195         sub = col.column()
196         sub.prop(lamp, "sun_brightness", text="Brightness")
197         sub.prop(lamp, "sun_size", text="Size")
198         sub.prop(lamp, "backscattered_light", slider=True, text="Back Light")
199
200         layout.separator()
201
202         layout.prop(lamp, "use_atmosphere")
203
204         split = layout.split()
205
206         col = split.column()
207         col.active = lamp.use_atmosphere
208         col.label(text="Intensity:")
209         col.prop(lamp, "sun_intensity", text="Sun")
210         col.prop(lamp, "atmosphere_distance_factor", text="Distance")
211
212         if wide_ui:
213             col = split.column()
214         col.active = lamp.use_atmosphere
215         col.label(text="Scattering:")
216         sub = col.column(align=True)
217         sub.prop(lamp, "atmosphere_inscattering", slider=True, text="Inscattering")
218         sub.prop(lamp, "atmosphere_extinction", slider=True, text="Extinction")
219
220
221 class DATA_PT_shadow(DataButtonsPanel, bpy.types.Panel):
222     bl_label = "Shadow"
223     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
224
225     @staticmethod
226     def poll(context):
227         lamp = context.lamp
228         engine = context.scene.render.engine
229         return (lamp and lamp.type in ('POINT', 'SUN', 'SPOT', 'AREA')) and (engine in __class__.COMPAT_ENGINES)
230
231     def draw(self, context):
232         layout = self.layout
233
234         lamp = context.lamp
235         wide_ui = context.region.width > narrowui
236
237         if wide_ui:
238             layout.prop(lamp, "shadow_method", expand=True)
239         else:
240             layout.prop(lamp, "shadow_method", text="")
241
242         if lamp.shadow_method == 'NOSHADOW' and lamp.type == 'AREA':
243             split = layout.split()
244
245             col= split.column()
246             col.label(text="Form factor sampling:")
247             
248             if wide_ui:
249                 sub=col.row(align=True)
250             else:
251                 sub=col.column(align=True)
252
253             if lamp.shape == 'SQUARE':
254                 sub.prop(lamp, "shadow_ray_samples_x", text="Samples")
255             elif lamp.shape == 'RECTANGLE':
256                 sub.prop(lamp, "shadow_ray_samples_x", text="Samples X")
257                 sub.prop(lamp, "shadow_ray_samples_y", text="Samples Y")
258
259         if lamp.shadow_method != 'NOSHADOW':
260             split = layout.split()
261
262             col = split.column()
263             col.prop(lamp, "shadow_color", text="")
264
265             if wide_ui:
266                 col = split.column()
267             col.prop(lamp, "shadow_layer", text="This Layer Only")
268             col.prop(lamp, "only_shadow")
269
270         if lamp.shadow_method == 'RAY_SHADOW':
271             split = layout.split()
272             
273             col = split.column()
274             col.label(text="Sampling:")
275             
276             if lamp.type in ('POINT', 'SUN', 'SPOT'):
277                 if wide_ui:
278                     sub=col.row()
279                 else:
280                     sub=col.column()
281                 
282                 sub.prop(lamp, "shadow_ray_samples", text="Samples")
283                 sub.prop(lamp, "shadow_soft_size", text="Soft Size")
284                 
285             elif lamp.type == 'AREA':
286                 if wide_ui:
287                     sub=col.row(align=True)
288                 else:
289                     sub=col.column(align=True)
290                 
291                 if lamp.shape == 'SQUARE':
292                     sub.prop(lamp, "shadow_ray_samples_x", text="Samples")
293                 elif lamp.shape == 'RECTANGLE':
294                     sub.prop(lamp, "shadow_ray_samples_x", text="Samples X")
295                     sub.prop(lamp, "shadow_ray_samples_y", text="Samples Y")
296
297             if wide_ui:
298                 col.row().prop(lamp, "shadow_ray_sampling_method", expand=True)
299             else:
300                 col.prop(lamp, "shadow_ray_sampling_method", text="")                
301
302             split = layout.split()
303             col = split.column()
304             
305             if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
306                 col.prop(lamp, "shadow_adaptive_threshold", text="Threshold")
307                 if wide_ui:
308                     col = split.column()
309             
310             if lamp.type == 'AREA' and lamp.shadow_ray_sampling_method == 'CONSTANT_JITTERED':
311                 col = split.column()
312                 col = split.column()
313                 col.prop(lamp, "umbra")
314                 col.prop(lamp, "dither")
315                 col.prop(lamp, "jitter")
316
317         elif lamp.shadow_method == 'BUFFER_SHADOW':
318             col = layout.column()
319             col.label(text="Buffer Type:")
320             if wide_ui:
321                 col.row().prop(lamp, "shadow_buffer_type", expand=True)
322             else:
323                 col.row().prop(lamp, "shadow_buffer_type", text="")
324
325             if lamp.shadow_buffer_type in ('REGULAR', 'HALFWAY', 'DEEP'):
326                 split = layout.split()
327
328                 col = split.column()
329                 col.label(text="Filter Type:")
330                 col.prop(lamp, "shadow_filter_type", text="")
331                 sub = col.column(align=True)
332                 sub.prop(lamp, "shadow_buffer_soft", text="Soft")
333                 sub.prop(lamp, "shadow_buffer_bias", text="Bias")
334
335                 if wide_ui:
336                     col = split.column()
337                 col.label(text="Sample Buffers:")
338                 col.prop(lamp, "shadow_sample_buffers", text="")
339                 sub = col.column(align=True)
340                 sub.prop(lamp, "shadow_buffer_size", text="Size")
341                 sub.prop(lamp, "shadow_buffer_samples", text="Samples")
342                 if lamp.shadow_buffer_type == 'DEEP':
343                     col.prop(lamp, "compression_threshold")
344
345             elif lamp.shadow_buffer_type == 'IRREGULAR':
346                 layout.prop(lamp, "shadow_buffer_bias", text="Bias")
347
348             split = layout.split()
349
350             col = split.column()
351             col.prop(lamp, "auto_clip_start", text="Autoclip Start")
352             sub = col.column()
353             sub.active = not lamp.auto_clip_start
354             sub.prop(lamp, "shadow_buffer_clip_start", text="Clip Start")
355
356             if wide_ui:
357                 col = split.column()
358             col.prop(lamp, "auto_clip_end", text="Autoclip End")
359             sub = col.column()
360             sub.active = not lamp.auto_clip_end
361             sub.prop(lamp, "shadow_buffer_clip_end", text=" Clip End")
362
363
364 class DATA_PT_area(DataButtonsPanel, bpy.types.Panel):
365     bl_label = "Area Shape"
366     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
367
368     @staticmethod
369     def poll(context):
370         lamp = context.lamp
371         engine = context.scene.render.engine
372         return (lamp and lamp.type == 'AREA') and (engine in __class__.COMPAT_ENGINES)
373
374     def draw(self, context):
375         lamp = context.lamp
376         wide_ui = context.region.width > narrowui
377
378         layout = self.layout
379         split = layout.split()
380
381         col = split.column()
382         
383         if wide_ui:
384             col.row().prop(lamp, "shape", expand=True)
385             sub = col.row(align=True)
386         else:
387             col.prop(lamp, "shape", text="")
388             sub = col.column(align=True)
389
390         if (lamp.shape == 'SQUARE'):
391             sub.prop(lamp, "size")
392         elif (lamp.shape == 'RECTANGLE'):
393             sub.prop(lamp, "size", text="Size X")
394             sub.prop(lamp, "size_y", text="Size Y")
395
396
397 class DATA_PT_spot(DataButtonsPanel, bpy.types.Panel):
398     bl_label = "Spot Shape"
399     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
400
401     @staticmethod
402     def poll(context):
403         lamp = context.lamp
404         engine = context.scene.render.engine
405         return (lamp and lamp.type == 'SPOT') and (engine in __class__.COMPAT_ENGINES)
406
407     def draw(self, context):
408         layout = self.layout
409
410         lamp = context.lamp
411         wide_ui = context.region.width > narrowui
412
413         split = layout.split()
414
415         col = split.column()
416         sub = col.column()
417         sub.prop(lamp, "spot_size", text="Size")
418         sub.prop(lamp, "spot_blend", text="Blend", slider=True)
419         col.prop(lamp, "square")
420         col.prop(lamp, "show_cone")
421
422         if wide_ui:
423             col = split.column()
424         else:
425             col.separator()
426         col.prop(lamp, "halo")
427         sub = col.column(align=True)
428         sub.active = lamp.halo
429         sub.prop(lamp, "halo_intensity", text="Intensity")
430         if lamp.shadow_method == 'BUFFER_SHADOW':
431             sub.prop(lamp, "halo_step", text="Step")
432
433
434 class DATA_PT_falloff_curve(DataButtonsPanel, bpy.types.Panel):
435     bl_label = "Falloff Curve"
436     bl_default_closed = True
437     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
438
439     @staticmethod
440     def poll(context):
441         lamp = context.lamp
442         engine = context.scene.render.engine
443
444         return (lamp and lamp.type in ('POINT', 'SPOT') and lamp.falloff_type == 'CUSTOM_CURVE') and (engine in __class__.COMPAT_ENGINES)
445
446     def draw(self, context):
447         lamp = context.lamp
448
449         self.layout.template_curve_mapping(lamp, "falloff_curve")
450
451
452 def register():
453     pass
454
455
456 def unregister():
457     pass
458
459 if __name__ == "__main__":
460     register()