diff options
author | IRIE Shinsuke <irieshinsuke@yahoo.co.jp> | 2013-11-25 15:58:23 +0400 |
---|---|---|
committer | IRIE Shinsuke <irieshinsuke@yahoo.co.jp> | 2013-11-25 17:19:47 +0400 |
commit | ab9822eff8865846d3c7ef81ff30cc35cb48ae0c (patch) | |
tree | 0955c1502f6f0327f59a3dd430c251378ba64c7c /source/blender/gpu/intern/gpu_material.c | |
parent | 33bc6a3959b4f59f6ded304b5db06733653051cd (diff) |
Blender Internal: Add "Lamp Data" shader node that allows shaders to acquire information such as light vector from specified Lamp.
For now this provides the following outputs:
- Color
- Light Vector
- Distance
- Shadow
- Visibility Factor
Note: Color output is multiplied by the lamp energy. Multiplication of
color*max(dot(light_vector,normal_vector),0)*shadow*visibility_factor
produces the exact same result as the Lambert shader.
Many thanks to Brecht for code review and discussion!
Diffstat (limited to 'source/blender/gpu/intern/gpu_material.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index ed7a2f4ede0..8e7194bb4a1 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -355,6 +355,11 @@ int GPU_material_bound(GPUMaterial *material) return material->bound; } +Scene *GPU_material_scene(GPUMaterial *material) +{ + return material->scene; +} + void GPU_material_vertex_attributes(GPUMaterial *material, GPUVertexAttribs *attribs) { *attribs = material->attribs; @@ -1953,6 +1958,48 @@ int GPU_lamp_shadow_layer(GPULamp *lamp) return -1; } +GPUNodeLink *GPU_lamp_get_data(GPUMaterial *mat, GPULamp *lamp, GPUNodeLink **col, GPUNodeLink **lv, GPUNodeLink **dist, GPUNodeLink **shadow) +{ + GPUNodeLink *visifac; + + *col = GPU_dynamic_uniform(lamp->dyncol, GPU_DYNAMIC_LAMP_DYNCOL, lamp->ob); + visifac = lamp_get_visibility(mat, lamp, lv, dist); + shade_light_textures(mat, lamp, col); + + if (GPU_lamp_has_shadow_buffer(lamp)) { + GPUNodeLink *vn, *inp; + + GPU_link(mat, "shade_norm", GPU_builtin(GPU_VIEW_NORMAL), &vn); + GPU_link(mat, "shade_inp", vn, *lv, &inp); + mat->dynproperty |= DYN_LAMP_PERSMAT; + + if (lamp->la->shadowmap_type == LA_SHADMAP_VARIANCE) { + GPU_link(mat, "shadows_only_vsm", + GPU_builtin(GPU_VIEW_POSITION), + GPU_dynamic_texture(lamp->tex, GPU_DYNAMIC_SAMPLER_2DSHADOW, lamp->ob), + GPU_dynamic_uniform((float*)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob), + GPU_uniform(&lamp->bias), GPU_uniform(&lamp->la->bleedbias), + GPU_uniform(lamp->shadow_color), inp, shadow); + } + else { + GPU_link(mat, "shadows_only", + GPU_builtin(GPU_VIEW_POSITION), + GPU_dynamic_texture(lamp->tex, GPU_DYNAMIC_SAMPLER_2DSHADOW, lamp->ob), + GPU_dynamic_uniform((float*)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob), + GPU_uniform(&lamp->bias), GPU_uniform(lamp->shadow_color), inp, shadow); + } + } + else { + GPU_link(mat, "set_rgb_one", shadow); + } + + /* ensure shadow buffer and lamp textures will be updated */ + add_user_list(&mat->lamps, lamp); + add_user_list(&lamp->materials, mat->ma); + + return visifac; +} + /* export the GLSL shader */ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma) |