Cycles: fix some issues with mix shaders when the weight for an emission shader

was 0.0, and background shader mix wasn't working.
This commit is contained in:
Brecht Van Lommel 2011-10-19 00:13:41 +00:00
parent 97e58e499d
commit 72e47de8b5
4 changed files with 38 additions and 13 deletions

@ -431,6 +431,7 @@ class CyclesWorld_PT_surface(CyclesButtonsPanel, Panel):
class CyclesWorld_PT_volume(CyclesButtonsPanel, Panel): class CyclesWorld_PT_volume(CyclesButtonsPanel, Panel):
bl_label = "Volume" bl_label = "Volume"
bl_context = "world" bl_context = "world"
bl_options = {'DEFAULT_CLOSED'}
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
@ -460,6 +461,7 @@ class CyclesMaterial_PT_surface(CyclesButtonsPanel, Panel):
class CyclesMaterial_PT_volume(CyclesButtonsPanel, Panel): class CyclesMaterial_PT_volume(CyclesButtonsPanel, Panel):
bl_label = "Volume" bl_label = "Volume"
bl_context = "material" bl_context = "material"
bl_options = {'DEFAULT_CLOSED'}
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):

@ -179,7 +179,7 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT
svm_node_closure_emission(sd, stack, node); svm_node_closure_emission(sd, stack, node);
break; break;
case NODE_CLOSURE_BACKGROUND: case NODE_CLOSURE_BACKGROUND:
svm_node_closure_background(sd, node); svm_node_closure_background(sd, stack, node);
break; break;
case NODE_CLOSURE_HOLDOUT: case NODE_CLOSURE_HOLDOUT:
svm_node_closure_holdout(sd, stack, node); svm_node_closure_holdout(sd, stack, node);

@ -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) __device void svm_node_closure_emission(ShaderData *sd, float *stack, uint4 node)
{ {
#ifdef __MULTI_CLOSURE__ #ifdef __MULTI_CLOSURE__
ShaderClosure *sc = svm_node_closure_get(sd);
uint mix_weight_offset = node.y; uint mix_weight_offset = node.y;
if(stack_valid(mix_weight_offset)) { 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) if(mix_weight == 0.0f)
return; return;
ShaderClosure *sc = svm_node_closure_get(sd);
sc->weight *= mix_weight; sc->weight *= mix_weight;
sc->type = CLOSURE_EMISSION_ID;
} }
else {
ShaderClosure *sc = svm_node_closure_get(sd);
sc->type = CLOSURE_EMISSION_ID;
}
#else #else
ShaderClosure *sc = &sd->closure; ShaderClosure *sc = &sd->closure;
sc->type = CLOSURE_EMISSION_ID;
#endif #endif
sc->type = CLOSURE_EMISSION_ID;
sd->flag |= SD_EMISSION; 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__ #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 #else
ShaderClosure *sc = &sd->closure; ShaderClosure *sc = &sd->closure;
#endif
sc->type = CLOSURE_BACKGROUND_ID; sc->type = CLOSURE_BACKGROUND_ID;
#endif
} }
__device void svm_node_closure_holdout(ShaderData *sd, float *stack, uint4 node) __device void svm_node_closure_holdout(ShaderData *sd, float *stack, uint4 node)
{ {
#ifdef __MULTI_CLOSURE__ #ifdef __MULTI_CLOSURE__
ShaderClosure *sc = svm_node_closure_get(sd);
uint mix_weight_offset = node.y; uint mix_weight_offset = node.y;
if(stack_valid(mix_weight_offset)) { 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) if(mix_weight == 0.0f)
return; return;
ShaderClosure *sc = svm_node_closure_get(sd);
sc->weight = make_float3(mix_weight, mix_weight, mix_weight); 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->weight = make_float3(1.0f, 1.0f, 1.0f);
sc->type = CLOSURE_HOLDOUT_ID;
sc->sample_weight = 0.0f; }
#else #else
ShaderClosure *sc = &sd->closure; ShaderClosure *sc = &sd->closure;
sc->type = CLOSURE_HOLDOUT_ID;
#endif #endif
sc->type = CLOSURE_HOLDOUT_ID;
sd->flag |= SD_HOLDOUT; sd->flag |= SD_HOLDOUT;
} }

@ -1370,7 +1370,7 @@ void BackgroundNode::compile(SVMCompiler& compiler)
else else
compiler.add_node(NODE_CLOSURE_SET_WEIGHT, color_in->value*strength_in->value.x); 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) void BackgroundNode::compile(OSLCompiler& compiler)