浏览代码

HDRenderPipeline: Move calculation of CreateTangentToWorld to pixel shader

/Branch_Batching2
Sebastien Lagarde 8 年前
当前提交
cc2fcd8e
共有 5 个文件被更改,包括 49 次插入66 次删除
  1. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
  2. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
  3. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/FragInputs.hlsl
  4. 90
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl
  5. 19
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/VertMesh.hlsl

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl


surfaceData.metallic = SURFACEDATA_BLEND_SCALAR(surfaceData, metallic, weights);
// Init other unused parameter
surfaceData.tangentWS = normalize(input.tangentToWorld[0].xyz);
surfaceData.tangentWS = input.tangentToWorld[0].xyz;
surfaceData.materialId = 0;
surfaceData.anisotropy = 0;
surfaceData.specular = 0.04;

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl


surfaceData.tangentWS = TransformObjectToWorldDir(tangentOS);
#endif
#else
surfaceData.tangentWS = normalize(input.tangentToWorld[0].xyz);
surfaceData.tangentWS = input.tangentToWorld[0].xyz;
#endif
// TODO: Is there anything todo regarding flip normal but for the tangent ?

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/FragInputs.hlsl


float2 texCoord1;
float2 texCoord2;
float2 texCoord3;
float3 tangentToWorld[3];
float3 tangentToWorld[3]; // These 3 vectors are normalized (no need for the material to normalize)
float4 color; // vertex color
// For two sided lighting

90
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl


float3 positionWS;
#endif
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD
float3 tangentToWorld[3];
float3 normalWS;
float4 tangentWS; // w contain mirror sign
#endif
#ifdef VARYINGS_NEED_TEXCOORD0
float2 texCoord0;

{
float4 positionCS : SV_Position;
#ifdef VARYINGS_NEED_POSITION_WS
float3 interpolators0 : TEXCOORD0;
#endif
#ifdef VARYINGS_NEED_POSITION_WS
// if present, pack positionWS
float4 interpolators1 : TEXCOORD1;
float4 interpolators2 : TEXCOORD2;
float4 interpolators3 : TEXCOORD3;
#else
float3 interpolators2 : TEXCOORD2;
float3 interpolators3 : TEXCOORD3;
#endif
#else
#ifdef VARYINGS_NEED_POSITION_WS
float3 interpolators0 : TEXCOORD0;
#endif
float4 interpolators2 : TEXCOORD2;
float4 interpolators4 : TEXCOORD4;
float4 interpolators3 : TEXCOORD3;
float2 interpolators4 : TEXCOORD4;
float2 interpolators3 : TEXCOORD3;
float4 interpolators5 : TEXCOORD5;
float4 interpolators4 : TEXCOORD4;
float2 interpolators5 : TEXCOORD5;
float2 interpolators4 : TEXCOORD4;
float4 interpolators6 : TEXCOORD6;
float4 interpolators5 : TEXCOORD5;
#endif
#if defined(VARYINGS_NEED_CULLFACE) && SHADER_STAGE_FRAGMENT

output.positionCS = input.positionCS;
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD
output.interpolators1.xyz = input.tangentToWorld[0];
output.interpolators2.xyz = input.tangentToWorld[1];
output.interpolators3.xyz = input.tangentToWorld[2];
#ifdef VARYINGS_NEED_POSITION_WS
output.interpolators1.w = input.positionWS.x;
output.interpolators2.w = input.positionWS.y;
output.interpolators3.w = input.positionWS.z;
#endif
#else
#ifdef VARYINGS_NEED_POSITION_WS
#ifdef VARYINGS_NEED_POSITION_WS
#endif
#endif
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD
output.interpolators1 = input.normalWS;
output.interpolators2 = input.tangentWS;
output.interpolators4.xy = input.texCoord0;
output.interpolators3.xy = input.texCoord0;
output.interpolators4.zw = input.texCoord1;
output.interpolators3.zw = input.texCoord1;
output.interpolators5.xy = input.texCoord2;
output.interpolators4.xy = input.texCoord2;
output.interpolators5.zw = input.texCoord3;
output.interpolators4.zw = input.texCoord3;
output.interpolators6 = input.color;
output.interpolators5 = input.color;
#endif
return output;

output.unPositionSS = input.positionCS; // input.positionCS is SV_Position
#ifdef VARYINGS_NEED_POSITION_WS
output.positionWS.xyz = input.interpolators0.xyz;
#endif
output.tangentToWorld[0] = input.interpolators1.xyz;
output.tangentToWorld[1] = input.interpolators2.xyz;
output.tangentToWorld[2] = input.interpolators3.xyz;
#ifdef VARYINGS_NEED_POSITION_WS
output.positionWS.xyz = float3(input.interpolators1.w, input.interpolators2.w, input.interpolators3.w);
#endif
#else
#ifdef VARYINGS_NEED_POSITION_WS
output.positionWS.xyz = input.interpolators0.xyz;
#endif
// Normalize the normal/tangent after interpolation
float3 normalWS = normalize(input.interpolators1);
float4 tangentWS = float4(normalize(input.interpolators2.xyz), input.interpolators2.w);
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w);
output.tangentToWorld[0] = tangentToWorld[0];
output.tangentToWorld[1] = tangentToWorld[1];
output.tangentToWorld[2] = tangentToWorld[2];
output.texCoord0 = input.interpolators4.xy;
output.texCoord0 = input.interpolators3.xy;
output.texCoord1 = input.interpolators4.zw;
output.texCoord1 = input.interpolators3.zw;
output.texCoord2 = input.interpolators5.xy;
output.texCoord2 = input.interpolators4.xy;
output.texCoord3 = input.interpolators5.zw;
output.texCoord3 = input.interpolators4.zw;
output.color = input.interpolators6;
output.color = input.interpolators5;
#endif
#if defined(VARYINGS_NEED_CULLFACE) && SHADER_STAGE_FRAGMENT

19
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/VertMesh.hlsl


#endif
output.positionCS = TransformWorldToHClip(positionWS);
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w);
output.tangentToWorld[0] = tangentToWorld[0];
output.tangentToWorld[1] = tangentToWorld[1];
output.tangentToWorld[2] = tangentToWorld[2];
output.normalWS = TransformObjectToWorldNormal(input.normalOS);
output.tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
#endif
#endif

{
VaryingsMeshToPS output;
output.positionCS = TransformWorldToHClip(input.positionWS);
output.positionCS = TransformWorldToHClip(input.positionWS);
float3x3 tangentToWorld = CreateTangentToWorld(input.normalWS, input.tangentWS.xyz, input.tangentWS.w);
output.tangentToWorld[0] = tangentToWorld[0];
output.tangentToWorld[1] = tangentToWorld[1];
output.tangentToWorld[2] = tangentToWorld[2];
output.normalWS = input.normalWS;
output.tangentWS = input.tangentWS;
#endif
#ifdef VARYINGS_NEED_TEXCOORD0

正在加载...
取消
保存