浏览代码

Fix normalizations in Shader Graph with LWRP (#1571)

* Remove double normalization
* Update changelog
* Normalize tangent and bitangent in pixel remap
* Fixes for PR
- Do correct normalization
- Update changelog
- Update importer version
* Missing post-processing submodule update
* Fixes to changelog
/main
GitHub 6 年前
当前提交
953cdf48
共有 3 个文件被更改,包括 8 次插入7 次删除
  1. 1
      com.unity.shadergraph/CHANGELOG.md
  2. 12
      com.unity.shadergraph/Editor/Data/Util/ShaderGenerator.cs
  3. 2
      com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs

1
com.unity.shadergraph/CHANGELOG.md


- If the current render pipeline is not compatible, master nodes now display an error badge.
- The preview shader now only considers the current render pipeline. Because of this there is less code to compile, and therefore the preview shader will compile faster.
- When you rename a shader graph or sub shader graph locally on your disk, the title of the Shader Graph window, black board, and preview also updates.
- The Lightweight PBR subshader now normalizes normal, tangent, and view direction correctly.
- Texture 2D Array and Texture 3D nodes can no longer be used in the vertex shader.
- Shader graphs using alpha clip now generate correct depth and shadow passes.
- `Normal Create` node has been renamed to `Normal From Texture`.

12
com.unity.shadergraph/Editor/Data/Util/ShaderGenerator.cs


if (combinedRequirements.requiresNormal > 0 || combinedRequirements.requiresBitangent > 0)
{
var name = preferredCoordinateSpace.ToVariableName(InterpolatorType.Normal);
vertexShader.AppendLine("float3 {0} = {1};", name, ConvertBetweenSpace("v.normal", CoordinateSpace.Object, preferredCoordinateSpace, InputType.Normal));
vertexShader.AppendLine("float3 {0} = normalize({1});", name, ConvertBetweenSpace("v.normal", CoordinateSpace.Object, preferredCoordinateSpace, InputType.Normal));
pixelShader.AppendLine("float3 {0} = normalize(IN.{0});", name);
pixelShader.AppendLine("float3 {0} = IN.{0};", name);
interpolatorIndex++;
}
}

if (combinedRequirements.requiresTangent > 0 || combinedRequirements.requiresBitangent > 0)
{
var name = preferredCoordinateSpace.ToVariableName(InterpolatorType.Tangent);
vertexShader.AppendLine("float3 {0} = {1};", name, ConvertBetweenSpace("v.tangent.xyz", CoordinateSpace.Object, preferredCoordinateSpace, InputType.Vector));
vertexShader.AppendLine("float3 {0} = normalize({1});", name, ConvertBetweenSpace("v.tangent.xyz", CoordinateSpace.Object, preferredCoordinateSpace, InputType.Vector));
if (graphModelRequirements.requiresTangent > 0 || graphModelRequirements.requiresBitangent > 0)
{
vertexOutputStruct.AppendLine("float3 {0} : TEXCOORD{1};", name, interpolatorIndex);

if (combinedRequirements.requiresBitangent > 0)
{
var name = preferredCoordinateSpace.ToVariableName(InterpolatorType.BiTangent);
vertexShader.AppendLine("float3 {0} = normalize(cross({1}, {2}.xyz) * {3});",
vertexShader.AppendLine("float3 {0} = cross({1}, {2}.xyz) * {3};",
name,
preferredCoordinateSpace.ToVariableName(InterpolatorType.Normal),
preferredCoordinateSpace.ToVariableName(InterpolatorType.Tangent),

if (combinedRequirements.requiresViewDir > 0)
{
var name = preferredCoordinateSpace.ToVariableName(InterpolatorType.ViewDirection);
const string worldSpaceViewDir = "SafeNormalize(_WorldSpaceCameraPos.xyz - mul(GetObjectToWorldMatrix(), float4(v.vertex.xyz, 1.0)).xyz)";
const string worldSpaceViewDir = "_WorldSpaceCameraPos.xyz - mul(GetObjectToWorldMatrix(), float4(v.vertex.xyz, 1.0)).xyz";
var preferredSpaceViewDir = ConvertBetweenSpace(worldSpaceViewDir, CoordinateSpace.World, preferredCoordinateSpace, InputType.Vector);
vertexShader.AppendLine("float3 {0} = {1};", name, preferredSpaceViewDir);
if (graphModelRequirements.requiresViewDir > 0)

pixelShader.AppendLine("float3 {0} = normalize(IN.{0});", name);
pixelShader.AppendLine("float3 {0} = IN.{0};", name);
interpolatorIndex++;
}
}

2
com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs


namespace UnityEditor.ShaderGraph
{
[ScriptedImporter(16, ShaderGraphExtension)]
[ScriptedImporter(17, ShaderGraphExtension)]
public class ShaderGraphImporter : ScriptedImporter
{
public const string ShaderGraphExtension = "shadergraph";

正在加载...
取消
保存