浏览代码
New template parser (#1532)
New template parser (#1532)
* Converting template parser to a class to enable recursive $include in the near future * New template parser working with $include, $splice Including dependency tracking on $include * Adding $buildType template command, and cleaning up the code around that. * Bump major version number. Using ShaderStringBuilder. * Don't build slot list twice * Fix view space position for FB case 1064118/main
GitHub
6 年前
当前提交
6d4f0be7
共有 10 个文件被更改,包括 584 次插入 和 479 次删除
-
160com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDPBRPass.template
-
104com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDSubShaderUtilities.cs
-
161com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDUnlitPassForward.template
-
6com.unity.shadergraph/Editor/Data/Implementation/NodeUtils.cs
-
483com.unity.shadergraph/Editor/Data/Util/GraphUtil.cs
-
10com.unity.shadergraph/Editor/Data/Util/ShaderStringBuilder.cs
-
71com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/SharedCode.template.hlsl
-
9com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/SharedCode.template.hlsl.meta
-
50com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/VertexAnimation.template.hlsl
-
9com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/VertexAnimation.template.hlsl.meta
|
|||
FragInputs BuildFragInputs(VaryingsMeshToPS input) |
|||
{ |
|||
FragInputs output; |
|||
ZERO_INITIALIZE(FragInputs, output); |
|||
|
|||
// Init to some default value to make the computer quiet (else it output 'divide by zero' warning even if value is not used). |
|||
// TODO: this is a really poor workaround, but the variable is used in a bunch of places |
|||
// to compute normals which are then passed on elsewhere to compute other values... |
|||
output.worldToTangent = k_identity3x3; |
|||
output.positionSS = input.positionCS; // input.positionCS is SV_Position |
|||
|
|||
$FragInputs.positionRWS: output.positionRWS = input.positionRWS; |
|||
$FragInputs.worldToTangent: output.worldToTangent = BuildWorldToTangent(input.tangentWS, input.normalWS); |
|||
$FragInputs.texCoord0: output.texCoord0 = input.texCoord0; |
|||
$FragInputs.texCoord1: output.texCoord1 = input.texCoord1; |
|||
$FragInputs.texCoord2: output.texCoord2 = input.texCoord2; |
|||
$FragInputs.texCoord3: output.texCoord3 = input.texCoord3; |
|||
$FragInputs.color: output.color = input.color; |
|||
#if SHADER_STAGE_FRAGMENT |
|||
$FragInputs.isFrontFace: output.isFrontFace = IS_FRONT_VFACE(input.cullFace, true, false); // TODO: SHADER_STAGE_FRAGMENT only |
|||
$FragInputs.isFrontFace: // Handle handness of the view matrix (In Unity view matrix default to a determinant of -1) |
|||
$FragInputs.isFrontFace: // when we render a cubemap the view matrix handness is flipped (due to convention used for cubemap) we have a determinant of +1 |
|||
$FragInputs.isFrontFace: output.isFrontFace = _DetViewMatrix < 0.0 ? output.isFrontFace : !output.isFrontFace; |
|||
#endif // SHADER_STAGE_FRAGMENT |
|||
|
|||
return output; |
|||
} |
|||
|
|||
SurfaceDescriptionInputs FragInputsToSurfaceDescriptionInputs(FragInputs input, float3 viewWS) |
|||
{ |
|||
SurfaceDescriptionInputs output; |
|||
ZERO_INITIALIZE(SurfaceDescriptionInputs, output); |
|||
|
|||
$SurfaceDescriptionInputs.WorldSpaceNormal: output.WorldSpaceNormal = normalize(input.worldToTangent[2].xyz); |
|||
$SurfaceDescriptionInputs.ObjectSpaceNormal: output.ObjectSpaceNormal = mul(output.WorldSpaceNormal, (float3x3) UNITY_MATRIX_M); // transposed multiplication by inverse matrix to handle normal scale |
|||
$SurfaceDescriptionInputs.ViewSpaceNormal: output.ViewSpaceNormal = mul(output.WorldSpaceNormal, (float3x3) UNITY_MATRIX_I_V); // transposed multiplication by inverse matrix to handle normal scale |
|||
$SurfaceDescriptionInputs.TangentSpaceNormal: output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); |
|||
$SurfaceDescriptionInputs.WorldSpaceTangent: output.WorldSpaceTangent = input.worldToTangent[0].xyz; |
|||
$SurfaceDescriptionInputs.ObjectSpaceTangent: output.ObjectSpaceTangent = TransformWorldToObjectDir(output.WorldSpaceTangent); |
|||
$SurfaceDescriptionInputs.ViewSpaceTangent: output.ViewSpaceTangent = TransformWorldToViewDir(output.WorldSpaceTangent); |
|||
$SurfaceDescriptionInputs.TangentSpaceTangent: output.TangentSpaceTangent = float3(1.0f, 0.0f, 0.0f); |
|||
$SurfaceDescriptionInputs.WorldSpaceBiTangent: output.WorldSpaceBiTangent = input.worldToTangent[1].xyz; |
|||
$SurfaceDescriptionInputs.ObjectSpaceBiTangent: output.ObjectSpaceBiTangent = TransformWorldToObjectDir(output.WorldSpaceBiTangent); |
|||
$SurfaceDescriptionInputs.ViewSpaceBiTangent: output.ViewSpaceBiTangent = TransformWorldToViewDir(output.WorldSpaceBiTangent); |
|||
$SurfaceDescriptionInputs.TangentSpaceBiTangent: output.TangentSpaceBiTangent = float3(0.0f, 1.0f, 0.0f); |
|||
$SurfaceDescriptionInputs.WorldSpaceViewDirection: output.WorldSpaceViewDirection = normalize(viewWS); |
|||
$SurfaceDescriptionInputs.ObjectSpaceViewDirection: output.ObjectSpaceViewDirection = TransformWorldToObjectDir(output.WorldSpaceViewDirection); |
|||
$SurfaceDescriptionInputs.ViewSpaceViewDirection: output.ViewSpaceViewDirection = TransformWorldToViewDir(output.WorldSpaceViewDirection); |
|||
$SurfaceDescriptionInputs.TangentSpaceViewDirection: float3x3 tangentSpaceTransform = float3x3(output.WorldSpaceTangent,output.WorldSpaceBiTangent,output.WorldSpaceNormal); |
|||
$SurfaceDescriptionInputs.TangentSpaceViewDirection: output.TangentSpaceViewDirection = mul(tangentSpaceTransform, output.WorldSpaceViewDirection); |
|||
$SurfaceDescriptionInputs.WorldSpacePosition: output.WorldSpacePosition = GetAbsolutePositionWS(input.positionRWS); |
|||
$SurfaceDescriptionInputs.ObjectSpacePosition: output.ObjectSpacePosition = TransformWorldToObject(input.positionRWS); |
|||
$SurfaceDescriptionInputs.ViewSpacePosition: output.ViewSpacePosition = TransformWorldToView(input.positionRWS); |
|||
$SurfaceDescriptionInputs.TangentSpacePosition: output.TangentSpacePosition = float3(0.0f, 0.0f, 0.0f); |
|||
$SurfaceDescriptionInputs.ScreenPosition: output.ScreenPosition = ComputeScreenPos(TransformWorldToHClip(input.positionRWS), _ProjectionParams.x); |
|||
$SurfaceDescriptionInputs.uv0: output.uv0 = float4(input.texCoord0, 0.0f, 0.0f); |
|||
$SurfaceDescriptionInputs.uv1: output.uv1 = float4(input.texCoord1, 0.0f, 0.0f); |
|||
$SurfaceDescriptionInputs.uv2: output.uv2 = float4(input.texCoord2, 0.0f, 0.0f); |
|||
$SurfaceDescriptionInputs.uv3: output.uv3 = float4(input.texCoord3, 0.0f, 0.0f); |
|||
$SurfaceDescriptionInputs.VertexColor: output.VertexColor = input.color; |
|||
$SurfaceDescriptionInputs.FaceSign: output.FaceSign = input.isFrontFace; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
// existing HDRP code uses the combined function to go directly from packed to frag inputs |
|||
FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input) |
|||
{ |
|||
VaryingsMeshToPS unpacked= UnpackVaryingsMeshToPS(input); |
|||
return BuildFragInputs(unpacked); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 63ca087b7dde4344bafcf314b6a7df47 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
|
|||
VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh input) |
|||
{ |
|||
VertexDescriptionInputs output; |
|||
ZERO_INITIALIZE(VertexDescriptionInputs, output); |
|||
|
|||
$VertexDescriptionInputs.ObjectSpaceNormal: output.ObjectSpaceNormal = input.normalOS; |
|||
$VertexDescriptionInputs.WorldSpaceNormal: output.WorldSpaceNormal = TransformObjectToWorldNormal(input.normalOS); |
|||
$VertexDescriptionInputs.ViewSpaceNormal: output.ViewSpaceNormal = TransformWorldToViewDir(output.WorldSpaceNormal); |
|||
$VertexDescriptionInputs.TangentSpaceNormal: output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f); |
|||
$VertexDescriptionInputs.ObjectSpaceTangent: output.ObjectSpaceTangent = input.tangentOS; |
|||
$VertexDescriptionInputs.WorldSpaceTangent: output.WorldSpaceTangent = TransformObjectToWorldDir(input.tangentOS.xyz); |
|||
$VertexDescriptionInputs.ViewSpaceTangent: output.ViewSpaceTangent = TransformWorldToViewDir(output.WorldSpaceTangent); |
|||
$VertexDescriptionInputs.TangentSpaceTangent: output.TangentSpaceTangent = float3(1.0f, 0.0f, 0.0f); |
|||
$VertexDescriptionInputs.ObjectSpaceBiTangent: output.ObjectSpaceBiTangent = normalize(cross(input.normalOS, input.tangentOS) * (input.tangentOS.w > 0.0f ? 1.0f : -1.0f) * GetOddNegativeScale()); |
|||
$VertexDescriptionInputs.WorldSpaceBiTangent: output.WorldSpaceBiTangent = TransformObjectToWorldDir(output.ObjectSpaceBiTangent); |
|||
$VertexDescriptionInputs.ViewSpaceBiTangent: output.ViewSpaceBiTangent = TransformWorldToViewDir(output.WorldSpaceBiTangent); |
|||
$VertexDescriptionInputs.TangentSpaceBiTangent: output.TangentSpaceBiTangent = float3(0.0f, 1.0f, 0.0f); |
|||
$VertexDescriptionInputs.ObjectSpacePosition: output.ObjectSpacePosition = input.positionOS; |
|||
$VertexDescriptionInputs.WorldSpacePosition: output.WorldSpacePosition = GetAbsolutePositionWS(TransformObjectToWorld(input.positionOS)); |
|||
$VertexDescriptionInputs.ViewSpacePosition: output.ViewSpacePosition = TransformWorldToView(output.WorldSpacePosition); |
|||
$VertexDescriptionInputs.TangentSpacePosition: output.TangentSpacePosition = float3(0.0f, 0.0f, 0.0f); |
|||
$VertexDescriptionInputs.WorldSpaceViewDirection: output.WorldSpaceViewDirection = GetWorldSpaceNormalizeViewDir(output.WorldSpacePosition); |
|||
$VertexDescriptionInputs.ObjectSpaceViewDirection: output.ObjectSpaceViewDirection = TransformWorldToObjectDir(output.WorldSpaceViewDirection); |
|||
$VertexDescriptionInputs.ViewSpaceViewDirection: output.ViewSpaceViewDirection = TransformWorldToViewDir(output.WorldSpaceViewDirection); |
|||
$VertexDescriptionInputs.TangentSpaceViewDirection: float3x3 tangentSpaceTransform = float3x3(output.WorldSpaceTangent,output.WorldSpaceBiTangent,output.WorldSpaceNormal); |
|||
$VertexDescriptionInputs.TangentSpaceViewDirection: output.TangentSpaceViewDirection = mul(tangentSpaceTransform, output.WorldSpaceViewDirection); |
|||
$VertexDescriptionInputs.ScreenPosition: output.ScreenPosition = ComputeScreenPos(TransformWorldToHClip(output.WorldSpacePosition), _ProjectionParams.x); |
|||
$VertexDescriptionInputs.uv0: output.uv0 = float4(input.uv0, 0.0f, 0.0f); |
|||
$VertexDescriptionInputs.uv1: output.uv1 = float4(input.uv1, 0.0f, 0.0f); |
|||
$VertexDescriptionInputs.uv2: output.uv2 = float4(input.uv2, 0.0f, 0.0f); |
|||
$VertexDescriptionInputs.uv3: output.uv3 = float4(input.uv3, 0.0f, 0.0f); |
|||
$VertexDescriptionInputs.VertexColor: output.VertexColor = input.color; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
AttributesMesh ApplyMeshModification(AttributesMesh input) |
|||
{ |
|||
// build graph inputs |
|||
VertexDescriptionInputs vertexDescriptionInputs = AttributesMeshToVertexDescriptionInputs(input); |
|||
|
|||
// evaluate vertex graph |
|||
VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs); |
|||
|
|||
// copy graph output to the results |
|||
$VertexDescription.Position: input.positionOS = vertexDescription.Position; |
|||
|
|||
return input; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0c7cf800109d94245b1843175a674ab4 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue