浏览代码

Update GBuffer parameters

- Update GBuffer parameters to be closer to what is describe on
confluence
- Add arbitrary packing function of float and int into a float with a
given precision
- Clean few stuff
- Current scene is 2 spot, 1 point and a directional and match betwee,
diffuse and forward.
/main
Sebastien Lagarde 8 年前
当前提交
4867b779
共有 5 个文件被更改,包括 89 次插入24 次删除
  1. 3
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  2. 1
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader
  3. 10
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/CommonMaterial.hlsl
  4. 15
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl
  5. 84
      Assets/ScriptableRenderLoop/ShaderLibrary/Packing.hlsl

3
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


InitAndClearBuffer(camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
// RenderForward(cullResults, camera, renderLoop);
FinalPass(renderLoop);

1
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader


// They are use to fill a SurfaceData. With a MaterialGraph these parameters will not be write here (?).
Properties
{
// Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear
_DiffuseColor("Diffuse", Color) = (1,1,1,1)
_DiffuseMap("Diffuse", 2D) = "white" {}

10
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/CommonMaterial.hlsl


return sqrt(roughness);
}
// Smoothness is the user facing name
// it should be perceptualSmoothness but we don't want the user to have to deal with this name
float SmoothnessToRoughness(float smoothness)
float PerceptualSmoothnessToRoughness(float perceptualSmoothness)
return (1 - smoothness) * (1 - smoothness);
return (1 - perceptualSmoothness) * (1 - perceptualSmoothness);
float SmoothnessToPerceptualRoughness(float smoothness)
float PerceptualSmoothnessToPerceptualRoughness(float perceptualSmoothness)
return (1 - smoothness);
return (1 - perceptualSmoothness);
}
#endif // UNITY_COMMON_MATERIAL_INCLUDED

15
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl


// GENERATED BY SHADER GRAPH
// Question for shader graph: how to handle dynamic parameter data like matData0 that can change name
// No guard header!
#define UNITY_MATERIAL_DISNEYGXX // Need to be define before including Material.hlsl

SurfaceData data;
data.diffuseColor = tex2D(_DiffuseMap, input.texCoord0) * _DiffuseColor;
data.occlusion = 1.0;
data.matData0 = 0.0;
data.SpecularOcclusion = 1.0;
data.ambientOcclusion = 1.0;
data.smoothness = _Smoothness;
data.perceptualSmoothness = _Smoothness;
data.normal = TransformTangentToWorld(normalTS, input.tangentToWorld);
data.normalWS = TransformTangentToWorld(normalTS, input.tangentToWorld);
data.materialId = 0;
data.baked = float3(0.0, 0.0, 0.0);
data.diffuseLighting = float3(0.0, 0.0, 0.0);
data.emissiveColor = float3(0.0, 0.0, 0.0);
data.emissiveIntensity = 0.0;

84
Assets/ScriptableRenderLoop/ShaderLibrary/Packing.hlsl


// Ref: http://jcgt.org/published/0003/02/01/paper.pdf
// Encode with Oct, this function work with any size of output
// return float between [-1, 1]
float2 PackNormalOctEncode(float3 v)
float2 PackNormalOctEncode(float3 n)
float l1norm = abs(v.x) + abs(v.y) + abs(v.z);
float2 res0 = v.xy * (1.0f / l1norm);
float l1norm = abs(n.x) + abs(n.y) + abs(n.z);
float2 res0 = n.xy * (1.0 / l1norm);
float2 val = 1.0f - abs(res0.yx);
return (v.zz < float2(0.0f, 0.0f) ? (res0 >= 0.0f ? val : -val) : res0);
float2 val = 1.0 - abs(res0.yx);
return (n.zz < float2(0.0, 0.0) ? (res0 >= 0.0 ? val : -val) : res0);
float3 UnpackNormalOctEncode(float x, float y)
float3 UnpackNormalOctEncode(float2 f)
float3 v = float3(x, y, 1.0f - abs(x) - abs(y));
float3 n = float3(f.x, f.y, 1.0 - abs(f.x) - abs(f.y));
float2 val = 1.0f - abs(v.yx);
v.xy = (v.zz < float2(0.0f, 0.0f) ? (v.xy >= 0.0f ? val : -val) : v.xy);
float2 val = 1.0 - abs(n.yx);
return normalize(v);
return normalize(n);
normal.xy = packednormal.wy * 2 - 1;
normal.xy = packednormal.wy * 2.0 - 1.0;
normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
return normal;
}

return result * (1.0 / float2(255.0, 255.0));
}
//-----------------------------------------------------------------------------
// Encode a float in [0..1] and an int in [0..maxi - 1] as a float [0..1] to be store in log2(precision) bit
// maxi must be a power of two and define the number of bit dedicated 0..1 to the int part (log2(maxi))
// Example: precision is 256.0, maxi is 2, i is [0..1] encode on 1 bit. f is [0..1] encode on 7 bit.
// Example: precision is 256.0, maxi is 4, i is [0..3] encode on 2 bit. f is [0..1] encode on 6 bit.
// Example: precision is 256.0, maxi is 8, i is [0..7] encode on 3 bit. f is [0..1] encode on 5 bit.
// ...
// Example: precision is 1024.0, maxi is 8, i is [0..7] encode on 3 bit. f is [0..1] encode on 7 bit.
//...
float PackFloatInt(float f, int i, float maxi, float precision)
{
// Constant
float precisionMinusOne = precision - 1.0;
float t1 = ((precision / maxi) - 1.0) / precisionMinusOne;
float t2 = (precision / maxi) / precisionMinusOne;
return t1 * f + t2 * float(i);
}
void UnpackFloatInt(float val, float maxi, float precision, out float f, out int i)
{
// Constant
float precisionMinusOne = precision - 1.0;
float t1 = ((precision / maxi) - 1.0) / precisionMinusOne;
float t2 = (precision / maxi) / precisionMinusOne;
// extract integer part
i = int(val / t2);
// Now that we have i, solve formula in PackFloatInt for f
//f = (val - t2 * float(i)) / t1 => convert in mads form
f = (-t2 * float(i) + val) / t1;
}
// Define various variante for ease of read
float PackFloatInt8bit(float f, int i, float maxi)
{
return PackFloatInt(f, i, maxi, 255.0);
}
float UnpackFloatInt8bit(float val, float maxi, out float f, out int i)
{
UnpackFloatInt(val, maxi, 255.0, f, i);
}
float PackFloatInt10bit(float f, int i, float maxi)
{
return PackFloatInt(f, i, maxi, 1024.0);
}
float UnpackFloatInt10bit(float val, float maxi, out float f, out int i)
{
UnpackFloatInt(val, maxi, 1024.0, f, i);
}
float PackFloatInt16bit(float f, int i, float maxi)
{
return PackFloatInt(f, i, maxi, 65536.0);
}
float UnpackFloatInt16bit(float val, float maxi, out float f, out int i)
{
UnpackFloatInt(val, maxi, 65536.0, f, i);
}
#endif // UNITY_PACKING_INCLUDED
正在加载...
取消
保存