@@ -48,6 +48,14 @@ void HwSurfaceNode::createVariables(const ShaderNode&, GenContext& context, Shad
4848void HwSurfaceNode::emitFunctionCall (const ShaderNode& node, GenContext& context, ShaderStage& stage) const
4949{
5050 const HwShaderGenerator& shadergen = static_cast <const HwShaderGenerator&>(context.getShaderGenerator ());
51+ const Syntax& syntax = shadergen.getSyntax ();
52+
53+ const string& vec2 = syntax.getTypeName (Type::VECTOR2);
54+ const string& vec3 = syntax.getTypeName (Type::VECTOR3);
55+ const string vec2_zero = syntax.getValue (Type::VECTOR2, HW::VEC3_ZERO);
56+ const string vec2_one = syntax.getValue (Type::VECTOR2, HW::VEC3_ONE);
57+ const string vec3_zero = syntax.getValue (Type::VECTOR3, HW::VEC3_ZERO);
58+ const string vec3_one = syntax.getValue (Type::VECTOR3, HW::VEC3_ONE);
5159
5260 DEFINE_SHADER_STAGE (stage, Stage::VERTEX)
5361 {
@@ -63,7 +71,7 @@ void HwSurfaceNode::emitFunctionCall(const ShaderNode& node, GenContext& context
6371 if (!normal->isEmitted ())
6472 {
6573 normal->setEmitted ();
66- shadergen.emitLine (prefix + normal->getVariable () + " = normalize(mx_matrix_mul(" + HW::T_WORLD_INVERSE_TRANSPOSE_MATRIX + " , vec4 (" + HW::T_IN_NORMAL + " , 0)).xyz)" , stage);
74+ shadergen.emitLine (prefix + normal->getVariable () + " = normalize(mx_matrix_mul(" + HW::T_WORLD_INVERSE_TRANSPOSE_MATRIX + " , " +syntax. getTypeName (Type::VECTOR4)+ " (" + HW::T_IN_NORMAL + " , 0)).xyz)" , stage);
6775 }
6876 if (context.getOptions ().hwAmbientOcclusion )
6977 {
@@ -89,10 +97,10 @@ void HwSurfaceNode::emitFunctionCall(const ShaderNode& node, GenContext& context
8997
9098 shadergen.emitScopeBegin (stage);
9199
92- shadergen.emitLine (" vec3 N = normalize(" + prefix + HW::T_NORMAL_WORLD + " )" , stage);
93- shadergen.emitLine (" vec3 V = normalize(" + HW::T_VIEW_POSITION + " - " + prefix + HW::T_POSITION_WORLD + " )" , stage);
94- shadergen.emitLine (" vec3 P = " + prefix + HW::T_POSITION_WORLD, stage);
95- shadergen.emitLine (" vec3 L = vec3(0,0,0); " , stage);
100+ shadergen.emitLine (vec3+ " N = normalize(" + prefix + HW::T_NORMAL_WORLD + " )" , stage);
101+ shadergen.emitLine (vec3+ " V = normalize(" + HW::T_VIEW_POSITION + " - " + prefix + HW::T_POSITION_WORLD + " )" , stage);
102+ shadergen.emitLine (vec3+ " P = " + prefix + HW::T_POSITION_WORLD, stage);
103+ shadergen.emitLine (vec3+ " L = " +vec3_zero , stage);
96104 shadergen.emitLine (" float occlusion = 1.0" , stage);
97105 shadergen.emitLineBreak (stage);
98106
@@ -127,10 +135,10 @@ void HwSurfaceNode::emitFunctionCall(const ShaderNode& node, GenContext& context
127135 if (context.getOptions ().hwAmbientOcclusion )
128136 {
129137 ShaderPort* texcoord = vertexData[HW::T_TEXCOORD + " _0" ];
130- shadergen.emitLine (" vec2 ambOccUv = " + prefix + texcoord->getVariable (), stage);
138+ shadergen.emitLine (vec2+ " ambOccUv = " + prefix + texcoord->getVariable (), stage);
131139 if (context.getOptions ().fileTextureVerticalFlip )
132140 {
133- shadergen.emitLine (" ambOccUv = vec2(ambOccUv.x, 1.0 - ambOccUv.y)" , stage);
141+ shadergen.emitLine (" ambOccUv = " + vec2+ " (ambOccUv.x, 1.0 - ambOccUv.y)" , stage);
134142 }
135143 shadergen.emitLine (" occlusion = mix(1.0, texture(" + HW::T_AMB_OCC_MAP + " , ambOccUv).x, " + HW::T_AMB_OCC_GAIN + " )" , stage);
136144 }
@@ -219,7 +227,7 @@ void HwSurfaceNode::emitFunctionCall(const ShaderNode& node, GenContext& context
219227 shadergen.emitComment (" Compute and apply surface opacity" , stage);
220228 shadergen.emitScopeBegin (stage);
221229 shadergen.emitLine (outColor + " *= surfaceOpacity" , stage);
222- shadergen.emitLine (outTransparency + " = mix(vec3(1.0) , " + outTransparency + " , surfaceOpacity)" , stage);
230+ shadergen.emitLine (outTransparency + " = mix(" +vec3_one+ " , " + outTransparency + " , surfaceOpacity)" , stage);
223231 shadergen.emitScopeEnd (stage);
224232 }
225233
0 commit comments