Cycles: fix some issues with mix shaders when the weight for an emission shader
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 19 Oct 2011 00:13:41 +0000 (00:13 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 19 Oct 2011 00:13:41 +0000 (00:13 +0000)
was 0.0, and background shader mix wasn't working.

intern/cycles/blender/addon/ui.py
intern/cycles/kernel/svm/svm.h
intern/cycles/kernel/svm/svm_closure.h
intern/cycles/render/nodes.cpp

index 10754ed6b9f59ec06504e20b3de12508883553aa..94a48e6c42d02c68f959ceedffe63beff001de2c 100644 (file)
@@ -431,6 +431,7 @@ class CyclesWorld_PT_surface(CyclesButtonsPanel, Panel):
 class CyclesWorld_PT_volume(CyclesButtonsPanel, Panel):
     bl_label = "Volume"
     bl_context = "world"
+    bl_options = {'DEFAULT_CLOSED'}
 
     @classmethod
     def poll(cls, context):
@@ -460,6 +461,7 @@ class CyclesMaterial_PT_surface(CyclesButtonsPanel, Panel):
 class CyclesMaterial_PT_volume(CyclesButtonsPanel, Panel):
     bl_label = "Volume"
     bl_context = "material"
+    bl_options = {'DEFAULT_CLOSED'}
 
     @classmethod
     def poll(cls, context):
index 62e02f1a01a98ddd55691869872b33d574894ee9..9628f96bcab18dbf4c74d5215b5b86e7005803e6 100644 (file)
@@ -179,7 +179,7 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT
                                svm_node_closure_emission(sd, stack, node);
                                break;
                        case NODE_CLOSURE_BACKGROUND:
-                               svm_node_closure_background(sd, node);
+                               svm_node_closure_background(sd, stack, node);
                                break;
                        case NODE_CLOSURE_HOLDOUT:
                                svm_node_closure_holdout(sd, stack, node);
index 90636380e43906c72f68495820ccaf7bf4370180..fcda7ac6fe1c0289fa0d82f5061ba7ab24af9bae 100644 (file)
@@ -236,7 +236,6 @@ __device void svm_node_closure_volume(KernelGlobals *kg, ShaderData *sd, float *
 __device void svm_node_closure_emission(ShaderData *sd, float *stack, uint4 node)
 {
 #ifdef __MULTI_CLOSURE__
-       ShaderClosure *sc = svm_node_closure_get(sd);
        uint mix_weight_offset = node.y;
 
        if(stack_valid(mix_weight_offset)) {
@@ -245,31 +244,52 @@ __device void svm_node_closure_emission(ShaderData *sd, float *stack, uint4 node
                if(mix_weight == 0.0f)
                        return;
 
+               ShaderClosure *sc = svm_node_closure_get(sd);
                sc->weight *= mix_weight;
+               sc->type = CLOSURE_EMISSION_ID;
        }
+       else {
+               ShaderClosure *sc = svm_node_closure_get(sd);
+               sc->type = CLOSURE_EMISSION_ID;
+       }
+
 #else
        ShaderClosure *sc = &sd->closure;
+       sc->type = CLOSURE_EMISSION_ID;
 #endif
 
-       sc->type = CLOSURE_EMISSION_ID;
        sd->flag |= SD_EMISSION;
 }
 
-__device void svm_node_closure_background(ShaderData *sd, uint4 node)
+__device void svm_node_closure_background(ShaderData *sd, float *stack, uint4 node)
 {
 #ifdef __MULTI_CLOSURE__
-       ShaderClosure *sc = svm_node_closure_get(sd);
+       uint mix_weight_offset = node.y;
+
+       if(stack_valid(mix_weight_offset)) {
+               float mix_weight = stack_load_float(stack, mix_weight_offset);
+
+               if(mix_weight == 0.0f)
+                       return;
+
+               ShaderClosure *sc = svm_node_closure_get(sd);
+               sc->weight *= mix_weight;
+               sc->type = CLOSURE_BACKGROUND_ID;
+       }
+       else {
+               ShaderClosure *sc = svm_node_closure_get(sd);
+               sc->type = CLOSURE_BACKGROUND_ID;
+       }
+
 #else
        ShaderClosure *sc = &sd->closure;
-#endif
-
        sc->type = CLOSURE_BACKGROUND_ID;
+#endif
 }
 
 __device void svm_node_closure_holdout(ShaderData *sd, float *stack, uint4 node)
 {
 #ifdef __MULTI_CLOSURE__
-       ShaderClosure *sc = svm_node_closure_get(sd);
        uint mix_weight_offset = node.y;
 
        if(stack_valid(mix_weight_offset)) {
@@ -278,17 +298,20 @@ __device void svm_node_closure_holdout(ShaderData *sd, float *stack, uint4 node)
                if(mix_weight == 0.0f)
                        return;
 
+               ShaderClosure *sc = svm_node_closure_get(sd);
                sc->weight = make_float3(mix_weight, mix_weight, mix_weight);
+               sc->type = CLOSURE_HOLDOUT_ID;
        }
-       else
+       else {
+               ShaderClosure *sc = svm_node_closure_get(sd);
                sc->weight = make_float3(1.0f, 1.0f, 1.0f);
-
-       sc->sample_weight = 0.0f;
+               sc->type = CLOSURE_HOLDOUT_ID;
+       }
 #else
        ShaderClosure *sc = &sd->closure;
+       sc->type = CLOSURE_HOLDOUT_ID;
 #endif
 
-       sc->type = CLOSURE_HOLDOUT_ID;
        sd->flag |= SD_HOLDOUT;
 }
 
index e6aff8590ad008277da349367b279728da1cc14a..9c72c01417add20dac44a412fd993b05e605d268 100644 (file)
@@ -1370,7 +1370,7 @@ void BackgroundNode::compile(SVMCompiler& compiler)
        else
                compiler.add_node(NODE_CLOSURE_SET_WEIGHT, color_in->value*strength_in->value.x);
 
-       compiler.add_node(NODE_CLOSURE_BACKGROUND, CLOSURE_BACKGROUND_ID);
+       compiler.add_node(NODE_CLOSURE_BACKGROUND, compiler.closure_mix_weight_offset());
 }
 
 void BackgroundNode::compile(OSLCompiler& compiler)