浏览代码

- Plug tangent, bitangent & vertexColor for MaterialGraph Integration

- Add Createbitangent independant function sur ShaderVariables
/scriptablerenderloop-materialgraph
Paul Demeulenaere 8 年前
当前提交
bd465a6d
共有 2 个文件被更改,包括 53 次插入5 次删除
  1. 48
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  2. 10
      Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl

48
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


{
public string attributeName;
public string semantic;
public SlotValueType semanticType;
public string vayringName;
public SlotValueType type;
public string vertexCode;

}
}
if (needFragInputRegex.IsMatch("normalWS") || activeNodeList.OfType<IMayRequireNormal>().Any(x => x.RequiresNormal()))
bool needBitangent = needFragInputRegex.IsMatch("bitangentWS");
if (needBitangent || needFragInputRegex.IsMatch("tangentWS"))
{
vayrings.Add(new Vayring()
{
attributeName = "tangentOS",
semantic = "TANGENT",
semanticType = SlotValueType.Vector4,
vayringName = "tangentWS",
type = SlotValueType.Vector3,
vertexCode = "output.tangentWS = TransformObjectToWorldDir(input.tangentOS.xyz);",
fragInputTarget = "tangentToWorld[0]",
pixelCode = string.Format("float3 {0} = normalize(fragInput.tangentToWorld[0]);", "worldSpaceTangent")
});
}
if (needBitangent || needFragInputRegex.IsMatch("normalWS") || activeNodeList.OfType<IMayRequireNormal>().Any(x => x.RequiresNormal()))
{
vayrings.Add(new Vayring()
{

});
}
if (needBitangent)
{
vayrings.Add(new Vayring()
{
vayringName = "bitangentWS",
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]);", "worldSpaceBitangent")
});
}
bool requireViewDirection = needFragInputRegex.IsMatch("viewDirectionWS") || activeNodeList.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection());
if (requireViewDirection || needFragInputRegex.IsMatch("positionWS") || activeNodeList.OfType<IMayRequireWorldPosition>().Any(x => x.RequiresWorldPosition()))
{

vayrings.Add(new Vayring()
{
pixelCode = string.Format("float3 {0} = GetWorldSpaceNormalizeViewDir(fragInput.positionWS);", ShaderGeneratorNames.WorldSpaceViewDirection)
});
}
if (needFragInputRegex.IsMatch("vertexColor"))
{
vayrings.Add(new Vayring()
{
attributeName = "vertexColor",
semantic = "COLOR",
vayringName = "vertexColor",
type = SlotValueType.Vector4,
vertexCode = "output.vertexColor = input.vertexColor;",
pixelCode = string.Format("float4 {0} = fragInput.vertexColor;", "vertexColor")
});
}

var typeSize = _fnTypeToSize(vayring.type);
if (!string.IsNullOrEmpty(vayring.attributeName))
{
vertexAttributeVisitor.AddShaderChunk(string.Format("float{0} {1} : {2};", typeSize, vayring.attributeName, vayring.semantic), true);
var semanticType = vayring.semanticType != SlotValueType.Dynamic ? vayring.semanticType : vayring.type;
var semanticSize = _fnTypeToSize(semanticType);
vertexAttributeVisitor.AddShaderChunk(string.Format("float{0} {1} : {2};", semanticSize, vayring.attributeName, vayring.semantic), true);
}
vayringVisitor.AddShaderChunk(string.Format("float{0} {1};", typeSize, vayring.vayringName), false);

10
Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl


return mul(GetWorldToHClipMatrix(), float4(positionWS, 1.0));
}
float3x3 CreateTangentToWorld(float3 normal, float3 tangent, float tangentSign)
float3 CreateBitangent(float3 normal, float3 tangent, float tangentSign)
// For odd-negative scale transforms we need to flip the sign
// For odd-negative scale transforms we need to flip the sign
float3 bitangent = cross(normal, tangent) * sign;
return cross(normal, tangent) * sign;
}
float3x3 CreateTangentToWorld(float3 normal, float3 tangent, float tangentSign)
{
float3 bitangent = CreateBitangent(normal, tangent, tangentSign);
return float3x3(tangent, bitangent, normal);
}

正在加载...
取消
保存