浏览代码

HDRenderLoop: Add builtin data structure + add velocity buffer

- Add velocity buffer as an experiment for the design
- Split surface data into surface data and builtin data (engine side for
lightmap etc...)
/main
sebastienlagarde 8 年前
当前提交
36c50926
共有 18 个文件被更改,包括 516 次插入172 次删除
  1. 40
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader
  2. 7
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.shader
  3. 3
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingForward.hlsl
  4. 114
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/DisneyGGX.hlsl
  5. 151
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl
  6. 108
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl
  7. 2
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
  8. 89
      Assets/TestScenes/HDTest/HDRenderLoopTest.unity
  9. 28
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test.mat
  10. 11
      Assets/TestScenes/HDTest/Rock/rcgRock012/Materials/rcgRock012Material.mat
  11. 32
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.hlsl
  12. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.hlsl.meta
  13. 30
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit.hlsl
  14. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit.hlsl.meta
  15. 7
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderConfig.cs
  16. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderConfig.cs.meta
  17. 28
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/CommonMaterial.hlsl
  18. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/CommonMaterial.hlsl.meta

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


// Following options are for the GUI inspector and different from the input parameters above
// These option below will cause different compilation flag.
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0
[ToggleOff] _DistortionDepthTest("Distortion Only", Float) = 0.0
[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5

[Enum(Mask Alpha, 0, BaseColor Alpha, 1)] _SmoothnessTextureChannel("Smoothness texture channel", Float) = 1
[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1
[Enum(None, 0, DoubleSided, 1, DoubleSidedLigthingFlip, 2, DoubleSidedLigthingMirror, 3)] _DoubleSidedMode("Double sided mode", Float) = 1
[Enum(None, 0, DoubleSided, 1, DoubleSidedLigthingFlip, 2, DoubleSidedLigthingMirror, 3)] _DoubleSidedMode("Double sided mode", Float) = 0
}
HLSLINCLUDE

#pragma vertex VertDefault
#pragma fragment FragForward
#include "TemplateDisneyGGX.hlsl"
#include "TemplateDisneyGGX.hlsl"
#if SHADER_STAGE_FRAGMENT
float4 FragForward(PackedVaryings packedInput) : SV_Target
{

SurfaceData surfaceData = GetSurfaceData(input);
SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, surfaceData, builtinData);
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);

return float4(diffuseLighting.rgb + specularLighting.rgb, surfaceData.opacity);
diffuseLighting.rgb += GetBakedDiffuseLigthing(surfaceData, builtinData);
return float4(diffuseLighting.rgb + specularLighting.rgb, builtinData.opacity);
#endif
ENDHLSL
}

Name "GBuffer" // Name is not used
Tags { "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index
Cull [_CullMode]
Cull [_CullMode]
HLSLPROGRAM
#pragma target 5.0

#pragma fragment FragDeferred
#include "TemplateDisneyGGX.hlsl"
#if SHADER_STAGE_FRAGMENT
#ifdef VELOCITY_IN_GBUFFER
, OUTPUT_GBUFFER_VELOCITY(outGBuffer)
#endif
, OUTPUT_GBUFFER_BAKE_LIGHTING(outGBuffer)
SurfaceData surfaceData = GetSurfaceData(input);
SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, surfaceData, builtinData);
#ifdef VELOCITY_IN_GBUFFER
ENCODE_VELOCITY_INTO_GBUFFER(builtinData.velocity, outGBuffer);
#endif
ENCODE_BAKE_LIGHTING_INTO_GBUFFER(GetBakedDiffuseLigthing(surfaceData, builtinData), outGBuffer);
#endif
ENDHLSL
}

7
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.shader


#pragma fragment FragDeferred
// CAUTION: In case deferred lighting need to support various lighting model statically, we will require to do multicompile with different define like UNITY_MATERIAL_DISNEYGXX
#define UNITY_MATERIAL_DISNEYGXX // Need to be define before including Material.hlsl
#define UNITY_MATERIAL_DISNEYGGX // Need to be define before including Material.hlsl
DECLARE_GBUFFER_BAKE_LIGHTING(_CameraGBufferTexture);
Texture2D _CameraDepthTexture;
float4 _ScreenSize;

float4 diffuseLighting;
float4 specularLighting;
ForwardLighting(V, positionWS, bsdfData, diffuseLighting, specularLighting);
FETCH_BAKE_LIGHTING_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS);
diffuseLighting.rgb += DECODE_BAKE_LIGHTING_FROM_GBUFFER(gbuffer);
return float4(diffuseLighting.rgb + specularLighting.rgb, 1.0);
}

3
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingForward.hlsl


specularLighting += localSpecularLighting;
}
*/
// Add GI
diffuseLighting.rgb += bsdfData.diffuseLightingAndEmissive;
}
#endif // UNITY_LIGHTING_FORWARD_INCLUDED

114
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/DisneyGGX.hlsl


// Main structure that store the user data (i.e user input of master node in material graph)
struct SurfaceData
{
// TODO: define what is the best parametrization for artsits, seems that metal smoothness is the winner, but would like at add back a specular parameter.
// Bonus, if we store as specular color we can define a liner specular 0..1 mapping 2% to 20%
float3 specularColor; // Should be YCbCr but need to validate that it is fine first! MEan have reflection probe
float3 specularColor;
float specularOcclusion;
float3 normalWS;

// TODO: create a system surfaceData for thing like that + Transparent
// As we collect some lighting information (Lightmap, lightprobe/proxy volume)
// and emissive ahead (i.e in Gbuffer pass when doing deferred), we need to
// to have them in the SurfaceData structure.
float3 diffuseLighting;
float3 emissiveColor; // Linear space
float emissiveIntensity;
// MaterialID SSS - When enable, we only need one channel for specColor, so one is free to store information.
float subSurfaceRadius;
// float thickness;

// float coatCoverage;
// float coatRoughness;
// Distortion
// float2 distortionVector;
// float distortionBlur; // Define the mipmap level to use
// float2 velocityVector;
float opacity; // Not store, use for blending
// float coatRoughness;
};
struct BSDFData

float3 fresnel0; // Should be YCbCr but need to validate that it is fine first! MEan have reflection probe
float3 fresnel0;
float specularOcclusion;
//float matData1;

float roughness;
// System
float3 diffuseLightingAndEmissive;
// conversion function for forward and deferred
// conversion function for forward
BSDFData ConvertSurfaceDataToBSDFData(SurfaceData data)
BSDFData ConvertSurfaceDataToBSDFData(SurfaceData input)
output.diffuseColor = data.diffuseColor;
output.matData0 = data.subSurfaceRadius; // TEMP
output.diffuseColor = input.diffuseColor;
output.matData0 = input.subSurfaceRadius; // TEMP
output.fresnel0 = data.specularColor;
output.specularOcclusion = data.specularOcclusion;
//output.matData1 = data.matData1;
output.fresnel0 = input.specularColor;
output.specularOcclusion = input.specularOcclusion;
//output.matData1 = input.matData1;
output.normalWS = data.normalWS;
output.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(data.perceptualSmoothness);
output.materialId = data.materialId;
output.normalWS = input.normalWS;
output.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(input.perceptualSmoothness);
output.materialId = input.materialId;
output.diffuseLightingAndEmissive = data.diffuseLighting * data.ambientOcclusion * data.diffuseColor + data.emissiveColor * data.emissiveIntensity;
// Packing function specific to this surfaceData
//-----------------------------------------------------------------------------
// Packing helper functions specific to this surfaceData
//-----------------------------------------------------------------------------
float PackMaterialId(int materialId)
{
return float(materialId) / 3.0;

return int(round(f * 3.0));
}
#define GBUFFER_COUNT 4
//-----------------------------------------------------------------------------
// bake lighting function
//-----------------------------------------------------------------------------
// This will encode UnityStandardData into GBuffer
void EncodeIntoGBuffer(SurfaceData data, out float4 outGBuffer0, out float4 outGBuffer1, out float4 outGBuffer2, out float4 outGBuffer3)
float3 GetBakedDiffuseLigthing(SurfaceData surfaceData, BuiltinData builtinData)
{
return builtinData.bakeDiffuseLighting * surfaceData.ambientOcclusion * surfaceData.diffuseColor + builtinData.emissiveColor * builtinData.emissiveIntensity;
}
//-----------------------------------------------------------------------------
// conversion function for deferred
//-----------------------------------------------------------------------------
#define GBUFFER_MATERIAL_COUNT 3
// Encode SurfaceData (BSDF parameters) into GBuffer
void EncodeIntoGBuffer( SurfaceData surfaceData,
out float4 outGBuffer0,
out float4 outGBuffer1,
out float4 outGBuffer2)
outGBuffer0 = float4(data.diffuseColor, data.subSurfaceRadius);
outGBuffer0 = float4(surfaceData.diffuseColor, surfaceData.subSurfaceRadius);
outGBuffer1 = float4(data.specularColor, data.specularOcclusion /*, data.matData1 */);
outGBuffer1 = float4(surfaceData.specularColor, surfaceData.specularOcclusion /*, surfaceData.matData1 */);
float2 octNormal = PackNormalOctEncode(data.normalWS);
float2 octNormal = PackNormalOctEncode(surfaceData.normalWS);
outGBuffer2 = float4(octNormal * 0.5 + 0.5, PerceptualSmoothnessToPerceptualRoughness(data.perceptualSmoothness), PackMaterialId(data.materialId));
// RT3 - 11:11:10 float
outGBuffer3 = float4(data.diffuseLighting * data.ambientOcclusion * data.diffuseColor + data.emissiveColor * data.emissiveIntensity, 0.0f);
outGBuffer2 = float4(octNormal * 0.5 + 0.5, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness), PackMaterialId(surfaceData.materialId));
// This decode the Gbuffer in a BSDFData struct
BSDFData DecodeFromGBuffer(float4 inGBuffer0, float4 inGBuffer1, float4 inGBuffer2, float4 inGBuffer3)
BSDFData DecodeFromGBuffer( float4 inGBuffer0,
float4 inGBuffer1,
float4 inGBuffer2)
{
BSDFData bsdfData;
bsdfData.diffuseColor = inGBuffer0.rgb;

bsdfData.roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness);
bsdfData.diffuseLightingAndEmissive = inGBuffer3.rgb;
return bsdfData;
}

void EvaluateBSDF_Punctual( float3 V, float3 positionWS, PunctualLightData light, BSDFData bsdfData,
void EvaluateBSDF_Punctual( float3 V, float3 positionWS, PunctualLightData lightData, BSDFData bsdfData,
out float4 diffuseLighting,
out float4 specularLighting)
{

// For point light and directional GetAngleAttenuation() return 1
float3 unL = light.positionWS - positionWS * light.useDistanceAttenuation;
float3 unL = lightData.positionWS - positionWS * lightData.useDistanceAttenuation;
float attenuation = GetDistanceAttenuation(unL, light.invSqrAttenuationRadius);
attenuation *= GetAngleAttenuation(L, light.forward, light.angleScale, light.angleOffset);
float attenuation = GetDistanceAttenuation(unL, lightData.invSqrAttenuationRadius);
attenuation *= GetAngleAttenuation(L, lightData.forward, lightData.angleScale, lightData.angleOffset);
float illuminance = saturate(dot(bsdfData.normalWS, L)) * attenuation;
diffuseLighting = float4(0.0, 0.0, 0.0, 1.0);

float Vis = V_SmithJointGGX(NdotL, NdotV, bsdfData.roughness);
float D = D_GGX(NdotH, bsdfData.roughness);
specularLighting.rgb = F * Vis * D;
float disneyDiffuse = DisneyDiffuse(NdotV, NdotL, LdotH, bsdfData.perceptualRoughness);
diffuseLighting.rgb = bsdfData.diffuseColor * disneyDiffuse;
#ifdef DIFFUSE_LAMBERT_BRDF
float diffuseTerm = Lambert();
#else
float diffuseTerm = DisneyDiffuse(NdotV, NdotL, LdotH, bsdfData.perceptualRoughness);
#endif
diffuseLighting.rgb = bsdfData.diffuseColor * diffuseTerm;
diffuseLighting.rgb *= light.color * illuminance;
specularLighting.rgb *= light.color * illuminance;
diffuseLighting.rgb *= lightData.color * illuminance;
specularLighting.rgb *= lightData.color * illuminance;
}
}

151
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl


#include "Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl"
#include "Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Shaderconfig.cs"
#include "CommonMaterial.hlsl"
//-----------------------------------------------------------------------------
// Parametrization function helpers
//-----------------------------------------------------------------------------
float PerceptualRoughnessToRoughness(float perceptualRoughness)
{
return perceptualRoughness * perceptualRoughness;
}
float RoughnessToPerceptualRoughness(float roughness)
{
return sqrt(roughness);
}
float PerceptualSmoothnessToRoughness(float perceptualSmoothness)
{
return (1 - perceptualSmoothness) * (1 - perceptualSmoothness);
}
float PerceptualSmoothnessToPerceptualRoughness(float perceptualSmoothness)
{
return (1 - perceptualSmoothness);
}
// Encode/Decode velocity in a buffer (either forward of deferred)
// Design note: We assume that VelocityVector fit into a single buffer (i.e not spread on several buffer)
void EncodeVelocity(float2 velocity, out float4 outBuffer)
{
// RT - 16:16 float
outBuffer = float4(velocity.xy, 0.0, 0.0);
}
float2 DecodeVelocity(float4 inBuffer)
{
return float2(inBuffer.xy);
}
// Encode/Decode into GBuffer - This is share so others material can use it.
// Design note: We assume that BakeDiffuseLighting and emissive fit into a single buffer (i.e not spread on several buffer)
void EncodeBakedDiffuseLigthingIntoGBuffer(float3 bakeDiffuseLighting, out float4 outBuffer)
{
// RT - 11:11:10f
outBuffer = float4(bakeDiffuseLighting.xyz, 0.0);
}
float3 DecodeBakedDiffuseLigthingFromGBuffer(float4 inBuffer)
{
return float3(inBuffer.xyz);
}
//-----------------------------------------------------------------------------
// BuiltinData
//-----------------------------------------------------------------------------
#include "BuiltinData.hlsl"
//-----------------------------------------------------------------------------
// SurfaceData
//-----------------------------------------------------------------------------
#ifdef UNITY_MATERIAL_DISNEYGXX
#ifdef UNITY_MATERIAL_DISNEYGGX
#elif defined(UNITY_MATERIAL_UNLIT)
#include "Unlit.hlsl"
#endif
//-----------------------------------------------------------------------------

#ifdef GBUFFER_COUNT
#if GBUFFER_COUNT == 3
#ifdef GBUFFER_MATERIAL_COUNT
#if GBUFFER_MATERIAL_COUNT == 3
#define OUTPUT_GBUFFER(NAME) \
out float4 MERGE_NAME(NAME, 0) : SV_Target0, \

#define ENCODE_INTO_GBUFFER(SURFACE_DATA, NAME) EncodeIntoGBuffer(SURFACE_DATA, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2))
#define DECODE_FROM_GBUFFER(NAME) DecodeFromGBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2))
#elif GBUFFER_COUNT == 4
#ifdef VELOCITY_IN_GBUFFER
#define GBUFFER_VELOCITY_NAME(NAME) MERGE_NAME(NAME, 3)
#define GBUFFER_VELOCITY_TARGET(TARGET) MERGE_NAME(TARGET, 3)
#define GBUFFER_BAKE_LIGHTING_NAME(NAME) MERGE_NAME(NAME, 4)
#define GBUFFER_BAKE_LIGHTING_TARGET(TARGET) MERGE_NAME(TARGET, 4)
#else
#define GBUFFER_BAKE_LIGHTING_NAME(NAME) MERGE_NAME(NAME, 3)
#define GBUFFER_BAKE_LIGHTING_TARGET(TARGET) MERGE_NAME(TARGET, 3)
#endif
#elif GBUFFER_MATERIAL_COUNT == 4
#define OUTPUT_GBUFFER(NAME) \
out float4 MERGE_NAME(NAME, 0) : SV_Target0, \

#define ENCODE_INTO_GBUFFER(SURFACE_DATA, NAME) EncodeIntoGBuffer(SURFACE_DATA, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3))
#define DECODE_FROM_GBUFFER(NAME) DecodeFromGBuffer(MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3))
#ifdef VELOCITY_IN_GBUFFER
#define GBUFFER_VELOCITY_NAME(NAME) MERGE_NAME(NAME, 4)
#define GBUFFER_VELOCITY_TARGET(TARGET) MERGE_NAME(TARGET, 4)
#define GBUFFER_BAKE_LIGHTING_NAME(NAME) MERGE_NAME(NAME, 5)
#define GBUFFER_BAKE_LIGHTING_TARGET(TARGET) MERGE_NAME(TARGET, 5)
#else
#define GBUFFER_BAKE_LIGHTING_NAME(NAME) MERGE_NAME(NAME, 4)
#define GBUFFER_BAKE_LIGHTING_TARGET(TARGET) MERGE_NAME(TARGET, 4)
#endif // #ifdef GBUFFER_COUNT
#elif GBUFFER_MATERIAL_COUNT == 5
#define OUTPUT_GBUFFER(NAME) \
out float4 MERGE_NAME(NAME, 0) : SV_Target0, \
out float4 MERGE_NAME(NAME, 1) : SV_Target1, \
out float4 MERGE_NAME(NAME, 2) : SV_Target2, \
out float4 MERGE_NAME(NAME, 3) : SV_Target3, \
out float4 MERGE_NAME(NAME, 4) : SV_Target4
#define DECLARE_GBUFFER_TEXTURE(NAME) \
Texture2D MERGE_NAME(NAME, 0); \
Texture2D MERGE_NAME(NAME, 1); \
Texture2D MERGE_NAME(NAME, 2); \
Texture2D MERGE_NAME(NAME, 3); \
Texture2D MERGE_NAME(NAME, 4);
#define FETCH_GBUFFER(NAME, TEX, UV) \
float4 MERGE_NAME(NAME, 0) = MERGE_NAME(TEX, 0).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 1) = MERGE_NAME(TEX, 1).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 2) = MERGE_NAME(TEX, 2).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 3) = MERGE_NAME(TEX, 3).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 4) = MERGE_NAME(TEX, 4).Load(uint3(UV, 0));
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, NAME) EncodeIntoGBuffer(SURFACE_DATA, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4))
#define DECODE_FROM_GBUFFER(NAME) DecodeFromGBuffer(MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4))
#ifdef VELOCITY_IN_GBUFFER
#define GBUFFER_VELOCITY_NAME(NAME) MERGE_NAME(NAME, 5)
#define GBUFFER_VELOCITY_TARGET(TARGET) MERGE_NAME(TARGET, 5)
#define GBUFFER_BAKE_LIGHTING_NAME(NAME) MERGE_NAME(NAME, 6)
#define GBUFFER_BAKE_LIGHTING_TARGET(TARGET) MERGE_NAME(TARGET, 6)
#else
#define GBUFFER_BAKE_LIGHTING_NAME(NAME) MERGE_NAME(NAME, 5)
#define GBUFFER_BAKE_LIGHTING_TARGET(TARGET) MERGE_NAME(TARGET, 5)
#endif
#endif // #if GBUFFER_MATERIAL_COUNT == 3
// Generic whatever the number of GBuffer
#ifdef VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) out float4 GBUFFER_VELOCITY_NAME(NAME) : GBUFFER_VELOCITY_TARGET(SV_Target)
#define DECLARE_GBUFFER_VELOCITY_TEXTURE(NAME) Texture2D GBUFFER_VELOCITY_NAME(NAME);
#define ENCODE_VELOCITY_INTO_GBUFFER(VELOCITY, NAME) EncodeVelocity(VELOCITY, GBUFFER_VELOCITY_NAME(NAME))
#endif
#define OUTPUT_GBUFFER_BAKE_LIGHTING(NAME) out float4 GBUFFER_BAKE_LIGHTING_NAME(NAME) : GBUFFER_BAKE_LIGHTING_TARGET(SV_Target)
#define DECLARE_GBUFFER_BAKE_LIGHTING(NAME) Texture2D GBUFFER_BAKE_LIGHTING_NAME(NAME);
#define ENCODE_BAKE_LIGHTING_INTO_GBUFFER(BAKE_DIFFUSE_LIGHTING, NAME) EncodeBakedDiffuseLigthingIntoGBuffer(BAKE_DIFFUSE_LIGHTING, GBUFFER_BAKE_LIGHTING_NAME(NAME))
#define FETCH_BAKE_LIGHTING_GBUFFER(NAME, TEX, UV) float4 GBUFFER_BAKE_LIGHTING_NAME(NAME) = GBUFFER_BAKE_LIGHTING_NAME(TEX).Load(uint3(UV, 0));
#define DECODE_BAKE_LIGHTING_FROM_GBUFFER(NAME) DecodeBakedDiffuseLigthingFromGBuffer(GBUFFER_BAKE_LIGHTING_NAME(NAME))
#endif // #ifdef GBUFFER_MATERIAL_COUNT
// Decode velocity need to be accessible in both forward and deferred
#ifdef VELOCITY_IN_GBUFFER
#define DECODE_VELOCITY_BUFFER(NAME) DecodeVelocity(GBUFFER_VELOCITY_NAME(NAME))
#else
#define DECODE_VELOCITY_BUFFER(NAME) DecodeVelocity(GBUFFER_VELOCITY_NAME(NAME))
#endif
#endif // UNITY_MATERIAL_INCLUDED

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


// No guard header!
#define UNITY_MATERIAL_DISNEYGXX // Need to be define before including Material.hlsl
#define UNITY_MATERIAL_DISNEYGGX // Need to be define before including Material.hlsl
#include "Lighting/Lighting.hlsl" // This include Material.hlsl
#include "ShaderVariables.hlsl"

float2 texCoord0;
float4 tangentToWorld[3]; // [3x3:tangentToWorld | 1x3:viewDirForParallax]
/*
*/
};
struct PackedVaryings

/*
*/
};
// Function to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions

output.tangentToWorld[1] = input.interpolators[2];
output.tangentToWorld[2] = input.interpolators[3];
/*
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
#ifdef SHADER_STAGE_FRAGMENT
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
#endif
*/
return output;
}

return PackVaryings(output);
}
//-------------------------------------------------------------------------------------
// Fill SurfaceData/Lighting data function
//-------------------------------------------------------------------------------------

return normalize(mul(normalTS, float3x3(tangentToWorld[0].xyz, tangentToWorld[1].xyz, tangentToWorld[2].xyz)));
}
SurfaceData GetSurfaceData(Varyings input)
#if SHADER_STAGE_FRAGMENT
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData)
// to manage the mettalic/specular representation we should have a neested master node instead of doing a new lighting model
// this is simulated here by doing the conversion on the inputs data.
SurfaceData data;
float3 baseColor = tex2D(_BaseColorMap, input.texCoord0).rgb * _BaseColor.rgb;
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
float alpha = _BaseColor.a;

clip(alpha - _Cutoff);
#endif
data.opacity = alpha;
builtinData.opacity = alpha;
data.ambientOcclusion = tex2D(_MaskMap, input.texCoord0).g;
surfaceData.ambientOcclusion = tex2D(_MaskMap, input.texCoord0).g;
data.ambientOcclusion = 1.0;
surfaceData.ambientOcclusion = 1.0;
data.diffuseColor = baseColor * (1.0 - mettalic);
surfaceData.diffuseColor = baseColor * (1.0 - mettalic);
data.specularColor = lerp(float3(f0_dieletric, f0_dieletric, f0_dieletric), baseColor, mettalic);
surfaceData.specularColor = lerp(float3(f0_dieletric, f0_dieletric, f0_dieletric), baseColor, mettalic);
data.perceptualSmoothness = tex2D(_BaseColorMap, input.texCoord0).a;
surfaceData.perceptualSmoothness = tex2D(_BaseColorMap, input.texCoord0).a;
data.perceptualSmoothness = tex2D(_MaskMap, input.texCoord0).a;
surfaceData.perceptualSmoothness = tex2D(_MaskMap, input.texCoord0).a;
data.perceptualSmoothness = 1.0;
surfaceData.perceptualSmoothness = 1.0;
data.perceptualSmoothness *= _Smoothness;
surfaceData.perceptualSmoothness *= _Smoothness;
data.specularOcclusion = tex2D(_SpecularOcclusionMap, input.texCoord0).a;
surfaceData.specularOcclusion = tex2D(_SpecularOcclusionMap, input.texCoord0).a;
//data.specularOcclusion = saturate(1.0 + horizonFade * dot(r, input.tangentToWorld[2].xyz);
//surfaceData.specularOcclusion = saturate(1.0 + horizonFade * dot(r, input.tangentToWorld[2].xyz);
//data.specularOcclusion *= data.specularOcclusion;
data.specularOcclusion = 1.0;
//surfaceData.specularOcclusion *= surfaceData.specularOcclusion;
surfaceData.specularOcclusion = 1.0;
#endif
// TODO: think about using BC5

#ifdef _NORMALMAP_TANGENT_SPACE
float3 normalTS = UnpackNormalDXT5nm(tex2D(_NormalMap, input.texCoord0));
data.normalWS = TransformTangentToWorld(normalTS, input.tangentToWorld);
surfaceData.normalWS = TransformTangentToWorld(normalTS, input.tangentToWorld);
data.normalWS = tex2D(_NormalMap, input.texCoord0).rgb;
surfaceData.normalWS = tex2D(_NormalMap, input.texCoord0).rgb;
data.normalWS = vertexNormalWS;
surfaceData.normalWS = vertexNormalWS;
float3 oppositeNormalWS = -data.normalWS;
float3 oppositeNormalWS = -surfaceData.normalWS;
float3 oppositeNormalWS = reflect(data.normalWS, vertexNormalWS);
float3 oppositeNormalWS = reflect(surfaceData.normalWS, vertexNormalWS);
//data.normalWS = IS_FRONT_VFACE(GetOdddNegativeScale() : -GetOdddNegativeScale()) >= 0.0 ? data.normalWS : oppositeNormalWS;
//surfaceData.normalWS = IS_FRONT_VFACE(GetOdddNegativeScale() : -GetOdddNegativeScale()) >= 0.0 ? surfaceData.normalWS : oppositeNormalWS;
data.normalWS = IS_FRONT_VFACE(input.cullFace, data.normalWS, -data.normalWS);
surfaceData.normalWS = IS_FRONT_VFACE(input.cullFace, surfaceData.normalWS, -surfaceData.normalWS);
data.materialId = 0;
surfaceData.materialId = 0;
// TODO: Sample lightmap/lightprobe/volume proxy
// This should also handle projective lightmap
// Note that data input above can be use to sample into lightmap (like normal)
data.diffuseLighting = tex2D(_DiffuseLightingMap, input.texCoord0).rgb;
// If we chose an emissive color, we have a dedicated texture for it and don't use MaskMap
#ifdef _EMISSIVE_COLOR
data.emissiveColor = tex2D(_EmissiveColorMap, input.texCoord0).rgb * _EmissiveColor;
#elif _MASKMAP // If we have a MaskMap, use emissive slot as a mask on baseColor
data.emissiveColor = data.baseColor * tex2D(_MaskMap, uv).b;
#else
data.emissiveColor = float3(0.0, 0.0, 0.0);
#endif
data.emissiveIntensity = _EmissiveIntensity;
data.subSurfaceRadius = 1.0; // tex2D(_SubSurfaceRadiusMap, input.texCoord0).r * _SubSurfaceRadius;
surfaceData.subSurfaceRadius = 1.0; // tex2D(_SubSurfaceRadiusMap, input.texCoord0).r * _SubSurfaceRadius;
// TODO
/*

sampler2D _CoatRoughnessMap;
*/
// TODO: handle alpha for transparency!
// Builtin Data
// TODO: Sample lightmap/lightprobe/volume proxy
// This should also handle projective lightmap
// Note that data input above can be use to sample into lightmap (like normal)
builtinData.bakeDiffuseLighting = tex2D(_DiffuseLightingMap, input.texCoord0).rgb;
// If we chose an emissive color, we have a dedicated texture for it and don't use MaskMap
#ifdef _EMISSIVE_COLOR
builtinData.emissiveColor = tex2D(_EmissiveColorMap, input.texCoord0).rgb * _EmissiveColor;
#elif _MASKMAP // If we have a MaskMap, use emissive slot as a mask on baseColor
builtinData.emissiveColor = data.baseColor * tex2D(_MaskMap, uv).bbb;
#else
builtinData.emissiveColor = float3(0.0, 0.0, 0.0);
#endif
builtinData.emissiveIntensity = _EmissiveIntensity;
builtinData.velocity = float2(0.0, 0.0);
builtinData.distortion = float2(0.0, 0.0);
builtinData.distortionBlur = 0.0;
}
return data;
}
#endif // #if SHADER_STAGE_FRAGMENT

2
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


Coordinate coord;
coord.positionSS = inPositionSS;
// TODO: How to detect automatically that we are a compute shader ?
#if 0
#if SHADER_STAGE_COMPUTE
// In case of compute shader an extra half offset is added to the screenPos to shift the integer position to pixel center.
coord.positionSS.xy += float2(0.5, 0.5);
#endif

89
Assets/TestScenes/HDTest/HDRenderLoopTest.unity


m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 970745596}
m_LocalRotation: {x: 0.31429112, y: 0.005978446, z: -0.010438241, w: 0.94925046}
m_LocalPosition: {x: 2.9189959, y: 2.6469984, z: -3.4988375}
m_LocalPosition: {x: 2.919, y: 2.76, z: -3.651}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}

m_Father: {fileID: 0}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1216278626
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1216278630}
- component: {fileID: 1216278629}
- component: {fileID: 1216278628}
- component: {fileID: 1216278627}
m_Layer: 0
m_Name: Plane (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!23 &1216278627
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1216278626}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingOrder: 0
--- !u!64 &1216278628
MeshCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1216278626}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Convex: 0
m_InflateMesh: 0
m_SkinWidth: 0.01
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!33 &1216278629
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1216278626}
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1216278630
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1216278626}
m_LocalRotation: {x: -0.6515461, y: -0, z: -0, w: 0.7586091}
m_LocalPosition: {x: 0.82856864, y: 2.573, z: -1.6136419}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: -81.317, y: 0, z: 0}
--- !u!1 &1220024533
GameObject:
m_ObjectHideFlags: 0

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1220024533}
m_LocalRotation: {x: -0.0034919123, y: 0.0089843245, z: -0.007998787, w: 0.99992156}
m_LocalPosition: {x: 0.19, y: 1.46, z: 1.26}
m_LocalPosition: {x: 0.19, y: 1.46, z: 1.286}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}

m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022

28
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test.mat


m_PrefabInternal: {fileID: 0}
m_Name: test
m_Shader: {fileID: 4800000, guid: e1a84346ee54f9f4993c2f05c59805a0, type: 3}
m_ShaderKeywords: _EMISSION
m_ShaderKeywords: _EMISSION _NORMALMAP _NORMALMAP_TANGENT_SPACE
m_LightmapFlags: 1
m_CustomRenderQueue: -1
stringTagMap: {}

m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MaskMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MetallicGlossMap
second:
m_Texture: {fileID: 0}

m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _AlphaCutoff
second: 0.5
- first:
name: _AlphaCutoffEnable
second: 0
- first:
name: _BlendMode
second: 0

second: 0
- first:
name: _CullMode
second: 2
second: 0
- first:
name: _Cutoff
second: 0.5

name: _DoubleSidedLigthing
second: 1
- first:
name: _DoubleSidedMode
second: 1
- first:
name: _EmissiveColorMode
second: 1
- first:
name: _EmissiveIntensity
second: 0
- first:

second: 1
- first:
name: _HeightBias
second: 0
- first:
name: _HeightMapMode
second: 0
- first:
name: _HeightScale

second: 0
- first:
name: _Mode
second: 0
- first:
name: _NormalMapSpace
second: 0
- first:
name: _OcclusionStrength

11
Assets/TestScenes/HDTest/Rock/rcgRock012/Materials/rcgRock012Material.mat


m_Name: rcgRock012Material
m_Shader: {fileID: 4800000, guid: e1a84346ee54f9f4993c2f05c59805a0, type: 3}
m_ShaderKeywords: _DOUBLESIDEDLIGTHING_OFF _DOUBLESIDED_OFF _EMISSION _METALLICGLOSSMAP
_NORMALMAP
_NORMALMAP _NORMALMAP_TANGENT_SPACE
m_LightmapFlags: 1
m_CustomRenderQueue: -1
stringTagMap: {}

m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _AlphaCutoff
second: 0.5
- first:
name: _AlphaCutoffEnable
second: 0
- first:

name: _HeightBias
second: 0
- first:
name: _HeightMapMode
second: 0
- first:
name: _HeightScale
second: -1.07
- first:

second: 0
- first:
name: _Mode
second: 0
- first:
name: _NormalMapSpace
second: 0
- first:
name: _OcclusionStrength

32
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.hlsl


#ifndef UNITY_BUILTIN_DATA_INCLUDED
#define UNITY_BUILTIN_DATA_INCLUDED
//-----------------------------------------------------------------------------
// BuiltinData
// This structure include common data that should be present in all material
// and are independent from the BSDF parametrization.
// Note: These parameters can be store in GBuffer if the writer wants
//-----------------------------------------------------------------------------
struct BuiltinData
{
float opacity;
// These are lighting data.
// We would prefer to split lighting and material information but for performance reasons,
// those lighting information are fill
// at the same time than material information.
float3 bakeDiffuseLighting; // This is the result of sampling lightmap/lightprobe/proxyvolume
float3 emissiveColor;
float emissiveIntensity;
// These is required for motion blur and temporalAA
float2 velocity;
// Distortion
float2 distortion;
float distortionBlur; // Define the color buffer mipmap level to use
};
#endif // UNITY_BUILTIN_DATA_INCLUDED

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.hlsl.meta


fileFormatVersion: 2
guid: 82161f939b9c88745950020764de18c9
timeCreated: 1475658936
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

30
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit.hlsl


#ifndef UNITY_UNLIT_INCLUDED
#define UNITY_UNLIT_INCLUDED
struct SurfaceData
{
float3 color;
BuiltinData builtin;
};
struct BSDFData
{
float3 color;
};
//-----------------------------------------------------------------------------
// conversion function for forward
//-----------------------------------------------------------------------------
BSDFData ConvertSurfaceDataToBSDFData(SurfaceData data)
{
BSDFData output;
output.color = data.color;
}
//-----------------------------------------------------------------------------
// No light evaluation, this is unlit
//-----------------------------------------------------------------------------
#endif // UNITY_UNLIT_INCLUDED

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit.hlsl.meta


fileFormatVersion: 2
guid: 00f37057845073e4880c18942abfb094
timeCreated: 1475742185
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

7
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderConfig.cs


//-----------------------------------------------------------------------------
// Configuration
//-----------------------------------------------------------------------------
// #define DIFFUSE_LAMBERT_BRDF
// #define VELOCITY_IN_GBUFFER

12
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderConfig.cs.meta


fileFormatVersion: 2
guid: 4c02a0bb722d0214696c302f8fe1688e
timeCreated: 1475742183
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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


#ifndef UNITY_COMMON_MATERIAL_INCLUDED
#define UNITY_COMMON_MATERIAL_INCLUDED
//-----------------------------------------------------------------------------
// Parametrization function helpers
//-----------------------------------------------------------------------------
float PerceptualRoughnessToRoughness(float perceptualRoughness)
{
return perceptualRoughness * perceptualRoughness;
}
float RoughnessToPerceptualRoughness(float roughness)
{
return sqrt(roughness);
}
float PerceptualSmoothnessToRoughness(float perceptualSmoothness)
{
return (1 - perceptualSmoothness) * (1 - perceptualSmoothness);
}
float PerceptualSmoothnessToPerceptualRoughness(float perceptualSmoothness)
{
return (1 - perceptualSmoothness);
}
#endif // UNITY_COMMON_MATERIAL_INCLUDED

8
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/CommonMaterial.hlsl.meta


fileFormatVersion: 2
guid: 71aa77c8ecebcc942b7914328d88f7d1
timeCreated: 1474465931
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存