浏览代码

HDRenderLoop: Add few function to the shader library related to far cry 4 talk

/main
Sebastien Lagarde 8 年前
当前提交
00d2aece
共有 5 个文件被更改,包括 115 次插入4 次删除
  1. 4
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl
  2. 11
      Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl
  3. 25
      Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl
  4. 51
      Assets/ScriptableRenderLoop/ShaderLibrary/Packing.hlsl
  5. 28
      Assets/ScriptableRenderLoop/ShaderLibrary/QuaternionMath.hlsl

4
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl


{
// For odd-negative scale transforms we need to flip the sign
float sign = tangentSign * GetOdddNegativeScale();
float3 binormal = cross(normal, tangent) * sign;
float3 bitangent = cross(normal, tangent) * sign;
return float3x3(tangent, binormal, normal);
return float3x3(tangent, bitangent, normal);
}
// Computes world space view direction, from object space position

11
Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl


// roughnessT -> roughness in tangent direction
// roughnessB -> roughness in bitangent direction
float D_GGX_Aniso(float NdotH, float TdotH, float BdotH, float roughnessT, float roughnessB)
float D_GGXAniso(float NdotH, float TdotH, float BdotH, float roughnessT, float roughnessB)
{
// TODO: Do the clamp on the artists parameter
float f = TdotH * TdotH / (roughnessT * roughnessT) + BdotH * BdotH / (roughnessB * roughnessB) + NdotH * NdotH;

#endif
}
// TODO: V_ term for aniso GGX from farcry
// Ref: https://cedec.cesa.or.jp/2015/session/ENG/14698.html The Rendering Materials of Far Cry 4
// TODO: Check with Eric Heitz
float V_SmithJointGGXAniso(float NdotL, float NdotV, float roughnessT, float roughnessB)
{
// TODO
return 1.0;
}
//-----------------------------------------------------------------------------
// Diffuse BRDF - diffuseColor is expected to be multiply by the caller

25
Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl


return RGBMRANGE * rgbm.rgb * rgbm.a;
}
// Ref: http://www.nvidia.com/object/real-time-ycocg-dxt-compression.html
#define CHROMA_BIAS (0.5 * 256.0 / 255.0)
float3 RGBToYCoCg(float3 rgb)
{
float3 YCoCg;
YCoCg.x = dot(RGB, float3(0.25, 0.5, 0.25));
YCoCg.y = dot(RGB, float3(0.5, 0.0, -0.5)) + CHROMA_BIAS;
YCoCg.z = dot(RGB, float3(-0.25, 0.5, -0.25)) + CHROMA_BIAS;
return YCoCg;
}
float3 YCoCgToRGB(float3 YCoCg)
{
float Y = YCoCg.x;
float Co = YCoCg.y - CHROMA_BIAS;
float Cg = YCoCg.z - CHROMA_BIAS;
float3 rgb;
rgb.r = Y + Co - Cg;
rgb.g = Y + Cg;
rgb.b = Y - Co - Cg;
return rgb;
}
#endif // UNITY_COLOR_INCLUDED

51
Assets/ScriptableRenderLoop/ShaderLibrary/Packing.hlsl


}
//-----------------------------------------------------------------------------
// Quaternion packing
//-----------------------------------------------------------------------------
// Ref: https://cedec.cesa.or.jp/2015/session/ENG/14698.html The Rendering Materials of Far Cry 4
/*
// This is GCN intrinsic
uint FindBiggestComponent(float4 q)
{
uint xyzIndex = CubeMapFaceID(q.x, q.y, q.z) * 0.5f;
uint wIndex = 3;
bool wBiggest = abs(q.w) > max3(abs(q.x), qbs(q.y), qbs(q.z));
return wBiggest ? wIndex : xyzIndex;
}
// Pack a quaternion into a 10:10:10:2
float4 PackQuat(float4 quat)
{
uint index = FindBiggestComponent(quat);
if (index == 0) quat = quat.yzwx;
if (index == 1) quat = quat.xzwy;
if (index == 2) quat = quat.xywz;
float4 packedQuat;
packedQuat.xyz = quat.xyz * sign(quat.w) * sqrt(0.5) + 0.5;
packedQuat.w = index / 3.0;
return packedQuat;
}
*/
// Unpack a quaternion from a 10:10:10:2
float4 UnpackQuat(float4 packedQuat)
{
uint index = (uint)(packedQuat.w * 3.0);
float4 quat;
quat.xyz = packedQuat.xyz * sqrt(2.0) - (1.0 / sqrt(2.0));
quat.w = sqrt(1.0 - saturate(dot(quat.xyz, quat.xyz)));
if (index == 0) quat = quat.wxyz;
if (index == 1) quat = quat.xwyz;
if (index == 2) quat = quat.xywz;
return quat;
}
//-----------------------------------------------------------------------------
// Byte packing
//-----------------------------------------------------------------------------

28
Assets/ScriptableRenderLoop/ShaderLibrary/QuaternionMath.hlsl


#include "Common.hlsl"
// Ref: https://cedec.cesa.or.jp/2015/session/ENG/14698.html The Rendering Materials of Far Cry 4
float4 TangentSpaceToQuat(float3 tagent, float3 bitangent, float3 normal)
{
float4 quat;
quat.x = normal.y - bitangent.z;
quat.y = tangent.z - normal.x;
quat.z = bitangent.x - tangent.y;
quat.w = 1.0 + tangent.x + bitangent.y + normal.z;
return normalize(quat);
}
void QuatToTangentSpace(float4 quaterion, out float3 tangent, out float3 bitangent, out float3 normal)
{
tangent = float3(1.0, 0.0, 0.0)
+ float3(-2.0, 2.0, 2.0) * quat.y * quat.yxw
+ float3(-2.0, -2.0, 2.0) * quat.z * quaternion.zwx;
bitangent = float3(0.0, 1.0, 0.0)
+ float3(2.0, -2.0, 2.0) * quat.z * quat.wzy
+ float3(2.0, -2.0, -2.0) * quat.x * quaternion.yxw;
normal = float3(0.0, 0.0, 1.0)
+ float3(2.0, 2.0, -2.0) * quat.x * quat.zwx
+ float3(-2.0, 2.0, -2.0) * quat.y * quaternion.wzy;
}
#endif // UNITY_QUATERNIONMATH_INCLUDED
正在加载...
取消
保存