public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar) { dataCollector.ForceNormal = true; dataCollector.AddToInput(m_uniqueId, UIUtils.GetInputDeclarationFromType(m_currentPrecisionType, AvailableSurfaceInputs.WORLD_NORMAL), true); dataCollector.AddToInput(m_uniqueId, Constants.InternalData, false); GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, m_uniqueId, m_currentPrecisionType); return(GeneratorUtils.WorldToTangentStr); }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar) { if (dataCollector.IsTemplate) { string varName = (m_viewDirSpace == ViewSpace.World)? dataCollector.TemplateDataCollectorInstance.GetNormalizedViewDir(): dataCollector.TemplateDataCollectorInstance.GetTangenViewDir(); return(GetOutputVectorItem(0, outputId, varName)); } if (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation) { if (m_viewDirSpace == ViewSpace.World) { string precision = UIUtils.FinalPrecisionWirePortToCgType(m_currentPrecisionType, WirePortDataType.FLOAT3); string worldPos = GeneratorUtils.GenerateWorldPosition(ref dataCollector, UniqueId); dataCollector.AddLocalVariable(UniqueId, precision + " worldViewDir = normalize( UnityWorldSpaceViewDir( " + worldPos + " ) );"); return(GetOutputVectorItem(0, outputId, "worldViewDir")); } else { string precision = UIUtils.FinalPrecisionWirePortToCgType(m_currentPrecisionType, WirePortDataType.FLOAT3); string worldPos = GeneratorUtils.GenerateWorldPosition(ref dataCollector, UniqueId); string worldToTangent = GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, UniqueId, m_currentPrecisionType); dataCollector.AddLocalVariable(UniqueId, precision + " tangentViewDir = mul( " + worldToTangent + ", normalize( UnityWorldSpaceViewDir( " + worldPos + " ) ) );"); return(GetOutputVectorItem(0, outputId, "tangentViewDir")); } } else { if (m_viewDirSpace == ViewSpace.World) { if (dataCollector.DirtyNormal) { dataCollector.AddToInput(UniqueId, UIUtils.GetInputDeclarationFromType(m_currentPrecisionType, AvailableSurfaceInputs.WORLD_POS), true); dataCollector.AddToLocalVariables(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT3, WorldDirVarStr, "normalize( UnityWorldSpaceViewDir( " + Constants.InputVarStr + ".worldPos ) )"); return(GetOutputVectorItem(0, outputId, WorldDirVarStr)); } else { return(base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalVar)); } } else { dataCollector.ForceNormal = true; return(base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalVar)); } } }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar) { if (dataCollector.IsTemplate) { return(dataCollector.TemplateDataCollectorInstance.GetWorldToTangentMatrix(CurrentPrecisionType)); } if (dataCollector.IsFragmentCategory) { dataCollector.ForceNormal = true; dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType); dataCollector.AddToInput(UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false); } GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, UniqueId, CurrentPrecisionType); return(GeneratorUtils.WorldToTangentStr); }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { if (m_outputPorts[0].IsLocalValue) { return(m_outputPorts[0].LocalValue); } if (dataCollector.IsFragmentCategory) { dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_POS); } string viewdir = GeneratorUtils.GenerateViewDirection(ref dataCollector, UniqueId, ViewSpace.World); string normal = string.Empty; if (m_inputPorts[0].IsConnected) { normal = m_inputPorts[0].GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT3, ignoreLocalvar, true); if (dataCollector.IsFragmentCategory) { dataCollector.AddToInput(UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false); if (m_normalSpace == ViewSpace.Tangent) { dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType); dataCollector.ForceNormal = true; normal = "WorldNormalVector( " + Constants.InputVarStr + " , " + normal + " )"; } } else { if (m_normalSpace == ViewSpace.Tangent) { string wtMatrix = GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, UniqueId, m_currentPrecisionType); normal = "mul( " + normal + "," + wtMatrix + " )"; } } } else { if (dataCollector.IsFragmentCategory) { dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_NORMAL, m_currentPrecisionType); if (dataCollector.DirtyNormal) { dataCollector.AddToInput(UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false); } } normal = dataCollector.IsTemplate ? dataCollector.TemplateDataCollectorInstance.GetWorldNormal() : GeneratorUtils.GenerateWorldNormal(ref dataCollector, UniqueId); } string bias = m_inputPorts[1].GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT, ignoreLocalvar, true); string scale = m_inputPorts[2].GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT, ignoreLocalvar, true); string power = m_inputPorts[3].GenerateShaderForOutput(ref dataCollector, WirePortDataType.FLOAT, ignoreLocalvar, true); string fresnelNDotVLocalValue = "dot( " + normal + ", " + viewdir + " )"; string fresnelNDotVLocalVar = "fresnelNDotV" + OutputId; dataCollector.AddLocalVariable(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT, fresnelNDotVLocalVar, fresnelNDotVLocalValue); string fresnelFinalVar = FresnedFinalVar + OutputId; string result = string.Format("( {0} + {1} * pow( 1.0 - {2}, {3} ) )", bias, scale, fresnelNDotVLocalVar, power); RegisterLocalVariable(0, result, ref dataCollector, fresnelFinalVar); return(m_outputPorts[0].LocalValue); }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { if (m_outputPorts[0].IsLocalValue(dataCollector.PortCategory)) { return(m_outputPorts[0].LocalValue(dataCollector.PortCategory)); } if (dataCollector.IsFragmentCategory) { dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_POS); } string viewdir = string.Empty; if (m_viewType == ViewType.ViewDir) { if (m_viewVecPort.IsConnected) { viewdir = m_viewVecPort.GeneratePortInstructions(ref dataCollector); } else { viewdir = GeneratorUtils.GenerateViewDirection(ref dataCollector, UniqueId, ViewSpace.World); } } else { if (m_viewVecPort.IsConnected) { viewdir = m_viewVecPort.GeneratePortInstructions(ref dataCollector); } else { viewdir = GeneratorUtils.GenerateWorldLightDirection(ref dataCollector, UniqueId, CurrentPrecisionType); } } string normal = string.Empty; if (m_normalType == NormalType.WorldNormal || m_normalType == NormalType.TangentNormal) { if (m_normalVecPort.IsConnected) { normal = m_normalVecPort.GeneratePortInstructions(ref dataCollector); if (dataCollector.IsFragmentCategory) { dataCollector.AddToInput(UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false); if (m_normalType == NormalType.TangentNormal) { if (dataCollector.IsTemplate) { normal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal(UniqueId, CurrentPrecisionType, normal, OutputId); } else { normal = GeneratorUtils.GenerateWorldNormal(ref dataCollector, UniqueId, CurrentPrecisionType, normal, OutputId); dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType); dataCollector.ForceNormal = true; } } else { if (m_normalizeVectors) { normal = string.Format("normalize( {0} )", normal); } } } else { if (m_normalType == NormalType.TangentNormal) { string wtMatrix = GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, UniqueId, CurrentPrecisionType); normal = "mul( " + normal + "," + wtMatrix + " )"; } } } else { if (dataCollector.IsFragmentCategory) { dataCollector.AddToInput(UniqueId, SurfaceInputs.WORLD_NORMAL, CurrentPrecisionType); if (dataCollector.DirtyNormal) { dataCollector.AddToInput(UniqueId, SurfaceInputs.INTERNALDATA, addSemiColon: false); } } if (dataCollector.IsTemplate) { normal = dataCollector.TemplateDataCollectorInstance.GetWorldNormal(CurrentPrecisionType, normalize: (dataCollector.DirtyNormal && m_normalizeVectors)); } else { normal = GeneratorUtils.GenerateWorldNormal(ref dataCollector, UniqueId, (dataCollector.DirtyNormal && m_normalizeVectors)); } if (dataCollector.DirtyNormal) { dataCollector.ForceNormal = true; } } } else { // generate HV if (!m_normalVecPort.IsConnected) { string halfView = GeneratorUtils.GenerateViewDirection(ref dataCollector, UniqueId, ViewSpace.World); string halfLight = GeneratorUtils.GenerateWorldLightDirection(ref dataCollector, UniqueId, CurrentPrecisionType); normal = "halfVector" + OutputId; dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3, normal, "normalize( " + halfView + " + " + halfLight + " )"); } else { normal = m_normalVecPort.GeneratePortInstructions(ref dataCollector); if (m_normalizeVectors) { normal = string.Format("normalize( {0} )", normal); } } } string bias = m_biasPort.GeneratePortInstructions(ref dataCollector); string scale = m_scalePort.GeneratePortInstructions(ref dataCollector); string power = m_powerPort.GeneratePortInstructions(ref dataCollector); string fresnelNDotVLocalValue = "dot( " + normal + ", " + viewdir + " )"; string fresnelNDotVLocalVar = "fresnelNdotV" + OutputId; dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT, fresnelNDotVLocalVar, fresnelNDotVLocalValue); string fresnelFinalVar = FresnedFinalVar + OutputId; string result = string.Empty; switch (m_fresnelType) { default: case FresnelType.Standard: { result = string.Format("( {0} + {1} * pow( 1.0 - {2}, {3} ) )", bias, scale, fresnelNDotVLocalVar, power); } break; case FresnelType.Schlick: { string f0VarName = "f0" + OutputId; dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT, f0VarName, bias); result = string.Format("( {0} + ( 1.0 - {0} ) * pow( 1.0 - {1}, 5 ) )", f0VarName, fresnelNDotVLocalVar); } break; case FresnelType.SchlickIOR: { string iorVarName = "ior" + OutputId; dataCollector.AddLocalVariable(UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT, iorVarName, scale); dataCollector.AddLocalVariable(UniqueId, iorVarName + " = pow( ( 1-" + iorVarName + " )/( 1+" + iorVarName + " ), 2 );"); result = string.Format("( {0} + ( 1.0 - {0} ) * pow( 1.0 - {1}, 5 ) )", iorVarName, fresnelNDotVLocalVar); } break; } RegisterLocalVariable(0, result, ref dataCollector, fresnelFinalVar); return(m_outputPorts[0].LocalValue(dataCollector.PortCategory)); }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { if (m_outputPorts[0].IsLocalValue(dataCollector.PortCategory)) { return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory))); } GeneratorUtils.RegisterUnity2019MatrixDefines(ref dataCollector); string result = m_inputPorts[0].GeneratePortInstructions(ref dataCollector); string varName = string.Empty; if ((int)m_from == (int)m_to) { RegisterLocalVariable(0, result, ref dataCollector); return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory))); } switch (m_from) { case TransformSpaceFrom.Object: { switch (m_to) { default: case TransformSpaceTo.Object: break; case TransformSpaceTo.World: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpaceTo.View: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpaceTo.Clip: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpaceTo.Tangent: { GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, UniqueId, CurrentPrecisionType); CalculateTransform(m_from, TransformSpaceTo.World, ref dataCollector, ref varName, ref result); result = string.Format(ASEWorldToTangentFormat, result); varName = AseObjectToTangentDirVarName + OutputId; } break; } } break; case TransformSpaceFrom.World: { switch (m_to) { case TransformSpaceTo.Object: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; default: case TransformSpaceTo.World: break; case TransformSpaceTo.View: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpaceTo.Clip: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpaceTo.Tangent: { GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, UniqueId, CurrentPrecisionType); result = string.Format(ASEWorldToTangentFormat, result); varName = AseWorldToTangentDirVarName + OutputId; } break; } } break; case TransformSpaceFrom.View: { switch (m_to) { case TransformSpaceTo.Object: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpaceTo.World: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; default: case TransformSpaceTo.View: break; case TransformSpaceTo.Clip: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpaceTo.Tangent: { GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, UniqueId, CurrentPrecisionType); CalculateTransform(m_from, TransformSpaceTo.World, ref dataCollector, ref varName, ref result); result = string.Format(ASEWorldToTangentFormat, result); varName = AseViewToTangentDirVarName + OutputId; } break; } } break; //case TransformSpace.Clip: //{ // switch( m_to ) // { // case TransformSpace.Object: // { // CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); // } // break; // case TransformSpace.World: // { // CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); // } // break; // case TransformSpace.View: // { // CalculateTransform( m_from, m_to, ref dataCollector, ref varName, ref result ); // } // break; // case TransformSpace.Clip: break; // case TransformSpace.Tangent: // { // GeneratorUtils.GenerateWorldToTangentMatrix( ref dataCollector, UniqueId, CurrentPrecisionType ); // CalculateTransform( m_from, TransformSpace.World, ref dataCollector, ref varName, ref result ); // result = string.Format( ASEWorldToTangentFormat, result ); // varName = AseClipToTangentDirVarName + OutputId; // } // break; // default: // break; // } //}break; case TransformSpaceFrom.Tangent: { string matrixVal = string.Empty; if (m_inverseTangentType == InverseTangentType.Fast) { matrixVal = GeneratorUtils.GenerateTangentToWorldMatrixFast(ref dataCollector, UniqueId, CurrentPrecisionType); } else { matrixVal = GeneratorUtils.GenerateTangentToWorldMatrixPrecise(ref dataCollector, UniqueId, CurrentPrecisionType); } switch (m_to) { case TransformSpaceTo.Object: { result = string.Format(ASEMulOpFormat, matrixVal, result); CalculateTransform(TransformSpaceFrom.World, m_to, ref dataCollector, ref varName, ref result); varName = AseTangentToObjectDirVarName + OutputId; } break; case TransformSpaceTo.World: { result = string.Format(ASEMulOpFormat, matrixVal, result); varName = AseTangentToWorldDirVarName + OutputId; } break; case TransformSpaceTo.View: { result = string.Format(ASEMulOpFormat, matrixVal, result); CalculateTransform(TransformSpaceFrom.World, m_to, ref dataCollector, ref varName, ref result); varName = AseTangentToViewDirVarName + OutputId; } break; case TransformSpaceTo.Clip: { result = string.Format(ASEMulOpFormat, matrixVal, result); CalculateTransform(TransformSpaceFrom.World, m_to, ref dataCollector, ref varName, ref result); varName = AseTangentToClipDirVarName + OutputId; } break; case TransformSpaceTo.Tangent: default: break; } } break; default: break; } if (m_normalize) { result = string.Format(NormalizeFunc, result); } RegisterLocalVariable(0, result, ref dataCollector, varName); return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory))); }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { if (m_outputPorts[0].IsLocalValue(dataCollector.PortCategory)) { return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory))); } string result = m_inputPorts[0].GeneratePortInstructions(ref dataCollector); string varName = string.Empty; switch (m_from) { case TransformSpace.Object: { switch (m_to) { default: case TransformSpace.Object: break; case TransformSpace.World: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpace.View: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpace.Clip: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpace.Tangent: { GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, UniqueId, m_currentPrecisionType); CalculateTransform(m_from, TransformSpace.World, ref dataCollector, ref varName, ref result); result = string.Format(ASEWorldToTangentFormat, result); varName = AseObjectToTangentPosVarName; } break; } } break; case TransformSpace.World: { switch (m_to) { case TransformSpace.Object: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; default: case TransformSpace.World: break; case TransformSpace.View: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpace.Clip: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpace.Tangent: { GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, UniqueId, m_currentPrecisionType); result = string.Format(ASEWorldToTangentFormat, result); varName = AseWorldToTangentPosVarName; } break; } } break; case TransformSpace.View: { switch (m_to) { case TransformSpace.Object: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpace.World: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result);; } break; default: case TransformSpace.View: break; case TransformSpace.Clip: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpace.Tangent: { GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, UniqueId, m_currentPrecisionType); CalculateTransform(m_from, TransformSpace.World, ref dataCollector, ref varName, ref result); result = string.Format(ASEWorldToTangentFormat, result); varName = AseViewToTangentPosVarName; } break; } } break; case TransformSpace.Clip: { switch (m_to) { case TransformSpace.Object: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpace.World: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpace.View: { CalculateTransform(m_from, m_to, ref dataCollector, ref varName, ref result); } break; case TransformSpace.Clip: break; case TransformSpace.Tangent: { GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, UniqueId, m_currentPrecisionType); CalculateTransform(m_from, TransformSpace.World, ref dataCollector, ref varName, ref result); result = string.Format(ASEWorldToTangentFormat, result); varName = AseClipToTangentPosVarName; } break; default: break; } } break; case TransformSpace.Tangent: { string matrixVal = string.Empty; if (m_inverseTangentType == InverseTangentType.Fast) { matrixVal = GeneratorUtils.GenerateTangentToWorldMatrixFast(ref dataCollector, UniqueId, m_currentPrecisionType); } else { matrixVal = GeneratorUtils.GenerateTangentToWorldMatrixPrecise(ref dataCollector, UniqueId, m_currentPrecisionType); } switch (m_to) { case TransformSpace.Object: { result = string.Format(ASEMulOpFormat, matrixVal, result); CalculateTransform(TransformSpace.World, m_to, ref dataCollector, ref varName, ref result); varName = AseTangentToObjectPosVarName; } break; case TransformSpace.World: { result = string.Format(ASEMulOpFormat, matrixVal, result); varName = AseTangentToWorldPosVarName; } break; case TransformSpace.View: { result = string.Format(ASEMulOpFormat, matrixVal, result); CalculateTransform(TransformSpace.World, m_to, ref dataCollector, ref varName, ref result); varName = AseTangentToViewPosVarName; } break; case TransformSpace.Clip: { result = string.Format(ASEMulOpFormat, matrixVal, result); CalculateTransform(TransformSpace.World, m_to, ref dataCollector, ref varName, ref result); varName = AseTangentToClipPosVarName; } break; case TransformSpace.Tangent: default: break; } } break; default: break; } if (m_to == TransformSpace.Clip) { if (m_perspectiveDivide) { dataCollector.AddLocalVariable(UniqueId, m_currentPrecisionType, WirePortDataType.FLOAT4, varName, result); result = string.Format(AseClipToNDC, varName); varName += "NDC"; } else { result += ".xyz"; } } RegisterLocalVariable(0, result, ref dataCollector, varName); return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory))); }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { //ConfigureFunctions(); dataCollector.AddPropertyNode(m_topTexture); dataCollector.AddPropertyNode(m_midTexture); dataCollector.AddPropertyNode(m_botTexture); bool isVertex = (dataCollector.PortCategory == MasterNodePortCategory.Tessellation || dataCollector.PortCategory == MasterNodePortCategory.Vertex); string texTop = string.Empty; string texMid = string.Empty; string texBot = string.Empty; if (m_inputPorts[0].IsConnected) { texTop = m_inputPorts[0].GeneratePortInstructions(ref dataCollector); } else { dataCollector.AddToUniforms(m_uniqueId, m_topTexture.GetTexture2DUniformValue()); dataCollector.AddToProperties(m_uniqueId, m_topTexture.GetTexture2DPropertyValue(), m_topTexture.OrderIndex); texTop = m_topTexture.PropertyName; } if (m_selectedTriplanarType == TriplanarType.Spherical) { texMid = texTop; texBot = texTop; } else { if (m_inputPorts[1].IsConnected) { texMid = m_inputPorts[1].GeneratePortInstructions(ref dataCollector); } else { dataCollector.AddToUniforms(m_uniqueId, m_midTexture.GetTexture2DUniformValue()); dataCollector.AddToProperties(m_uniqueId, m_midTexture.GetTexture2DPropertyValue(), m_midTexture.OrderIndex); texMid = m_midTexture.PropertyName; } if (m_inputPorts[2].IsConnected) { texBot = m_inputPorts[2].GeneratePortInstructions(ref dataCollector); } else { dataCollector.AddToUniforms(m_uniqueId, m_botTexture.GetTexture2DUniformValue()); dataCollector.AddToProperties(m_uniqueId, m_botTexture.GetTexture2DPropertyValue(), m_botTexture.OrderIndex); texBot = m_botTexture.PropertyName; } } dataCollector.AddToInput(m_uniqueId, UIUtils.GetInputDeclarationFromType(m_currentPrecisionType, AvailableSurfaceInputs.WORLD_POS), true); dataCollector.AddToInput(m_uniqueId, UIUtils.GetInputDeclarationFromType(m_currentPrecisionType, AvailableSurfaceInputs.WORLD_NORMAL), true); string tilling = m_inputPorts[3].GeneratePortInstructions(ref dataCollector); string falloff = m_inputPorts[4].GeneratePortInstructions(ref dataCollector); dataCollector.ForceNormal = true; dataCollector.AddToInput(m_uniqueId, Constants.InternalData, false); if (m_normalCorrection) { string worldToTangent = GeneratorUtils.GenerateWorldToTangentMatrix(ref dataCollector, m_uniqueId, m_currentPrecisionType); string pos = GeneratorUtils.GenerateWorldPosition(ref dataCollector, m_uniqueId); string norm = GeneratorUtils.GenerateWorldNormal(ref dataCollector, m_uniqueId); if (m_selectedTriplanarSpace == TriplanarSpace.Object) { dataCollector.AddLocalVariable(m_uniqueId, "float3 localTangent = mul( unity_WorldToObject, float4( " + GeneratorUtils.WorldTangentStr + ", 0 ) );"); dataCollector.AddLocalVariable(m_uniqueId, "float3 localBitangent = mul( unity_WorldToObject, float4( " + GeneratorUtils.WorldBitangentStr + ", 0 ) );"); dataCollector.AddLocalVariable(m_uniqueId, "float3 localNormal = mul( unity_WorldToObject, float4( " + GeneratorUtils.WorldNormalStr + ", 0 ) );"); norm = "localNormal"; dataCollector.AddLocalVariable(m_uniqueId, "float3x3 objectToTangent = float3x3(localTangent, localBitangent, localNormal);"); dataCollector.AddLocalVariable(m_uniqueId, "float3 localPos = mul( unity_WorldToObject, float4( " + pos + ", 1 ) );"); pos = "localPos"; worldToTangent = "objectToTangent"; } string normalTriplanar = string.Empty; IOUtils.AddFunctionHeader(ref normalTriplanar, m_functionNormalHeader); if (m_selectedTriplanarType == TriplanarType.Spherical) { for (int i = 0; i < m_functionNormalBody.Length; i++) { IOUtils.AddFunctionLine(ref normalTriplanar, m_functionNormalBody[i]); } } else { for (int i = 0; i < m_functionNormalBodyTMB.Length; i++) { IOUtils.AddFunctionLine(ref normalTriplanar, m_functionNormalBodyTMB[i]); } } IOUtils.CloseFunctionBody(ref normalTriplanar); string call = dataCollector.AddFunctions(m_functionNormalCall, normalTriplanar, texTop, texMid, texBot, pos, norm, falloff, tilling, (isVertex ? "1" : "0")); dataCollector.AddToLocalVariables(dataCollector.PortCategory, m_uniqueId, "float3 worldTriplanarNormal" + m_uniqueId + " = " + call + ";"); dataCollector.AddToLocalVariables(dataCollector.PortCategory, m_uniqueId, "float3 tanTriplanarNormal" + m_uniqueId + " = mul( " + worldToTangent + ", worldTriplanarNormal" + m_uniqueId + " );"); return(GetOutputVectorItem(0, outputId, "tanTriplanarNormal" + m_uniqueId)); } else { string samplingTriplanar = string.Empty; IOUtils.AddFunctionHeader(ref samplingTriplanar, m_functionSamplingHeader); if (m_selectedTriplanarType == TriplanarType.Spherical) { for (int i = 0; i < m_functionSamplingBody.Length; i++) { IOUtils.AddFunctionLine(ref samplingTriplanar, m_functionSamplingBody[i]); } } else { for (int i = 0; i < m_functionSamplingBodyTMB.Length; i++) { IOUtils.AddFunctionLine(ref samplingTriplanar, m_functionSamplingBodyTMB[i]); } } IOUtils.CloseFunctionBody(ref samplingTriplanar); string pos = GeneratorUtils.GenerateWorldPosition(ref dataCollector, m_uniqueId); string norm = GeneratorUtils.GenerateWorldNormal(ref dataCollector, m_uniqueId); if (m_selectedTriplanarSpace == TriplanarSpace.Object) { dataCollector.AddToLocalVariables(dataCollector.PortCategory, m_uniqueId, "float3 localPos = mul( unity_WorldToObject, float4( " + pos + ", 1 ) );"); pos = "localPos"; dataCollector.AddToLocalVariables(dataCollector.PortCategory, m_uniqueId, "float3 localNormal = mul( unity_WorldToObject, float4( " + norm + ", 0 ) );"); norm = "localNormal"; } string call = dataCollector.AddFunctions(m_functionSamplingCall, samplingTriplanar, texTop, texMid, texBot, pos, norm, falloff, tilling, (isVertex ? "1" : "0")); dataCollector.AddToLocalVariables(dataCollector.PortCategory, m_uniqueId, "float4 triplanar" + m_uniqueId + " = " + call + ";"); return(GetOutputVectorItem(0, outputId, "triplanar" + m_uniqueId)); } }