|
|
|
|
|
|
public static void GenerateSpaceTranslationSurfaceInputs( |
|
|
|
NeededCoordinateSpace neededSpaces, |
|
|
|
InterpolatorType interpolatorType, |
|
|
|
ShaderGenerator surfaceInputs, |
|
|
|
string format = "float3 {0};") |
|
|
|
{ |
|
|
|
var builder = new ShaderStringBuilder(); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(neededSpaces, interpolatorType, builder, format); |
|
|
|
surfaceInputs.AddShaderChunk(builder.ToString(), false); |
|
|
|
} |
|
|
|
|
|
|
|
public static void GenerateSpaceTranslationSurfaceInputs( |
|
|
|
NeededCoordinateSpace neededSpaces, |
|
|
|
InterpolatorType interpolatorType, |
|
|
|
ShaderStringBuilder builder, |
|
|
|
string format = "float3 {0};") |
|
|
|
{ |
|
|
|
|
|
|
public static void GenerateStandardTransforms( |
|
|
|
int interpolatorStartIndex, |
|
|
|
int maxInterpolators, |
|
|
|
ShaderGenerator interpolators, |
|
|
|
ShaderStringBuilder vertexDescriptionInputs, |
|
|
|
ShaderGenerator vertexShader, |
|
|
|
ShaderGenerator pixelShader, |
|
|
|
ShaderGenerator surfaceInputs, |
|
|
|
ShaderStringBuilder vertexOutputStruct, |
|
|
|
ShaderStringBuilder vertexShader, |
|
|
|
ShaderStringBuilder vertexShaderDescriptionInputs, |
|
|
|
ShaderStringBuilder vertexShaderOutputs, |
|
|
|
ShaderStringBuilder pixelShader, |
|
|
|
ShaderStringBuilder pixelShaderSurfaceInputs, |
|
|
|
ShaderGraphRequirements pixelRequirements, |
|
|
|
ShaderGraphRequirements surfaceRequirements, |
|
|
|
ShaderGraphRequirements modelRequiements, |
|
|
|
|
|
|
if (combinedRequirements.requiresNormal > 0 || combinedRequirements.requiresBitangent > 0) |
|
|
|
{ |
|
|
|
var name = preferredCoordinateSpace.ToVariableName(InterpolatorType.Normal); |
|
|
|
vertexDescriptionInputs.AppendLine("float3 {0} = {1};", name, ConvertBetweenSpace("v.normal", CoordinateSpace.Object, preferredCoordinateSpace, InputType.Normal)); |
|
|
|
if (vertexRequirements.requiresNormal > 0 || vertexRequirements.requiresBitangent > 0) |
|
|
|
vertexDescriptionInputs.AppendLine("vdi.{0} = {0};", name); |
|
|
|
vertexShader.AppendLine("float3 {0} = {1};", name, ConvertBetweenSpace("v.normal", CoordinateSpace.Object, preferredCoordinateSpace, InputType.Normal)); |
|
|
|
//if (vertexRequirements.requiresNormal > 0 || vertexRequirements.requiresBitangent > 0)
|
|
|
|
// vertexDescriptionInputs.AppendLine("vdi.{0} = {0};", name);
|
|
|
|
interpolators.AddShaderChunk(string.Format("float3 {0} : TEXCOORD{1};", name, interpolatorIndex), false); |
|
|
|
vertexShader.AddShaderChunk(string.Format("o.{0} = {0};", name), false); |
|
|
|
pixelShader.AddShaderChunk(string.Format("float3 {0} = normalize(IN.{0});", name), false); |
|
|
|
vertexOutputStruct.AppendLine("float3 {0} : TEXCOORD{1};", name, interpolatorIndex); |
|
|
|
vertexShaderOutputs.AppendLine("o.{0} = {0};", name); |
|
|
|
pixelShader.AppendLine("float3 {0} = normalize(IN.{0});", name); |
|
|
|
interpolatorIndex++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
var name = preferredCoordinateSpace.ToVariableName(InterpolatorType.Tangent); |
|
|
|
vertexDescriptionInputs.AppendLine("float3 {0} = {1};", name, ConvertBetweenSpace("v.tangent.xyz", CoordinateSpace.Object, preferredCoordinateSpace, InputType.Vector)); |
|
|
|
if (vertexRequirements.requiresTangent > 0 || vertexRequirements.requiresBitangent > 0) |
|
|
|
vertexDescriptionInputs.AppendLine("vdi.{0} = {0};", name); |
|
|
|
vertexShader.AppendLine("float3 {0} = {1};", name, ConvertBetweenSpace("v.tangent.xyz", CoordinateSpace.Object, preferredCoordinateSpace, InputType.Vector)); |
|
|
|
//if (vertexRequirements.requiresTangent > 0 || vertexRequirements.requiresBitangent > 0)
|
|
|
|
// vertexDescriptionInputs.AppendLine("vdi.{0} = {0};", name);
|
|
|
|
interpolators.AddShaderChunk(string.Format("float3 {0} : TEXCOORD{1};", name, interpolatorIndex), false); |
|
|
|
vertexShader.AddShaderChunk(string.Format("o.{0} = {0};", name), false); |
|
|
|
pixelShader.AddShaderChunk(string.Format("float3 {0} = IN.{0};", name), false); |
|
|
|
vertexOutputStruct.AppendLine("float3 {0} : TEXCOORD{1};", name, interpolatorIndex); |
|
|
|
vertexShaderOutputs.AppendLine("o.{0} = {0};", name); |
|
|
|
pixelShader.AppendLine("float3 {0} = IN.{0};", name); |
|
|
|
interpolatorIndex++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
var name = preferredCoordinateSpace.ToVariableName(InterpolatorType.BiTangent); |
|
|
|
vertexDescriptionInputs.AppendLine("float3 {0} = normalize(cross({1}, {2}.xyz) * {3});", |
|
|
|
vertexShader.AppendLine("float3 {0} = normalize(cross({1}, {2}.xyz) * {3});", |
|
|
|
if (vertexRequirements.requiresBitangent > 0) |
|
|
|
vertexDescriptionInputs.AppendLine("vdi.{0} = {0};", name); |
|
|
|
//if (vertexRequirements.requiresBitangent > 0)
|
|
|
|
// vertexDescriptionInputs.AppendLine("vdi.{0} = {0};", name);
|
|
|
|
interpolators.AddShaderChunk(string.Format("float3 {0} : TEXCOORD{1};", name, interpolatorIndex), false); |
|
|
|
vertexShader.AddShaderChunk(string.Format("o.{0} = {0};", name), false); |
|
|
|
pixelShader.AddShaderChunk(string.Format("float3 {0} = IN.{0};", name), false); |
|
|
|
vertexOutputStruct.AppendLine("float3 {0} : TEXCOORD{1};", name, interpolatorIndex); |
|
|
|
vertexShaderOutputs.AppendLine("o.{0} = {0};", name); |
|
|
|
pixelShader.AppendLine("float3 {0} = IN.{0};", name); |
|
|
|
interpolatorIndex++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
const string worldSpaceViewDir = "SafeNormalize(_WorldSpaceCameraPos.xyz - mul(GetObjectToWorldMatrix(), float4(v.vertex.xyz, 1.0)).xyz)"; |
|
|
|
var preferredSpaceViewDir = ConvertBetweenSpace(worldSpaceViewDir, CoordinateSpace.World, preferredCoordinateSpace, InputType.Vector); |
|
|
|
if (vertexRequirements.requiresViewDir > 0) |
|
|
|
vertexDescriptionInputs.AppendLine("vdi.{0} = {1};", name, preferredSpaceViewDir); |
|
|
|
vertexShaderDescriptionInputs.AppendLine("vdi.{0} = {1};", name, preferredSpaceViewDir); |
|
|
|
interpolators.AddShaderChunk(string.Format("float3 {0} : TEXCOORD{1};", name, interpolatorIndex), false); |
|
|
|
vertexShader.AddShaderChunk(string.Format("o.{0} = {1};", name, preferredSpaceViewDir), false); |
|
|
|
pixelShader.AddShaderChunk(string.Format("float3 {0} = normalize(IN.{0});", name), false); |
|
|
|
vertexOutputStruct.AppendLine("float3 {0} : TEXCOORD{1};", name, interpolatorIndex); |
|
|
|
vertexShaderOutputs.AppendLine("o.{0} = {1};", name, preferredSpaceViewDir); |
|
|
|
pixelShader.AppendLine("float3 {0} = normalize(IN.{0});", name); |
|
|
|
interpolatorIndex++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
var name = preferredCoordinateSpace.ToVariableName(InterpolatorType.Position); |
|
|
|
var preferredSpacePosition = ConvertBetweenSpace("v.vertex", CoordinateSpace.Object, preferredCoordinateSpace, InputType.Position); |
|
|
|
if (vertexRequirements.requiresPosition > 0) |
|
|
|
vertexDescriptionInputs.AppendLine("float3 {0} = {1};", name, preferredSpacePosition); |
|
|
|
vertexShader.AppendLine("float3 {0} = {1};", name, preferredSpacePosition); |
|
|
|
interpolators.AddShaderChunk(string.Format("float3 {0} : TEXCOORD{1};", name, interpolatorIndex), false); |
|
|
|
vertexShader.AddShaderChunk(string.Format("o.{0} = {1}.xyz;", name, preferredSpacePosition), false); |
|
|
|
pixelShader.AddShaderChunk(string.Format("float3 {0} = IN.{0};", name), false); |
|
|
|
vertexOutputStruct.AppendLine("float3 {0} : TEXCOORD{1};", name, interpolatorIndex); |
|
|
|
vertexShaderOutputs.AppendLine("o.{0} = {1}.xyz;", name, preferredSpacePosition); |
|
|
|
pixelShader.AppendLine("float3 {0} = IN.{0};", name); |
|
|
|
interpolatorIndex++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
var bitangent = preferredCoordinateSpace.ToVariableName(InterpolatorType.BiTangent); |
|
|
|
var normal = preferredCoordinateSpace.ToVariableName(InterpolatorType.Normal); |
|
|
|
if (vertexRequirements.NeedsTangentSpace()) |
|
|
|
vertexDescriptionInputs.AppendLine("float3x3 tangentSpaceTransform = float3x3({0},{1},{2});", |
|
|
|
vertexShader.AppendLine("float3x3 tangentSpaceTransform = float3x3({0},{1},{2});", |
|
|
|
pixelShader.AddShaderChunk(string.Format("float3x3 tangentSpaceTransform = float3x3({0},{1},{2});", |
|
|
|
tangent, bitangent, normal), false); |
|
|
|
pixelShader.AppendLine("float3x3 tangentSpaceTransform = float3x3({0},{1},{2});", |
|
|
|
tangent, bitangent, normal); |
|
|
|
var sg = new ShaderGenerator(); |
|
|
|
//var sg = new ShaderGenerator();
|
|
|
|
InputType.Normal, sg, Dimension.Three); |
|
|
|
InputType.Normal, vertexShader, Dimension.Three); |
|
|
|
InputType.Vector, sg, Dimension.Three); |
|
|
|
InputType.Vector, vertexShader, Dimension.Three); |
|
|
|
InputType.Vector, sg, Dimension.Three); |
|
|
|
InputType.Vector, vertexShader, Dimension.Three); |
|
|
|
InputType.Vector, sg, Dimension.Three); |
|
|
|
InputType.Vector, vertexShader, Dimension.Three); |
|
|
|
InputType.Position, sg, Dimension.Three); |
|
|
|
vertexDescriptionInputs.AppendLines(sg.GetShaderString(0)); |
|
|
|
InputType.Position, vertexShader, Dimension.Three); |
|
|
|
//vertexShader.AppendLines(sg.GetShaderString(0));
|
|
|
|
} |
|
|
|
|
|
|
|
// Generate the space translations needed by the surface description and model
|
|
|
|
|
|
|
GenerateSpaceTranslations(graphModelRequirements.requiresPosition, InterpolatorType.Position, preferredCoordinateSpace, |
|
|
|
InputType.Position, pixelShader, Dimension.Three); |
|
|
|
|
|
|
|
if (combinedRequirements.requiresVertexColor) |
|
|
|
{ |
|
|
|
vertexDescriptionInputs.AppendLine("vdi.{0} = v.color;", ShaderGeneratorNames.VertexColor); |
|
|
|
vertexShaderDescriptionInputs.AppendLine("vdi.{0} = v.color;", ShaderGeneratorNames.VertexColor); |
|
|
|
interpolators.AddShaderChunk(string.Format("float4 {0} : COLOR;", ShaderGeneratorNames.VertexColor), false); |
|
|
|
vertexShader.AddShaderChunk(string.Format("o.{0} = v.color;", ShaderGeneratorNames.VertexColor), false); |
|
|
|
pixelShader.AddShaderChunk(string.Format("float4 {0} = IN.{0};", ShaderGeneratorNames.VertexColor), false); |
|
|
|
vertexOutputStruct.AppendLine("float4 {0} : COLOR;", ShaderGeneratorNames.VertexColor); |
|
|
|
vertexShaderOutputs.AppendLine("o.{0} = v.color;", ShaderGeneratorNames.VertexColor); |
|
|
|
pixelShader.AppendLine("float4 {0} = IN.{0};", ShaderGeneratorNames.VertexColor); |
|
|
|
} |
|
|
|
if (combinedRequirements.requiresScreenPosition) |
|
|
|
/*if (combinedRequirements.requiresScreenPosition) |
|
|
|
vertexShader.AddShaderChunk(string.Format("o.{0} = ComputeScreenPos(mul(GetWorldToHClipMatrix(), mul(GetObjectToWorldMatrix(), v.vertex)), _ProjectionParams.x);", ShaderGeneratorNames.ScreenPosition), false); |
|
|
|
vertexOutputs.AddShaderChunk(string.Format("o.{0} = ComputeScreenPos(mul(GetWorldToHClipMatrix(), mul(GetObjectToWorldMatrix(), v.vertex)), _ProjectionParams.x);", ShaderGeneratorNames.ScreenPosition), false); |
|
|
|
} |
|
|
|
}*/ |
|
|
|
|
|
|
|
if (combinedRequirements.requiresScreenPosition) |
|
|
|
{ |
|
|
|
|
|
|
vertexDescriptionInputs.AppendLine("float4 {0} = {1};", ShaderGeneratorNames.ScreenPosition, screenPosition); |
|
|
|
vertexShader.AppendLine("float4 {0} = {1};", ShaderGeneratorNames.ScreenPosition, screenPosition); |
|
|
|
vertexShaderDescriptionInputs.AppendLine("vdi.{0} = {0};", ShaderGeneratorNames.ScreenPosition); |
|
|
|
interpolators.AddShaderChunk(string.Format("float4 {0} : TEXCOORD{1};", ShaderGeneratorNames.ScreenPosition, interpolatorIndex), false); |
|
|
|
vertexShader.AddShaderChunk(string.Format("o.{0} = {1};", ShaderGeneratorNames.ScreenPosition, screenPosition), false); |
|
|
|
pixelShader.AddShaderChunk(string.Format("float4 {0} = IN.{0};", ShaderGeneratorNames.ScreenPosition), false); |
|
|
|
vertexOutputStruct.AppendLine("float4 {0} : TEXCOORD{1};", ShaderGeneratorNames.ScreenPosition, interpolatorIndex); |
|
|
|
vertexShaderOutputs.AppendLine("o.{0} = {1};", ShaderGeneratorNames.ScreenPosition, screenPosition); |
|
|
|
pixelShader.AppendLine("float4 {0} = IN.{0};", ShaderGeneratorNames.ScreenPosition); |
|
|
|
interpolatorIndex++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
vertexDescriptionInputs.AppendLine("vdi.{0} = v.texcoord{1};", channel.GetUVName(), (int)channel); |
|
|
|
vertexShaderDescriptionInputs.AppendLine("vdi.{0} = v.texcoord{1};", channel.GetUVName(), (int)channel); |
|
|
|
interpolators.AddShaderChunk(string.Format("half4 {0} : TEXCOORD{1};", channel.GetUVName(), interpolatorIndex == 0 ? "" : interpolatorIndex.ToString()), false); |
|
|
|
vertexShader.AddShaderChunk(string.Format("o.{0} = v.texcoord{1};", channel.GetUVName(), (int)channel), false); |
|
|
|
pixelShader.AddShaderChunk(string.Format("float4 {0} = IN.{0};", channel.GetUVName()), false); |
|
|
|
vertexOutputStruct.AppendLine("half4 {0} : TEXCOORD{1};", channel.GetUVName(), interpolatorIndex == 0 ? "" : interpolatorIndex.ToString()); |
|
|
|
vertexShaderOutputs.AppendLine("o.{0} = v.texcoord{1};", channel.GetUVName(), (int)channel); |
|
|
|
pixelShader.AppendLine("float4 {0} = IN.{0};", channel.GetUVName()); |
|
|
|
interpolatorIndex++; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
// and are not needed in the shader graph
|
|
|
|
{ |
|
|
|
var replaceString = "surfaceInput.{0} = {0};"; |
|
|
|
GenerateSpaceTranslationSurfaceInputs(surfaceRequirements.requiresNormal, InterpolatorType.Normal, surfaceInputs, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(surfaceRequirements.requiresTangent, InterpolatorType.Tangent, surfaceInputs, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(surfaceRequirements.requiresBitangent, InterpolatorType.BiTangent, surfaceInputs, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(surfaceRequirements.requiresViewDir, InterpolatorType.ViewDirection, surfaceInputs, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(surfaceRequirements.requiresPosition, InterpolatorType.Position, surfaceInputs, replaceString); |
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
|
var replaceString = "vdi.{0} = {0};"; |
|
|
|
var sg = new ShaderGenerator(); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(vertexRequirements.requiresNormal, InterpolatorType.Normal, sg, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(vertexRequirements.requiresTangent, InterpolatorType.Tangent, sg, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(vertexRequirements.requiresBitangent, InterpolatorType.BiTangent, sg, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(vertexRequirements.requiresViewDir, InterpolatorType.ViewDirection, sg, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(vertexRequirements.requiresPosition, InterpolatorType.Position, sg, replaceString); |
|
|
|
vertexDescriptionInputs.AppendLines(sg.GetShaderString(0)); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(surfaceRequirements.requiresNormal, InterpolatorType.Normal, pixelShaderSurfaceInputs, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(surfaceRequirements.requiresTangent, InterpolatorType.Tangent, pixelShaderSurfaceInputs, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(surfaceRequirements.requiresBitangent, InterpolatorType.BiTangent, pixelShaderSurfaceInputs, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(surfaceRequirements.requiresViewDir, InterpolatorType.ViewDirection, pixelShaderSurfaceInputs, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(surfaceRequirements.requiresPosition, InterpolatorType.Position, pixelShaderSurfaceInputs, replaceString); |
|
|
|
|
|
|
|
|
|
|
|
surfaceInputs.AddShaderChunk(string.Format("surfaceInput.{0} = {0};", ShaderGeneratorNames.VertexColor), false); |
|
|
|
pixelShaderSurfaceInputs.AppendLine("surfaceInput.{0} = {0};", ShaderGeneratorNames.VertexColor); |
|
|
|
surfaceInputs.AddShaderChunk(string.Format("surfaceInput.{0} = {0};", ShaderGeneratorNames.ScreenPosition), false); |
|
|
|
pixelShaderSurfaceInputs.AppendLine("surfaceInput.{0} = {0};", ShaderGeneratorNames.ScreenPosition); |
|
|
|
surfaceInputs.AddShaderChunk(string.Format("surfaceInput.{0} = {0};", channel.GetUVName()), false); |
|
|
|
pixelShaderSurfaceInputs.AppendLine("surfaceInput.{0} = {0};", ShaderGeneratorNames.GetUVName(channel)); |
|
|
|
|
|
|
|
{ |
|
|
|
var replaceString = "vdi.{0} = {0};"; |
|
|
|
GenerateSpaceTranslationSurfaceInputs(vertexRequirements.requiresNormal, InterpolatorType.Normal, vertexShaderDescriptionInputs, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(vertexRequirements.requiresTangent, InterpolatorType.Tangent, vertexShaderDescriptionInputs, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(vertexRequirements.requiresBitangent, InterpolatorType.BiTangent, vertexShaderDescriptionInputs, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(vertexRequirements.requiresViewDir, InterpolatorType.ViewDirection, vertexShaderDescriptionInputs, replaceString); |
|
|
|
GenerateSpaceTranslationSurfaceInputs(vertexRequirements.requiresPosition, InterpolatorType.Position, vertexShaderDescriptionInputs, replaceString); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public enum Dimension |
|
|
|
|
|
|
InterpolatorType type, |
|
|
|
CoordinateSpace from, |
|
|
|
InputType inputType, |
|
|
|
ShaderGenerator pixelShader, |
|
|
|
ShaderStringBuilder pixelShader, |
|
|
|
pixelShader.AddShaderChunk( |
|
|
|
string.Format("float{0} {1} = {2};", DimensionToString(dimension), |
|
|
|
CoordinateSpace.Object.ToVariableName(type), ConvertBetweenSpace(from.ToVariableName(type), from, CoordinateSpace.Object, inputType, from)), false); |
|
|
|
pixelShader.AppendLine("float{0} {1} = {2};", DimensionToString(dimension), |
|
|
|
CoordinateSpace.Object.ToVariableName(type), ConvertBetweenSpace(from.ToVariableName(type), from, CoordinateSpace.Object, inputType, from)); |
|
|
|
pixelShader.AddShaderChunk( |
|
|
|
string.Format("float{0} {1} = {2};", DimensionToString(dimension), |
|
|
|
CoordinateSpace.World.ToVariableName(type), ConvertBetweenSpace(from.ToVariableName(type), from, CoordinateSpace.World, inputType, from)), false); |
|
|
|
pixelShader.AppendLine("float{0} {1} = {2};", DimensionToString(dimension), |
|
|
|
CoordinateSpace.World.ToVariableName(type), ConvertBetweenSpace(from.ToVariableName(type), from, CoordinateSpace.World, inputType, from)); |
|
|
|
pixelShader.AddShaderChunk( |
|
|
|
string.Format("float{0} {1} = {2};", DimensionToString(dimension), |
|
|
|
pixelShader.AppendLine("float{0} {1} = {2};", DimensionToString(dimension), |
|
|
|
ConvertBetweenSpace(from.ToVariableName(type), from, CoordinateSpace.View, inputType, from)), false); |
|
|
|
ConvertBetweenSpace(from.ToVariableName(type), from, CoordinateSpace.View, inputType, from)); |
|
|
|
pixelShader.AddShaderChunk( |
|
|
|
string.Format("float{0} {1} = {2};", DimensionToString(dimension), |
|
|
|
pixelShader.AppendLine("float{0} {1} = {2};", DimensionToString(dimension), |
|
|
|
ConvertBetweenSpace(from.ToVariableName(type), from, CoordinateSpace.Tangent, inputType, from)), false); |
|
|
|
ConvertBetweenSpace(from.ToVariableName(type), from, CoordinateSpace.Tangent, inputType, from)); |
|
|
|
var interpolators = new ShaderGenerator(); |
|
|
|
var vertexDescriptionInputs = new ShaderStringBuilder(3); |
|
|
|
var vertexShader = new ShaderGenerator(); |
|
|
|
var pixelShader = new ShaderGenerator(); |
|
|
|
var surfaceInputs = new ShaderGenerator(); |
|
|
|
var vertexOutputStruct = new ShaderStringBuilder(2); |
|
|
|
|
|
|
|
var vertexShader = new ShaderStringBuilder(2); |
|
|
|
var vertexShaderDescriptionInputs = new ShaderStringBuilder(2); |
|
|
|
var vertexShaderOutputs = new ShaderStringBuilder(1); |
|
|
|
|
|
|
|
var pixelShader = new ShaderStringBuilder(2); |
|
|
|
var pixelShaderSurfaceInputs = new ShaderStringBuilder(2); |
|
|
|
var pixelShaderSurfaceRemap = new ShaderStringBuilder(2); |
|
|
|
interpolators, |
|
|
|
vertexDescriptionInputs, |
|
|
|
vertexOutputStruct, |
|
|
|
vertexShaderDescriptionInputs, |
|
|
|
vertexShaderOutputs, |
|
|
|
surfaceInputs, |
|
|
|
pixelShaderSurfaceInputs, |
|
|
|
shaderGraphRequirements, |
|
|
|
shaderGraphRequirements, |
|
|
|
ShaderGraphRequirements.none, |
|
|
|
|
|
|
vertexDescriptionInputs.AppendLines(vertexShader.GetShaderString(0)); |
|
|
|
vertexShader.AppendLines(vertexShaderDescriptionInputs.ToString()); |
|
|
|
vertexShader.AppendLines(vertexShaderOutputs.ToString()); |
|
|
|
var outputs = new ShaderGenerator(); |
|
|
|
if (node != null) |
|
|
|
{ |
|
|
|
var outputSlot = node.GetOutputSlots<MaterialSlot>().FirstOrDefault(); |
|
|
|
|
|
|
outputs.AddShaderChunk(string.Format("return {0};", AdaptNodeOutputForPreview(node, outputSlot.id, result)), true); |
|
|
|
pixelShaderSurfaceRemap.AppendLine("return {0};", AdaptNodeOutputForPreview(node, outputSlot.id, result)); |
|
|
|
outputs.AddShaderChunk("return 0;", true); |
|
|
|
pixelShaderSurfaceRemap.AppendLine("return 0;"); |
|
|
|
outputs.AddShaderChunk("return surf.PreviewOutput;", false); |
|
|
|
pixelShaderSurfaceRemap.AppendLine("return surf.PreviewOutput;"); |
|
|
|
var res = subShaderTemplate.Replace("${Interpolators}", interpolators.GetShaderString(0)); |
|
|
|
res = res.Replace("${VertexShader}", vertexDescriptionInputs.ToString()); |
|
|
|
res = res.Replace("${LocalPixelShader}", pixelShader.GetShaderString(0)); |
|
|
|
res = res.Replace("${SurfaceInputs}", surfaceInputs.GetShaderString(0)); |
|
|
|
res = res.Replace("${SurfaceOutputRemap}", outputs.GetShaderString(0)); |
|
|
|
var res = subShaderTemplate.Replace("${Interpolators}", vertexOutputStruct.ToString()); |
|
|
|
res = res.Replace("${VertexShader}", vertexShader.ToString()); |
|
|
|
res = res.Replace("${LocalPixelShader}", pixelShader.ToString()); |
|
|
|
res = res.Replace("${SurfaceInputs}", pixelShaderSurfaceInputs.ToString()); |
|
|
|
res = res.Replace("${SurfaceOutputRemap}", pixelShaderSurfaceRemap.ToString()); |
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
float4 frag (GraphVertexOutput IN) : SV_Target |
|
|
|
{ |
|
|
|
${LocalPixelShader} |
|
|
|
|
|
|
|
SurfaceInputs surfaceInput = (SurfaceInputs)0;; |
|
|
|
SurfaceDescriptionInputs surfaceInput = (SurfaceDescriptionInputs)0;; |
|
|
|
|
|
|
|
SurfaceDescription surf = PopulateSurfaceData(surfaceInput); |
|
|
|
${SurfaceOutputRemap} |
|
|
|
} |
|
|
|