Tim Cooper
7 年前
当前提交
f799dd40
共有 24 个文件被更改,包括 403 次插入 和 479 次删除
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/LightWeightShaderPaths.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/MasterNodes/UnlitMasterNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/HDPipeline.meta
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/MasterNodes.meta
-
78MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/HDUnlitPassForward.template
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/HDUnlitPassForward.template.meta
-
78MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/HDUnlitPassForwardDepthOnly.template
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/HDUnlitPassForwardDepthOnly.template.meta
-
201MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/HDPipeline/HDUnlitSubShader.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/HDPipeline/HDUnlitSubShader.cs.meta
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SurfaceModel/MetallicMasterNode.cs.meta
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SurfaceModel/SpecularMasterNode.cs.meta
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SurfaceModel/ProjectSpecificMasterNode.cs.meta
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SurfaceModel/ExportTextureMasterNode.cs.meta
-
97MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SurfaceModel/ProjectSpecificMasterNode.cs
-
156MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SurfaceModel/ExportTextureMasterNode.cs
-
88MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SurfaceModel/MetallicMasterNode.cs
-
87MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SurfaceModel/SpecularMasterNode.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/MasterNodes/PBRMasterNode.cs.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/MasterNodes/UnlitMasterNode.cs.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/MasterNodes/PBRMasterNode.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/MasterNodes/UnlitMasterNode.cs
|
|||
fileFormatVersion: 2 |
|||
guid: 621b9da5e0cd5cc449775c0394b63d58 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: be7d4ec304eccd8489095f90e0909d93 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// Unlit shader always render in forward |
|||
Pass |
|||
{ |
|||
Name "ForwardUnlit" |
|||
Tags { "LightMode" = "ForwardOnly" } |
|||
|
|||
${Tags} |
|||
${Blending} |
|||
${Culling} |
|||
${ZTest} |
|||
${ZWrite} |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma target 4.5 |
|||
#pragma only_renderers d3d11 ps4 vulkan metal // TEMP: until we go further in dev |
|||
//#pragma enable_d3d11_debug_symbols |
|||
|
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
#pragma glsl |
|||
#pragma debug |
|||
|
|||
#define UNITY_MATERIAL_UNLIT // Need to be define before including Material.hlsl |
|||
|
|||
#include "ShaderLibrary/common.hlsl" |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../ShaderPass/FragInputs.hlsl" |
|||
#include "../../ShaderPass/ShaderPass.cs.hlsl" |
|||
|
|||
#define SHADERPASS SHADERPASS_FORWARD_UNLIT |
|||
|
|||
#include "../../Material/Material.hlsl" |
|||
|
|||
${Defines} |
|||
|
|||
// This include will define the various Attributes/Varyings structure |
|||
#include "../../ShaderPass/VaryingMesh.hlsl" |
|||
|
|||
${Graph} |
|||
|
|||
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData) |
|||
{ |
|||
${LocalPixelShader} |
|||
|
|||
SurfaceInputs surfaceInput; |
|||
${SurfaceInputs} |
|||
|
|||
SurfaceDescription surf = PopulateSurfaceData(surfaceInput); |
|||
float3 Color = 0; |
|||
float Alpha = 0; |
|||
${SurfaceOutputRemap} |
|||
|
|||
surfaceData.color = Color; |
|||
|
|||
#ifdef _ALPHATEST_ON |
|||
DoAlphaTest(Alpha, _AlphaCutoff); |
|||
#endif |
|||
|
|||
// Builtin Data |
|||
builtinData.opacity = Alpha; |
|||
builtinData.bakeDiffuseLighting = float3(0.0, 0.0, 0.0); |
|||
builtinData.emissiveIntensity = 0; |
|||
builtinData.emissiveColor = 0; |
|||
builtinData.velocity = float2(0.0, 0.0); |
|||
builtinData.shadowMask0 = 0.0; |
|||
builtinData.shadowMask1 = 0.0; |
|||
builtinData.shadowMask2 = 0.0; |
|||
builtinData.shadowMask3 = 0.0; |
|||
builtinData.distortion = float2(0.0, 0.0); |
|||
builtinData.distortionBlur = 0.0; |
|||
builtinData.depthOffset = 0.0; |
|||
} |
|||
|
|||
#include "../../ShaderPass/ShaderPassForwardUnlit.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6eeaaca43ab129049ae23a1bd89420c4 |
|||
timeCreated: 1481194716 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// Unlit shader always render in forward |
|||
Pass |
|||
{ |
|||
Name "ForwardUnlit" |
|||
Tags { "LightMode" = "DepthForwardOnly" } |
|||
|
|||
${Tags} |
|||
${Blending} |
|||
${Culling} |
|||
${ZTest} |
|||
${ZWrite} |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma target 4.5 |
|||
#pragma only_renderers d3d11 ps4 vulkan metal // TEMP: until we go further in dev |
|||
//#pragma enable_d3d11_debug_symbols |
|||
|
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
#pragma glsl |
|||
#pragma debug |
|||
|
|||
#define UNITY_MATERIAL_UNLIT // Need to be define before including Material.hlsl |
|||
|
|||
#include "ShaderLibrary/common.hlsl" |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../ShaderPass/FragInputs.hlsl" |
|||
#include "../../ShaderPass/ShaderPass.cs.hlsl" |
|||
|
|||
#define SHADERPASS SHADERPASS_DEPTH_ONLY |
|||
|
|||
#include "../../Material/Material.hlsl" |
|||
|
|||
${Defines} |
|||
|
|||
// This include will define the various Attributes/Varyings structure |
|||
#include "../../ShaderPass/VaryingMesh.hlsl" |
|||
|
|||
${Graph} |
|||
|
|||
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData) |
|||
{ |
|||
${LocalPixelShader} |
|||
|
|||
SurfaceInputs surfaceInput; |
|||
${SurfaceInputs} |
|||
|
|||
SurfaceDescription surf = PopulateSurfaceData(surfaceInput); |
|||
float3 Color = 0; |
|||
float Alpha = 0; |
|||
${SurfaceOutputRemap} |
|||
|
|||
surfaceData.color = Color; |
|||
|
|||
#ifdef _ALPHATEST_ON |
|||
DoAlphaTest(Alpha, _AlphaCutoff); |
|||
#endif |
|||
|
|||
// Builtin Data |
|||
builtinData.opacity = Alpha; |
|||
builtinData.bakeDiffuseLighting = float3(0.0, 0.0, 0.0); |
|||
builtinData.emissiveIntensity = 0; |
|||
builtinData.emissiveColor = 0; |
|||
builtinData.velocity = float2(0.0, 0.0); |
|||
builtinData.shadowMask0 = 0.0; |
|||
builtinData.shadowMask1 = 0.0; |
|||
builtinData.shadowMask2 = 0.0; |
|||
builtinData.shadowMask3 = 0.0; |
|||
builtinData.distortion = float2(0.0, 0.0); |
|||
builtinData.distortionBlur = 0.0; |
|||
builtinData.depthOffset = 0.0; |
|||
} |
|||
|
|||
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 43a0f516e224cf14a8b1d58a4aa9b780 |
|||
timeCreated: 1481194716 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
public class HDUnlitSubShader |
|||
{ |
|||
Pass m_UnlitPass = new Pass() |
|||
{ |
|||
Name = "Unlit", |
|||
PixelShaderSlots = new List<int>() |
|||
{ |
|||
UnlitMasterNode.ColorSlotId, |
|||
UnlitMasterNode.AlphaSlotId |
|||
} |
|||
}; |
|||
|
|||
struct Pass |
|||
{ |
|||
public string Name; |
|||
public List<int> VertexShaderSlots; |
|||
public List<int> PixelShaderSlots; |
|||
} |
|||
|
|||
private static string GetShaderPassFromTemplate(string template, UnlitMasterNode masterNode, Pass pass, GenerationMode mode) |
|||
{ |
|||
var surfaceDescriptionFunction = new ShaderGenerator(); |
|||
var surfaceDescriptionStruct = new ShaderGenerator(); |
|||
var shaderFunctionVisitor = new ShaderGenerator(); |
|||
var surfaceInputs = new ShaderGenerator(); |
|||
|
|||
var shaderProperties = new PropertyCollector(); |
|||
|
|||
surfaceInputs.AddShaderChunk("struct SurfaceInputs{", false); |
|||
surfaceInputs.Indent(); |
|||
|
|||
var activeNodeList = ListPool<INode>.Get(); |
|||
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, masterNode, NodeUtils.IncludeSelf.Include, pass.PixelShaderSlots); |
|||
|
|||
var requirements = AbstractMaterialGraph.GetRequirements(activeNodeList); |
|||
|
|||
/* |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresNormal, InterpolatorType.Normal, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresTangent, InterpolatorType.Tangent, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresBitangent, InterpolatorType.BiTangent, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresViewDir, InterpolatorType.ViewDirection, surfaceInputs); |
|||
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresPosition, InterpolatorType.Position, surfaceInputs);*/ |
|||
|
|||
|
|||
ShaderGenerator defines = new ShaderGenerator(); |
|||
|
|||
if (requirements.requiresVertexColor) |
|||
surfaceInputs.AddShaderChunk(string.Format("float4 {0};", ShaderGeneratorNames.VertexColor), false); |
|||
|
|||
/*if (requirements.requiresScreenPosition) |
|||
surfaceInputs.AddShaderChunk(string.Format("float4 {0};", ShaderGeneratorNames.ScreenPosition), false);*/ |
|||
|
|||
foreach (var channel in requirements.requiresMeshUVs.Distinct()) |
|||
{ |
|||
surfaceInputs.AddShaderChunk(string.Format("half4 {0};", channel.GetUVName()), false); |
|||
defines.AddShaderChunk("#define ATTRIBUTES_NEED_TEXCOORD" + (int)channel, true); |
|||
defines.AddShaderChunk("#define VARYINGS_NEED_TEXCOORD" + (int)channel, true); |
|||
} |
|||
|
|||
surfaceInputs.Deindent(); |
|||
surfaceInputs.AddShaderChunk("};", false); |
|||
|
|||
var slots = new List<MaterialSlot>(); |
|||
foreach (var id in pass.PixelShaderSlots) |
|||
{ |
|||
var slot = masterNode.FindSlot<MaterialSlot>(id); |
|||
if (slot != null) |
|||
slots.Add(slot); |
|||
} |
|||
AbstractMaterialGraph.GenerateSurfaceDescriptionStruct(surfaceDescriptionStruct, slots, true); |
|||
|
|||
var usedSlots = new List<MaterialSlot>(); |
|||
foreach (var id in pass.PixelShaderSlots) |
|||
usedSlots.Add(masterNode.FindSlot<MaterialSlot>(id)); |
|||
|
|||
AbstractMaterialGraph.GenerateSurfaceDescription( |
|||
activeNodeList, |
|||
masterNode, |
|||
masterNode.owner as AbstractMaterialGraph, |
|||
surfaceDescriptionFunction, |
|||
shaderFunctionVisitor, |
|||
shaderProperties, |
|||
requirements, |
|||
mode, |
|||
"PopulateSurfaceData", |
|||
"SurfaceDescription", |
|||
null, |
|||
null, |
|||
usedSlots); |
|||
|
|||
var graph = new ShaderGenerator(); |
|||
graph.AddShaderChunk(shaderFunctionVisitor.GetShaderString(2), false); |
|||
graph.AddShaderChunk(surfaceInputs.GetShaderString(2), false); |
|||
graph.AddShaderChunk(surfaceDescriptionStruct.GetShaderString(2), false); |
|||
graph.AddShaderChunk(shaderProperties.GetPropertiesDeclaration(2), false); |
|||
graph.AddShaderChunk(surfaceDescriptionFunction.GetShaderString(2), false); |
|||
|
|||
var tagsVisitor = new ShaderGenerator(); |
|||
var blendingVisitor = new ShaderGenerator(); |
|||
var cullingVisitor = new ShaderGenerator(); |
|||
var zTestVisitor = new ShaderGenerator(); |
|||
var zWriteVisitor = new ShaderGenerator(); |
|||
|
|||
var materialOptions = new SurfaceMaterialOptions(); |
|||
materialOptions.GetTags(tagsVisitor); |
|||
materialOptions.GetBlend(blendingVisitor); |
|||
materialOptions.GetCull(cullingVisitor); |
|||
materialOptions.GetDepthTest(zTestVisitor); |
|||
materialOptions.GetDepthWrite(zWriteVisitor); |
|||
|
|||
var localPixelShader = new ShaderGenerator(); |
|||
var localSurfaceInputs = new ShaderGenerator(); |
|||
var surfaceOutputRemap = new ShaderGenerator(); |
|||
|
|||
var reqs = ShaderGraphRequirements.none; |
|||
reqs.requiresNormal |= NeededCoordinateSpace.World; |
|||
reqs.requiresTangent |= NeededCoordinateSpace.World; |
|||
reqs.requiresBitangent |= NeededCoordinateSpace.World; |
|||
reqs.requiresPosition |= NeededCoordinateSpace.World; |
|||
reqs.requiresViewDir |= NeededCoordinateSpace.World; |
|||
|
|||
foreach (var channel in requirements.requiresMeshUVs.Distinct()) |
|||
localSurfaceInputs.AddShaderChunk(string.Format("surfaceInput.{0} = {1};", channel.GetUVName(), string.Format("half4(input.texCoord{0}, 0, 0)", (int)channel)), false); |
|||
|
|||
/*ShaderGenerator.GenerateStandardTransforms( |
|||
3, |
|||
10, |
|||
interpolators, |
|||
localVertexShader, |
|||
localPixelShader, |
|||
localSurfaceInputs, |
|||
requirements, |
|||
reqs, |
|||
CoordinateSpace.World);*/ |
|||
|
|||
var templateLocation = ShaderGenerator.GetTemplatePath(template); |
|||
|
|||
foreach (var slot in usedSlots) |
|||
{ |
|||
surfaceOutputRemap.AddShaderChunk(slot.shaderOutputName |
|||
+ " = surf." |
|||
+ slot.shaderOutputName + ";", true); |
|||
} |
|||
|
|||
if (!File.Exists(templateLocation)) |
|||
return string.Empty; |
|||
|
|||
var subShaderTemplate = File.ReadAllText(templateLocation); |
|||
var resultPass = subShaderTemplate.Replace("${Defines}", defines.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${Graph}", graph.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${LocalPixelShader}", localPixelShader.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${SurfaceInputs}", localSurfaceInputs.GetShaderString(3)); |
|||
resultPass = resultPass.Replace("${SurfaceOutputRemap}", surfaceOutputRemap.GetShaderString(3)); |
|||
|
|||
resultPass = resultPass.Replace("${Tags}", tagsVisitor.GetShaderString(2)); |
|||
resultPass = resultPass.Replace("${Blending}", blendingVisitor.GetShaderString(2)); |
|||
resultPass = resultPass.Replace("${Culling}", cullingVisitor.GetShaderString(2)); |
|||
resultPass = resultPass.Replace("${ZTest}", zTestVisitor.GetShaderString(2)); |
|||
resultPass = resultPass.Replace("${ZWrite}", zWriteVisitor.GetShaderString(2)); |
|||
resultPass = resultPass.Replace("${LOD}", "" + materialOptions.lod); |
|||
return resultPass; |
|||
} |
|||
|
|||
public IEnumerable<string> GetSubshader(UnlitMasterNode masterNode, GenerationMode mode) |
|||
{ |
|||
var subShader = new ShaderGenerator(); |
|||
subShader.AddShaderChunk("SubShader", true); |
|||
subShader.AddShaderChunk("{", true); |
|||
subShader.Indent(); |
|||
subShader.AddShaderChunk("Tags{ \"RenderType\" = \"Opaque\" }", true); |
|||
|
|||
subShader.AddShaderChunk( |
|||
GetShaderPassFromTemplate( |
|||
"HDUnlitPassForwardDepthOnly.template", |
|||
masterNode, |
|||
m_UnlitPass, |
|||
mode), |
|||
true); |
|||
|
|||
subShader.AddShaderChunk( |
|||
GetShaderPassFromTemplate( |
|||
"HDUnlitPassForward.template", |
|||
masterNode, |
|||
m_UnlitPass, |
|||
mode), |
|||
true); |
|||
|
|||
subShader.Deindent(); |
|||
subShader.AddShaderChunk("}", true); |
|||
|
|||
return new[] { subShader.GetShaderString(0) }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 292c6a3c80161fa4cb49a9d11d35cbe9 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 42127be94ae3fe2469834cecaa1a185e |
|||
timeCreated: 1478188276 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ce805d849104fa244b396c52f2531f13 |
|||
timeCreated: 1478188276 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c9237152ca800cd48a60f04edac61381 |
|||
timeCreated: 1481184633 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 318b40c0b58f791468e39e5c358b64be |
|||
timeCreated: 1495482393 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
/*using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Text.RegularExpressions; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public abstract class ProjectSpecificMasterNode : AbstractMasterNode |
|||
{ |
|||
public override string GetSubShader(GenerationMode mode) |
|||
{ |
|||
|
|||
} |
|||
|
|||
public override string GetFullShader( |
|||
GenerationMode mode, |
|||
out List<PropertyGenerator.TextureInfo> configuredTextures) |
|||
{ |
|||
var shaderTemplateLocation = ShaderGenerator.GetTemplatePath("shader.template"); |
|||
|
|||
if (!File.Exists(shaderTemplateLocation)) |
|||
{ |
|||
configuredTextures = new List<PropertyGenerator.TextureInfo>(); |
|||
return string.Empty; |
|||
} |
|||
|
|||
var templateText = File.ReadAllText(shaderTemplateLocation); |
|||
|
|||
var shaderBodyVisitor = new ShaderGenerator(); |
|||
var shaderFunctionVisitor = new ShaderGenerator(); |
|||
var shaderPropertiesVisitor = new PropertyGenerator(); |
|||
var shaderPropertyUsagesVisitor = new ShaderGenerator(); |
|||
var shaderInputVisitor = new ShaderGenerator(); |
|||
var vertexShaderBlock = new ShaderGenerator(); |
|||
|
|||
GenerateSurfaceShaderInternal( |
|||
shaderBodyVisitor, |
|||
shaderFunctionVisitor, |
|||
shaderInputVisitor, |
|||
vertexShaderBlock, |
|||
shaderPropertiesVisitor, |
|||
shaderPropertyUsagesVisitor, |
|||
mode); |
|||
|
|||
var tagsVisitor = new ShaderGenerator(); |
|||
var blendingVisitor = new ShaderGenerator(); |
|||
var cullingVisitor = new ShaderGenerator(); |
|||
var zTestVisitor = new ShaderGenerator(); |
|||
var zWriteVisitor = new ShaderGenerator(); |
|||
|
|||
m_MaterialOptions.GetTags(tagsVisitor); |
|||
m_MaterialOptions.GetBlend(blendingVisitor); |
|||
m_MaterialOptions.GetCull(cullingVisitor); |
|||
m_MaterialOptions.GetDepthTest(zTestVisitor); |
|||
m_MaterialOptions.GetDepthWrite(zWriteVisitor); |
|||
|
|||
var resultShader = templateText.Replace("${ShaderName}", GetType() + guid.ToString()); |
|||
resultShader = resultShader.Replace("${ShaderPropertiesHeader}", shaderPropertiesVisitor.GetShaderString(2)); |
|||
resultShader = resultShader.Replace("${ShaderPropertyUsages}", shaderPropertyUsagesVisitor.GetShaderString(2)); |
|||
resultShader = resultShader.Replace("${LightingFunctionName}", GetLightFunction()); |
|||
resultShader = resultShader.Replace("${SurfaceOutputStructureName}", GetSurfaceOutputName()); |
|||
resultShader = resultShader.Replace("${ShaderFunctions}", shaderFunctionVisitor.GetShaderString(2)); |
|||
resultShader = resultShader.Replace("${ShaderInputs}", shaderInputVisitor.GetShaderString(3)); |
|||
resultShader = resultShader.Replace("${PixelShaderBody}", shaderBodyVisitor.GetShaderString(3)); |
|||
resultShader = resultShader.Replace("${Tags}", tagsVisitor.GetShaderString(2)); |
|||
resultShader = resultShader.Replace("${Blending}", blendingVisitor.GetShaderString(2)); |
|||
resultShader = resultShader.Replace("${Culling}", cullingVisitor.GetShaderString(2)); |
|||
resultShader = resultShader.Replace("${ZTest}", zTestVisitor.GetShaderString(2)); |
|||
resultShader = resultShader.Replace("${ZWrite}", zWriteVisitor.GetShaderString(2)); |
|||
|
|||
resultShader = resultShader.Replace("${VertexShaderDecl}", "vertex:vert"); |
|||
resultShader = resultShader.Replace("${VertexShaderBody}", vertexShaderBlock.GetShaderString(3)); |
|||
|
|||
configuredTextures = shaderPropertiesVisitor.GetConfiguredTexutres(); |
|||
|
|||
return Regex.Replace(resultShader, @"\r\n|\n\r|\n|\r", Environment.NewLine); |
|||
|
|||
} |
|||
|
|||
private void GenerateSurfaceShaderInternal( |
|||
ShaderGenerator propertyUsages, |
|||
GenerationMode mode) |
|||
{ |
|||
var activeNodeList = new List<INode>(); |
|||
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, this); |
|||
|
|||
foreach (var node in activeNodeList.OfType<AbstractMaterialNode>()) |
|||
{ |
|||
node.GeneratePropertyUsages(propertyUsages, mode); |
|||
} |
|||
|
|||
} |
|||
} |
|||
}*/ |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Text.RegularExpressions; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
/* [Serializable] |
|||
[Title("Master", "Custom Texture")] |
|||
public class ExportTextureMasterNode : MasterNode |
|||
{ |
|||
public const string ColorSlotName = "Color"; |
|||
public const int ColorSlotId = 0; |
|||
|
|||
public ExportTextureMasterNode() |
|||
{ |
|||
name = "ExportTextureMasterNode"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, SlotValueType.Vector4, Vector4.zero)); |
|||
|
|||
// clear out slot names that do not match the slots we support
|
|||
RemoveSlotsNameNotMatching(new[] { ColorSlotId }); |
|||
} |
|||
|
|||
public override PreviewMode previewMode |
|||
{ |
|||
get |
|||
{ |
|||
return PreviewMode.Preview2D; |
|||
} |
|||
} |
|||
|
|||
public override string GetSubShader(GenerationMode mode, PropertyCollector shaderPropertiesVisitor) |
|||
{ |
|||
return ""; |
|||
} |
|||
|
|||
public override bool has3DPreview() |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
public override string GetFullShader(GenerationMode generationMode, string name, out List<PropertyCollector.TextureInfo> configuredTextures) |
|||
{ |
|||
// figure out what kind of preview we want!
|
|||
var activeNodeList = ListPool<INode>.Get(); |
|||
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, this); |
|||
|
|||
string templateLocation = ShaderGenerator.GetTemplatePath("ExportTexture.template"); |
|||
if (!File.Exists(templateLocation)) |
|||
{ |
|||
configuredTextures = new List<PropertyCollector.TextureInfo>(); |
|||
return string.Empty; |
|||
} |
|||
|
|||
string template = File.ReadAllText(templateLocation); |
|||
|
|||
var shaderBodyVisitor = new ShaderGenerator(); |
|||
var shaderFunctionVisitor = new ShaderGenerator(); |
|||
var shaderPropertiesVisitor = new PropertyCollector(); |
|||
var shaderPropertyUsagesVisitor = new ShaderGenerator(); |
|||
var shaderInputVisitor = new ShaderGenerator(); |
|||
|
|||
// always add color because why not.
|
|||
shaderInputVisitor.AddShaderChunk("float4 color : COLOR;", true); |
|||
|
|||
bool needBitangent = activeNodeList.OfType<IMayRequireBitangent>().Any(x => x.RequiresBitangent()); |
|||
bool needsWorldPos = activeNodeList.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection()); |
|||
if (needsWorldPos || activeNodeList.OfType<IMayRequireWorldPosition>().Any(x => x.RequiresWorldPosition())) |
|||
{ |
|||
shaderBodyVisitor.AddShaderChunk("float3 " + ShaderGeneratorNames.WorldSpacePosition + " = float3(0.0, 0.0, 0.0);", true); |
|||
} |
|||
|
|||
if (needBitangent || activeNodeList.OfType<IMayRequireNormal>().Any(x => x.RequiresNormal())) |
|||
{ |
|||
shaderBodyVisitor.AddShaderChunk("float3 " + ShaderGeneratorNames.WorldSpaceNormal + " = float3(0.0, 0.0, 1.0);", true); |
|||
} |
|||
|
|||
for (int uvIndex = 0; uvIndex < ShaderGeneratorNames.UVCount; ++uvIndex) |
|||
{ |
|||
var channel = (UVChannel)uvIndex; |
|||
if (activeNodeList.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV(channel))) |
|||
{ |
|||
shaderBodyVisitor.AddShaderChunk("half4 " + channel.GetUVName() + " = float4(IN.localTexcoord.xyz,1.0);", true); |
|||
} |
|||
} |
|||
|
|||
if (activeNodeList.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection())) |
|||
{ |
|||
shaderBodyVisitor.AddShaderChunk("float3 " + ShaderGeneratorNames.WorldSpaceViewDirection + " = float3(0.0, 0.0, -1.0);", true); |
|||
} |
|||
|
|||
if (activeNodeList.OfType<IMayRequireScreenPosition>().Any(x => x.RequiresScreenPosition())) |
|||
{ |
|||
shaderBodyVisitor.AddShaderChunk("half4 " + ShaderGeneratorNames.ScreenPosition + " = float4(IN.globalTexcoord.xyz, 1.0);", true); |
|||
} |
|||
if (needBitangent || activeNodeList.OfType<IMayRequireTangent>().Any(x => x.RequiresTangent())) |
|||
{ |
|||
shaderBodyVisitor.AddShaderChunk("float3 " + ShaderGeneratorNames.WorldSpaceTangent + " = float3(1.0,0.0,0.0);", true); |
|||
} |
|||
if (needBitangent) |
|||
{ |
|||
shaderBodyVisitor.AddShaderChunk("float3 " + ShaderGeneratorNames.WorldSpaceBitangent + " = float3(0.0,1.0,0.0);", true); |
|||
} |
|||
|
|||
if (activeNodeList.OfType<IMayRequireVertexColor>().Any(x => x.RequiresVertexColor())) |
|||
{ |
|||
shaderBodyVisitor.AddShaderChunk("float4 " + ShaderGeneratorNames.VertexColor + " = float4(1.0,1.0,1.0,1.0);", true); |
|||
} |
|||
|
|||
foreach (var activeNode in activeNodeList.OfType<AbstractMaterialNode>()) |
|||
{ |
|||
if (activeNode is IGeneratesFunction) |
|||
(activeNode as IGeneratesFunction).GenerateNodeFunction(shaderFunctionVisitor, generationMode); |
|||
if (activeNode is IGeneratesBodyCode) |
|||
(activeNode as IGeneratesBodyCode).GenerateNodeCode(shaderBodyVisitor, generationMode); |
|||
|
|||
activeNode.GeneratePropertyBlock(shaderPropertiesVisitor, generationMode); |
|||
activeNode.GeneratePropertyUsages(shaderPropertyUsagesVisitor, generationMode); |
|||
} |
|||
|
|||
var inputSlot = GetInputSlots<MaterialSlot>().First(); |
|||
var edges = owner.GetEdges(inputSlot.slotReference); |
|||
if (edges.Count() > 0) |
|||
{ |
|||
var outputRef = edges.First().outputSlot; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid); |
|||
shaderBodyVisitor.AddShaderChunk("return " + fromNode.GetVariableNameForSlot(outputRef.slotId) + ";", true); |
|||
} |
|||
else |
|||
{ |
|||
shaderBodyVisitor.AddShaderChunk("return float4(0.5, 0.5, 0.5, 0.5);", true); |
|||
} |
|||
|
|||
ListPool<INode>.Release(activeNodeList); |
|||
|
|||
template = template.Replace("${ShaderName}", name); |
|||
template = template.Replace("${ShaderPropertiesHeader}", shaderPropertiesVisitor.GetPropertiesBlock(2)); |
|||
template = template.Replace("${ShaderPropertyUsages}", shaderPropertyUsagesVisitor.GetShaderString(3)); |
|||
template = template.Replace("${ShaderFunctions}", shaderFunctionVisitor.GetShaderString(3)); |
|||
template = template.Replace("${PixelShaderBody}", shaderBodyVisitor.GetShaderString(4)); |
|||
|
|||
//In preview mode we use a different vertex shader, as the custom texture shaders are customized and not preview compatible.
|
|||
template = template.Replace("${ShaderIsUsingPreview}", generationMode == GenerationMode.Preview ? "_Preview" : ""); |
|||
|
|||
configuredTextures = shaderPropertiesVisitor.GetConfiguredTexutres(); |
|||
return Regex.Replace(template, @"\r\n|\n\r|\n|\r", Environment.NewLine); |
|||
} |
|||
}*/ |
|||
} |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
/* [Serializable] |
|||
[Title("Master", "Metallic")] |
|||
public class MetallicMasterNode : AbstractSurfaceMasterNode |
|||
{ |
|||
public const string MetallicSlotName = "Metallic"; |
|||
public const int MetallicSlotId = 2; |
|||
|
|||
public const string LightFunctionName = "Standard"; |
|||
public const string SurfaceOutputStructureName = "SurfaceOutputStandard"; |
|||
|
|||
public MetallicMasterNode() |
|||
{ |
|||
name = "MetallicMasterNode"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(VertexOffsetId, VertexOffsetName, VertexOffsetName, SlotType.Input, SlotValueType.Vector3, Vector4.zero, ShaderStage.Vertex)); |
|||
AddSlot(new MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero, ShaderStage.Fragment)); |
|||
AddSlot(new MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero, ShaderStage.Fragment)); |
|||
AddSlot(new MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero, ShaderStage.Fragment)); |
|||
AddSlot(new MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero, ShaderStage.Fragment)); |
|||
AddSlot(new MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero, ShaderStage.Fragment)); |
|||
AddSlot(new MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero, ShaderStage.Fragment)); |
|||
AddSlot(new MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero, ShaderStage.Fragment)); |
|||
|
|||
// clear out slot names that do not match the slots
|
|||
// we support
|
|||
RemoveSlotsNameNotMatching( |
|||
new[] |
|||
{ |
|||
AlbedoSlotId, |
|||
NormalSlotId, |
|||
EmissionSlotId, |
|||
MetallicSlotId, |
|||
SmoothnessSlotId, |
|||
OcclusionSlotId, |
|||
AlphaSlotId, |
|||
VertexOffsetId |
|||
}); |
|||
} |
|||
|
|||
protected override int[] surfaceInputs |
|||
{ |
|||
get |
|||
{ |
|||
return new[] |
|||
{ |
|||
AlbedoSlotId, |
|||
NormalSlotId, |
|||
EmissionSlotId, |
|||
MetallicSlotId, |
|||
SmoothnessSlotId, |
|||
OcclusionSlotId, |
|||
AlphaSlotId, |
|||
}; |
|||
} |
|||
} |
|||
|
|||
|
|||
protected override int[] vertexInputs |
|||
{ |
|||
get |
|||
{ |
|||
return new[] |
|||
{ |
|||
VertexOffsetId |
|||
}; |
|||
} |
|||
} |
|||
|
|||
public override string GetSurfaceOutputName() |
|||
{ |
|||
return SurfaceOutputStructureName; |
|||
} |
|||
|
|||
public override string GetLightFunction() |
|||
{ |
|||
return LightFunctionName; |
|||
} |
|||
}*/ |
|||
} |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
/* [Serializable] |
|||
[Title("Master", "Specular")] |
|||
public class SpecularMasterNode : AbstractSurfaceMasterNode |
|||
{ |
|||
public const string SpecularSlotName = "Specular"; |
|||
public const int SpecularSlotId = 2; |
|||
|
|||
public const string LightFunctionName = "StandardSpecular"; |
|||
public const string SurfaceOutputStructureName = "SurfaceOutputStandardSpecular"; |
|||
|
|||
public SpecularMasterNode() |
|||
{ |
|||
name = "SpecularMasterNode"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
protected override int[] surfaceInputs |
|||
{ |
|||
get |
|||
{ |
|||
return new[] |
|||
{ |
|||
AlbedoSlotId, |
|||
NormalSlotId, |
|||
EmissionSlotId, |
|||
SmoothnessSlotId, |
|||
OcclusionSlotId, |
|||
AlphaSlotId, |
|||
SpecularSlotId |
|||
}; |
|||
} |
|||
} |
|||
|
|||
|
|||
protected override int[] vertexInputs |
|||
{ |
|||
get |
|||
{ |
|||
return new[] |
|||
{ |
|||
VertexOffsetId |
|||
}; |
|||
} |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(VertexOffsetId, VertexOffsetName, VertexOffsetName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(SpecularSlotId, SpecularSlotName, SpecularSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
|
|||
// clear out slot names that do not match the slots
|
|||
// we support
|
|||
RemoveSlotsNameNotMatching( |
|||
new[] |
|||
{ |
|||
AlbedoSlotId, |
|||
NormalSlotId, |
|||
EmissionSlotId, |
|||
SpecularSlotId, |
|||
SmoothnessSlotId, |
|||
OcclusionSlotId, |
|||
AlphaSlotId |
|||
}); |
|||
} |
|||
|
|||
public override string GetSurfaceOutputName() |
|||
{ |
|||
return SurfaceOutputStructureName; |
|||
} |
|||
|
|||
public override string GetLightFunction() |
|||
{ |
|||
return LightFunctionName; |
|||
} |
|||
}*/ |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue