|
|
|
|
|
|
throw new ArgumentNullException(nameof(node)); |
|
|
|
|
|
|
|
var vertexShader = new ShaderGenerator(); |
|
|
|
var sufraceDescriptionFunction = new ShaderGenerator(); |
|
|
|
var surfaceDescriptionFunction = new ShaderGenerator(); |
|
|
|
var surfaceDescriptionStruct = new ShaderGenerator(); |
|
|
|
var shaderFunctionVisitor = new ShaderGenerator(); |
|
|
|
var surfaceInputs = new ShaderGenerator(); |
|
|
|
|
|
|
surfaceDescriptionStruct.Deindent(); |
|
|
|
surfaceDescriptionStruct.AddShaderChunk("};", false); |
|
|
|
|
|
|
|
sufraceDescriptionFunction.AddShaderChunk("SurfaceDescription PopulateSurfaceData(SurfaceInputs IN) {", false); |
|
|
|
sufraceDescriptionFunction.Indent(); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk("SurfaceDescription PopulateSurfaceData(SurfaceInputs IN) {", false); |
|
|
|
surfaceDescriptionFunction.Indent(); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ObjectSpaceNormal), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ObjectSpaceNormal), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ViewSpaceNormal), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ViewSpaceNormal), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.WorldSpaceNormal), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.WorldSpaceNormal), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.TangentSpaceNormal), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.TangentSpaceNormal), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ObjectSpaceTangent), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ObjectSpaceTangent), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ViewSpaceTangent), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ViewSpaceTangent), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.WorldSpaceTangent), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.WorldSpaceTangent), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.TangentSpaceTangent), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.TangentSpaceTangent), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ObjectSpaceBiTangent), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ObjectSpaceBiTangent), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ViewSpaceBiTangent), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ViewSpaceBiTangent), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.WorldSpaceBiTangent), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.WorldSpaceBiTangent), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.TangentSpaceBiTangent), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.TangentSpaceBiTangent), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ObjectSpaceViewDirection), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ObjectSpaceViewDirection), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ViewSpaceViewDirection), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ViewSpaceViewDirection), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.WorldSpaceViewDirection), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.WorldSpaceViewDirection), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.TangentSpaceViewDirection), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.TangentSpaceViewDirection), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ObjectSpacePosition), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ObjectSpacePosition), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ViewSpacePosition), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.ViewSpacePosition), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.WorldSpacePosition), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.WorldSpacePosition), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.TangentSpacePosition), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float3 {0} = IN.{0};", ShaderGeneratorNames.TangentSpacePosition), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float4 {0} = IN.{0};", ShaderGeneratorNames.ScreenPosition), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float4 {0} = IN.{0};", ShaderGeneratorNames.ScreenPosition), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("float4 {0} = IN.{0};", ShaderGeneratorNames.VertexColor), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("float4 {0} = IN.{0};", ShaderGeneratorNames.VertexColor), false); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("half4 {0} = IN.{0};", channel.GetUVName()), false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("half4 {0} = IN.{0};", channel.GetUVName()), false); |
|
|
|
|
|
|
|
var shaderProperties = new PropertyCollector(); |
|
|
|
CollectShaderProperties(shaderProperties, mode); |
|
|
|
|
|
|
if (activeNode is IGeneratesFunction) |
|
|
|
(activeNode as IGeneratesFunction).GenerateNodeFunction(shaderFunctionVisitor, mode); |
|
|
|
if (activeNode is IGeneratesBodyCode) |
|
|
|
(activeNode as IGeneratesBodyCode).GenerateNodeCode(sufraceDescriptionFunction, mode); |
|
|
|
(activeNode as IGeneratesBodyCode).GenerateNodeCode(surfaceDescriptionFunction, mode); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk("SurfaceDescription surface = (SurfaceDescription)0;", false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk("SurfaceDescription surface = (SurfaceDescription)0;", false); |
|
|
|
foreach (var edge in GetEdges(input.slotReference)) |
|
|
|
var foundEdges = GetEdges(input.slotReference).ToArray(); |
|
|
|
if (foundEdges.Any()) |
|
|
|
{ |
|
|
|
var outputRef = foundEdges[0].outputSlot; |
|
|
|
var fromNode = GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {1};", input.shaderOutputName, fromNode.GetVariableNameForSlot(outputRef.slotId)), true); |
|
|
|
} |
|
|
|
else |
|
|
|
var outputRef = edge.outputSlot; |
|
|
|
var fromNode = GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid); |
|
|
|
if (fromNode == null) |
|
|
|
continue; |
|
|
|
|
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {1};", input.shaderOutputName, fromNode.GetVariableNameForSlot(outputRef.slotId)), true); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {1};", input.shaderOutputName, input.GetDefaultValue(mode)), true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
sufraceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {0};", node.GetVariableNameForSlot(slot.id)), true); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {0};", node.GetVariableNameForSlot(slot.id)), true); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk("return surface;", false); |
|
|
|
sufraceDescriptionFunction.Deindent(); |
|
|
|
sufraceDescriptionFunction.AddShaderChunk("}", false); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk("return surface;", false); |
|
|
|
surfaceDescriptionFunction.Deindent(); |
|
|
|
surfaceDescriptionFunction.AddShaderChunk("}", false); |
|
|
|
ListPool<INode>.Release(activeNodeList); |
|
|
|
|
|
|
|
var finalShader = new ShaderGenerator(); |
|
|
|
|
|
|
finalShader.AddShaderChunk(surfaceDescriptionStruct.GetShaderString(2), false); |
|
|
|
finalShader.AddShaderChunk(shaderProperties.GetPropertiesDeclaration(2), false); |
|
|
|
finalShader.AddShaderChunk(vertexShader.GetShaderString(2), false); |
|
|
|
finalShader.AddShaderChunk(sufraceDescriptionFunction.GetShaderString(2), false); |
|
|
|
finalShader.AddShaderChunk(surfaceDescriptionFunction.GetShaderString(2), false); |
|
|
|
finalShader.AddShaderChunk("ENDCG", false); |
|
|
|
|
|
|
|
var masterNode = node as IMasterNode; |
|
|
|