Skip to content

Commit

Permalink
Simplify mix operator to only require a single weight
Browse files Browse the repository at this point in the history
  • Loading branch information
Achilleas Anagnostopoulos committed Oct 2, 2016
1 parent 2e3cd39 commit a9cfb94
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 39 deletions.
3 changes: 1 addition & 2 deletions asset/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,7 @@ func (sc *sceneCompiler) generateMaterialTree(mat *input.Material, exprNode mate
return -1, err
}

node.Union2[0] = t.Weights[0]
node.Union2[1] = t.Weights[1]
node.Union2[0] = t.Weight
case material.MixMapNode:
node.Union1[0] = int32(material.OpMixMap)
node.Union1[1], err = sc.generateMaterialTree(mat, t.Expressions[0])
Expand Down
4 changes: 2 additions & 2 deletions asset/material/material_expr.y
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ float_or_name: tokFLOAT { $$ = FloatNode($1) }
float_or_texture: tokFLOAT { $$ = FloatNode($1) }
| tokTEXTURE { $$ = TextureNode($1) }

op_spec: tokMIX tokLPAREN bxdf_or_op_spec tokCOMMA bxdf_or_op_spec tokCOMMA tokFLOAT tokCOMMA tokFLOAT tokRPAREN
op_spec: tokMIX tokLPAREN bxdf_or_op_spec tokCOMMA bxdf_or_op_spec tokCOMMA tokFLOAT tokRPAREN
{
$$ = MixNode{
Expressions: [2]ExprNode{$3, $5},
Weights: [2]float32{$7, $9},
Weight: $7,
}
}
| tokMIX_MAP tokLPAREN bxdf_or_op_spec tokCOMMA bxdf_or_op_spec tokCOMMA tokTEXTURE tokRPAREN
Expand Down
51 changes: 25 additions & 26 deletions asset/material/material_expr.y.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,40 +312,39 @@ const exprPrivate = 57344
var exprTokenNames []string
var exprStates []string

const exprLast = 111
const exprLast = 109

var exprAct = [...]int{

58, 33, 64, 57, 24, 25, 26, 27, 28, 29,
30, 31, 32, 93, 36, 76, 70, 85, 71, 75,
30, 31, 32, 92, 36, 76, 70, 85, 71, 75,
37, 38, 39, 40, 10, 11, 12, 13, 14, 15,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 5, 6, 7, 8, 9, 60, 56, 61, 62,
63, 67, 59, 72, 73, 74, 65, 66, 94, 92,
87, 84, 77, 68, 96, 82, 50, 49, 48, 47,
46, 45, 44, 43, 91, 90, 88, 83, 79, 78,
55, 54, 53, 86, 52, 51, 42, 97, 60, 99,
95, 89, 81, 80, 41, 21, 20, 98, 19, 18,
17, 16, 34, 2, 35, 3, 4, 23, 22, 69,
1,
63, 67, 59, 72, 73, 74, 65, 66, 93, 87,
84, 77, 68, 94, 82, 50, 49, 48, 47, 46,
45, 44, 43, 91, 90, 83, 79, 78, 55, 54,
53, 52, 51, 86, 42, 95, 60, 97, 89, 88,
81, 80, 41, 21, 20, 96, 19, 18, 17, 16,
34, 2, 35, 3, 4, 23, 22, 69, 1,
}
var exprPact = [...]int{

14, -1000, -1000, -1000, 97, 96, 95, 94, 92, 91,
14, -1000, -1000, -1000, 95, 94, 93, 92, 90, 89,
-1000, -1000, -1000, -1000, -1000, -1000, -8, 3, 3, 3,
3, 3, 89, 78, -1000, 64, 63, 62, 61, 60,
59, 58, 57, 77, -1000, -1000, -1000, 76, 74, 73,
72, -1000, -8, 40, 40, 40, 40, 46, 46, 53,
3, 3, 87, 76, -1000, 63, 62, 61, 60, 59,
58, 57, 56, 74, -1000, -1000, -1000, 73, 72, 71,
70, -1000, -8, 40, 40, 40, 40, 46, 46, 52,
6, 3, 3, 43, 7, -2, -1000, -1000, -1000, -1000,
52, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, 71, 70, 88, 87, 56, 69, 51, 5,
-1000, -1000, 82, 50, 68, 86, 67, 66, 49, -1000,
-5, 48, 85, 55, 80, -1000, 82, -1000, 84, -1000,
51, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, 69, 68, 86, 85, 55, 67, 50, 5,
-1000, -1000, 80, 49, 84, 83, 66, 65, -1000, -1000,
-5, 48, 54, 78, 80, -1000, 82, -1000,
}
var exprPgo = [...]int{

0, 110, 0, 4, 3, 2, 109, 104, 108, 107,
102, 1, 106,
0, 108, 0, 4, 3, 2, 107, 102, 106, 105,
100, 1, 104,
}
var exprR1 = [...]int{

Expand All @@ -358,7 +357,7 @@ var exprR2 = [...]int{

0, 1, 1, 4, 1, 1, 1, 1, 1, 1,
0, 1, 1, 3, 3, 3, 3, 3, 3, 3,
3, 3, 1, 1, 7, 1, 1, 1, 1, 10,
3, 3, 1, 1, 7, 1, 1, 1, 1, 8,
8, 6, 6, 12, 1, 1, 1,
}
var exprChk = [...]int{
Expand All @@ -371,8 +370,8 @@ var exprChk = [...]int{
9, 8, 8, 8, 8, 8, -3, -4, -2, 12,
6, -4, -4, -4, -5, 10, 11, -5, 10, -6,
10, 12, -11, -11, 12, 12, 17, 10, 8, 8,
5, 5, 9, 8, 10, 12, -2, 10, 8, 5,
8, 8, 10, 18, 10, 5, 9, 7, -2, 5,
5, 5, 9, 8, 10, 12, -2, 10, 5, 5,
8, 8, 18, 10, 9, 7, -2, 5,
}
var exprDef = [...]int{

Expand All @@ -384,8 +383,8 @@ var exprDef = [...]int{
0, 0, 0, 0, 0, 0, 13, 14, 22, 23,
0, 15, 16, 17, 18, 25, 26, 19, 20, 21,
27, 28, 0, 0, 0, 0, 0, 0, 0, 0,
31, 32, 0, 0, 0, 0, 0, 0, 0, 30,
0, 0, 0, 0, 0, 29, 0, 24, 0, 33,
31, 32, 0, 0, 0, 0, 0, 0, 29, 30,
0, 0, 0, 0, 0, 24, 0, 33,
}
var exprTok1 = [...]int{

Expand Down Expand Up @@ -862,12 +861,12 @@ exprdefault:
exprVAL.node = TextureNode(exprDollar[1].sVal)
}
case 29:
exprDollar = exprS[exprpt-10 : exprpt+1]
exprDollar = exprS[exprpt-8 : exprpt+1]
//line material_expr.y:135
{
exprVAL.node = MixNode{
Expressions: [2]ExprNode{exprDollar[3].node, exprDollar[5].node},
Weights: [2]float32{exprDollar[7].fVal, exprDollar[9].fVal},
Weight: exprDollar[7].fVal,
}
}
case 30:
Expand Down
9 changes: 3 additions & 6 deletions asset/material/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type BxdfParameterList []BxdfParamNode

type MixNode struct {
Expressions [2]ExprNode
Weights [2]float32
Weight float32
}

type BumpMapNode struct {
Expand Down Expand Up @@ -227,13 +227,10 @@ func (n MixNode) Validate() error {
if err != nil {
return fmt.Errorf("mix argument %d: %v", argIndex, err)
}
if n.Weights[argIndex] < 0 || n.Weights[argIndex] > 1.0 {
return fmt.Errorf("mix weight %d: value must be in the [0, 1] range", argIndex)
}
}

if n.Weights[0]+n.Weights[1] != 1.0 {
return fmt.Errorf("mix weight sum must be equal to 1.0")
if n.Weight < 0 || n.Weight > 1.0 {
return fmt.Errorf("Mix: mix weight must be in the [0, 1] range")
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion asset/scene/optimized_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type MaterialNode struct {
// Layout:
// [0-3] reflectance or specularity or radiance
// [0-3] RGB intIORs for dispersion
// [0-2] blend weights
// [0] mix weight
Union2 types.Vec4

// Layout:
Expand Down
2 changes: 1 addition & 1 deletion tracer/opencl/CL/samplers/material_sampler.cl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void matSelectNode(__global Path *path, Surface *surface, float3 inRayDir, Mater
case MAT_OP_MIX:
// Depending on the sample, follow left or right
sample = randomGetSample2f(rndState);
node = materialNodes + (sample.x < node->mixWeights.x ? node->leftChild : node->rightChild);
node = materialNodes + (sample.x < node->mixWeight ? node->leftChild : node->rightChild);
break;
case MAT_OP_MIX_MAP:
// Sample weight from texture
Expand Down
2 changes: 1 addition & 1 deletion tracer/opencl/CL/types.cl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ typedef struct {
float3 intDispersionIORs;

// mix node
float2 mixWeights;
float mixWeight;
};

union {
Expand Down

0 comments on commit a9cfb94

Please sign in to comment.