浏览代码

Fix CustomTexture preview

/main
Florent Guinier 8 年前
当前提交
8012f9e3
共有 2 个文件被更改,包括 17 次插入4 次删除
  1. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/ExportTexture.template
  2. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/ExportTextureMasterNode.cs

13
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/ExportTexture.template


{
CGPROGRAM
#include "UnityCustomRenderTexture.cginc"
#pragma vertex CustomRenderTextureVertexShader
#pragma vertex CustomRenderTextureVertexShader${ShaderIsUsingPreview}
v2f_customrendertexture CustomRenderTextureVertexShader_Preview(appdata_base IN)
{
v2f_customrendertexture OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.primitiveID = 0;//TODO
OUT.localTexcoord = IN.texcoord;
OUT.globalTexcoord = IN.texcoord;
OUT.direction = CustomRenderTextureComputeCubeDirection(OUT.globalTexcoord.xy);
return OUT;
}
${ShaderPropertyUsages}

8
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/ExportTextureMasterNode.cs


namespace UnityEngine.MaterialGraph
{
[Serializable]
[Title("Master/Export Texture")]
[Title("Master/Custom Texture")]
public class ExportTextureMasterNode : AbstractMasterNode
{
public const string ColorSlotName = "Color";

return false;
}
public override string GetFullShader(GenerationMode mode, out List<PropertyGenerator.TextureInfo> configuredTextures)
public override string GetFullShader(GenerationMode generationMode, out List<PropertyGenerator.TextureInfo> configuredTextures)
{
// figure out what kind of preview we want!

shaderBodyVisitor.AddShaderChunk("float4 " + ShaderGeneratorNames.VertexColor + " = float4(1.0,1.0,1.0,1.0);", true);
}
var generationMode = GenerationMode.Preview;
foreach (var activeNode in activeNodeList.OfType<AbstractMaterialNode>())
{
if (activeNode is IGeneratesFunction)

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);

正在加载...
取消
保存