浏览代码

Temp integration approach : use the common define approach

/scriptablerenderloop-materialgraph
Paul Demeulenaere 8 年前
当前提交
f1f73e08
共有 3 个文件被更改,包括 37 次插入42 次删除
  1. 35
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderloopMaterialGraph.cs
  2. 22
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.template
  3. 22
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitSharePass.template

35
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderloopMaterialGraph.cs


public string vertexCode;
public string pixelCode;
public string fragInputTarget;
public string[] tempAdditionnalDefine; //only for first version purpose : use common define system
};
private string GenerateLitDataTemplate(GenerationMode mode, string useSurfaceDataInput, string useSurfaceFragInput, PropertyGenerator propertyGenerator, ShaderGenerator propertyUsagesVisitor, ShaderGenerator shaderFunctionVisitor, string litShareTemplate)

vayringName = "texCoord" + iTexCoord,
type = SlotValueType.Vector2,
vertexCode = string.Format("output.texCoord{0} = input.texCoord{0};", iTexCoord),
pixelCode = string.Format("float4 {0} = float4(fragInput.texCoord{1}, 0, 0);", ShaderGeneratorNames.GetUVName((UVChannel)iTexCoord), iTexCoord)
pixelCode = string.Format("float4 {0} = float4(fragInput.texCoord{1}, 0, 0);", ShaderGeneratorNames.GetUVName((UVChannel)iTexCoord), iTexCoord),
tempAdditionnalDefine = new string[] { "ATTRIBUTES_NEED_TEXCOORD" + iTexCoord, "VARYINGS_NEED_TEXCOORD" + iTexCoord }
});
}
}

type = SlotValueType.Vector3,
vertexCode = "output.tangentWS = TransformObjectToWorldDir(input.tangentOS.xyz);",
fragInputTarget = "tangentToWorld[0]",
pixelCode = string.Format("float3 {0} = normalize(fragInput.tangentToWorld[0]);", ShaderGeneratorNames.WorldSpaceTangent)
pixelCode = string.Format("float3 {0} = normalize(fragInput.tangentToWorld[0]);", ShaderGeneratorNames.WorldSpaceTangent),
tempAdditionnalDefine = new string[] { "ATTRIBUTES_NEED_NORMAL", "ATTRIBUTES_NEED_TANGENT", "VARYINGS_NEED_TANGENT_TO_WORLD" }
});
}

type = SlotValueType.Vector3,
vertexCode = "output.normalWS = TransformObjectToWorldNormal(input.normalOS);",
fragInputTarget = "tangentToWorld[2]",
pixelCode = string.Format("float3 {0} = normalize(fragInput.tangentToWorld[2]);", ShaderGeneratorNames.WorldSpaceNormal)
pixelCode = string.Format("float3 {0} = normalize(fragInput.tangentToWorld[2]);", ShaderGeneratorNames.WorldSpaceNormal),
tempAdditionnalDefine = new string[] { "ATTRIBUTES_NEED_NORMAL", "ATTRIBUTES_NEED_TANGENT", "VARYINGS_NEED_TANGENT_TO_WORLD" }
});
}

type = SlotValueType.Vector3,
vertexCode = "output.bitangentWS = CreateBitangent(output.normalWS, output.tangentWS, input.tangentOS.w);",
fragInputTarget = "tangentToWorld[1]",
pixelCode = string.Format("float3 {0} = normalize(fragInput.tangentToWorld[1]);", ShaderGeneratorNames.WorldSpaceBitangent)
pixelCode = string.Format("float3 {0} = normalize(fragInput.tangentToWorld[1]);", ShaderGeneratorNames.WorldSpaceBitangent),
tempAdditionnalDefine = new string[] { "ATTRIBUTES_NEED_NORMAL", "ATTRIBUTES_NEED_TANGENT", "VARYINGS_NEED_TANGENT_TO_WORLD" }
});
}

vayringName = "positionWS",
type = SlotValueType.Vector3,
vertexCode = "output.positionWS = TransformObjectToWorld(input.positionOS);",
pixelCode = string.Format("float3 {0} = fragInput.positionWS;", ShaderGeneratorNames.WorldSpacePosition)
pixelCode = string.Format("float3 {0} = fragInput.positionWS;", ShaderGeneratorNames.WorldSpacePosition),
tempAdditionnalDefine = new string[] { "VARYINGS_NEED_POSITION_WS" }
});
}

vayringName = "vertexColor",
type = SlotValueType.Vector4,
vertexCode = "output.vertexColor = input.vertexColor;",
pixelCode = string.Format("float4 {0} = fragInput.vertexColor;", "vertexColor")
pixelCode = string.Format("float4 {0} = fragInput.color;", ShaderGeneratorNames.VertexColor),
tempAdditionnalDefine = new string[] { "ATTRIBUTES_NEED_COLOR", "VARYINGS_NEED_COLOR" }
});
}

resultShader = resultShader.Replace("${PackingVaryingCode}", packInterpolatorVisitor.GetShaderString(1));
resultShader = resultShader.Replace("${UnpackVaryingCode}", unpackInterpolatorVisitor.GetShaderString(1));
resultShader = resultShader.Replace("${VertexShaderBody}", vertexShaderBodyVisitor.GetShaderString(1));
/* temporary behavior : use common define system */
var tempAdditionnalDefine = new ShaderGenerator();
foreach (var define in vayrings.Where(o => o.tempAdditionnalDefine != null).SelectMany(o => o.tempAdditionnalDefine).Distinct())
{
tempAdditionnalDefine.AddShaderChunk(string.Format("#define {0}", define), false);
}
resultShader = resultShader.Replace("${TemporaryAdditionnalDefines}", tempAdditionnalDefine.GetShaderString(1));
return resultShader;
}

22
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.template


float _AlphaCutoff;
#pragma vertex Vert
#pragma fragment Frag
ENDHLSL
SubShader

Cull [_CullMode]
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#define SHADERPASS SHADERPASS_GBUFFER
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Material.hlsl"

#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl"
ENDHLSL
}
/*
// ------------------------------------------------------------------
// Debug pass
// ------------------------------------------------------------------

Cull[_CullMode]
HLSLPROGRAM
#pragma vertex VertDefault
#pragma fragment Frag
#define SHADERPASS SHADERPASS_DEBUG_VIEW_MATERIAL
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Material.hlsl"

ENDHLSL
}
// ------------------------------------------------------------------
// Extracts information for lightmapping, GI (emission, albedo, ...)
// This pass it not used during regular rendering.

// Lightmap memo
// DYNAMICLIGHTMAP_ON is used when we have an "enlighten lightmap" ie a lightmap updated at runtime by enlighten.This lightmap contain indirect lighting from realtime lights and realtime emissive material.Offline baked lighting(from baked material / light,
// both direct and indirect lighting) will hand up in the "regular" lightmap->LIGHTMAP_ON.
#pragma vertex VertDefault
#pragma fragment Frag
#define SHADERPASS SHADERPASS_LIGHT_TRANSPORT
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Material.hlsl"

HLSLPROGRAM
#pragma vertex VertDefault
#pragma fragment Frag
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Material.hlsl"

HLSLPROGRAM
#pragma vertex VertDefault
#pragma fragment Frag
#define SHADERPASS SHADERPASS_FORWARD
// TEMP until pragma work in include
// #include "../../Lighting/Forward.hlsl"

ENDHLSL
}
*/
}
CustomEditor "Experimental.ScriptableRenderLoop.LitGraphUI"
}

22
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitSharePass.template


#define UnpackNormal(x) UnpackNormalAG(x, 1.0)
#if SHADERPASS == SHADERPASS_LIGHT_TRANSPORT
CBUFFER_START(UnityMetaPass)
// x = use uv1 as raster position
// y = use uv2 as raster position
bool4 unity_MetaVertexControl;
// x = return albedo
// y = return normal
bool4 unity_MetaFragmentControl;
CBUFFER_END
// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency
float unity_OneOverOutputBoost;
float unity_MaxOutputValue;
#endif
void GetSurfaceAndBuiltinData(FragInputs fragInput, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
{
ZERO_INITIALIZE(SurfaceData, surfaceData);

#endif
}
#if 1 //lazy implementation, use define approach
//Sth with some define generated=
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl"
#if 1 //lazy implementation : use define approach
${TemporaryAdditionnalDefines}
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl"
#else
//WIP : old implementation (needs refactor to use this approach, should be better packing)
struct Attributes

正在加载...
取消
保存