浏览代码

HDRenderLoop: Update GGXDisney.Shader with lot of parameters

- Goal is to add a lot of thing so we can ensure that scriptable render
loop support all the case
- Here try to add transparent and alpha testing + prepare materialID
with SSS and clear coat.
/main
sebastienlagarde 8 年前
当前提交
07ccb020
共有 4 个文件被更改,包括 250 次插入48 次删除
  1. 56
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader
  2. 34
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/DisneyGGX.hlsl
  3. 99
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl
  4. 109
      Assets/TestScenes/HDTest/Material/test.mat

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


Shader "Unity/DisneyGGX"
{
// TODO: Following set of parameters represent the parameters node inside the MaterialGraph.
// They are use to fill a SurfaceData. With a MaterialGraph these parameters will not be write here (?).
// Following set of parameters represent the parameters node inside the MaterialGraph.
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist.
_DiffuseColor("Diffuse", Color) = (1,1,1,1)
_DiffuseMap("Diffuse", 2D) = "white" {}
_BaseColor("BaseColor", Color) = (1,1,1,1)
_BaseColorMap("BaseColorMap", 2D) = "white" {}
_AmbientOcclusionMap("AmbientOcclusion", 2D) = "white" {}
_SpecColor("Specular", Color) = (0.04,0.04,0.04)
_SpecMap("Specular", 2D) = "white" {}
_Mettalic("Mettalic", Range(0.0, 1.0)) = 0
_MettalicMap("MettalicMap", 2D) = "white" {}
_SmoothnessMap("Smoothness", 2D) = "white" {}
_SmoothnessMap("SmoothnessMap", 2D) = "white" {}
_SpecularOcclusionMap("SpecularOcclusion", 2D) = "white" {}
_NormalMap("Normal Map", 2D) = "bump" {}
_OcclusionMap("Occlusion", 2D) = "white" {}
_NormalMap("NormalMap", 2D) = "bump" {}
[Enum(TangentSpace, 0, ObjectSpace, 1)] _MaterialID("NormalMap space", Float) = 0
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_DiffuseLightingMap("DiffuseLightingMap", 2D) = "black" {}
_EmissiveColor("Emissive", Color) = (0, 0, 0)
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
_EmissiveIntensity("EmissiveIntensity", Float) = 0
_SubSurfaceRadius("SubSurfaceRadius", Range(0.0, 1.0)) = 0
//_SubSurfaceRadiusMap("SubSurfaceRadiusMap", 2D) = "white" {}
//_Thickness("Thickness", Range(0.0, 1.0)) = 0
//_ThicknessMap("ThicknessMap", 2D) = "white" {}
//_SubSurfaceProfile("SubSurfaceProfile", Float) = 0
//_CoatCoverage("CoatCoverage", Range(0.0, 1.0)) = 0
//_CoatCoverageMap("CoatCoverageMapMap", 2D) = "white" {}
//_CoatRoughness("CoatRoughness", Range(0.0, 1.0)) = 0
//_CoatRoughnessMap("CoatRoughnessMap", 2D) = "white" {}
// _DistortionVectorMap("DistortionVectorMap", 2D) = "white" {}
// _DistortionBlur("DistortionBlur", Range(0.0, 1.0)) = 0
// Following options are for the GUI inspector and different from the input parameters above
// These option below will cause different compilation flag.
[ToggleOff] _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
[ToggleOff] _DoubleSided("Double Sided", Float) = 1.0
[ToggleOff] _DoubleSidedLigthing("Double Sided Lighting", Float) = 1.0
[HideInInspector] _Mode ("__mode", Float) = 0.0
[HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0
[HideInInspector] _BlendMode ("__blendmode", Float) = 0.0
// Material Id
[HideInInspector] _MaterialId("_MaterialId", FLoat) = 0
}
CGINCLUDE

ENDCG
}
}
//CustomEditor "DisneyGGXGUI"
}

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


// 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 diffuseColor;
float matData0;
float ambientOcclusion;
float SpecularOcclusion;
//float matData1;
float specularOcclusion;
float ambientOcclusion;
// 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

float emissiveIntensity;
// MaterialID SSS - When enable, we only need one channel for specColor, so one is free to store information.
float subSurfaceRadius;
// float thickness;
// int subSurfaceProfile;
// MaterialID Clear coat
// float coatCoverage;
// float coatRoughness;
// Distortion
// float2 distortionVector;
// float distortionBlur; // Define the mipmap level to use
// float2 velocityVector;
};
struct BSDFData

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

BSDFData output;
output.diffuseColor = data.diffuseColor;
output.matData0 = data.matData0;
output.matData0 = data.subSurfaceRadius; // TEMP
output.SpecularOcclusion = data.SpecularOcclusion;
output.specularOcclusion = data.specularOcclusion;
//output.matData1 = data.matData1;
output.normalWS = data.normalWS;

void EncodeIntoGBuffer(SurfaceData data, out float4 outGBuffer0, out float4 outGBuffer1, out float4 outGBuffer2, out float4 outGBuffer3)
{
// RT0 - 8:8:8:8 sRGB
outGBuffer0 = float4(data.diffuseColor, data.matData0);
outGBuffer0 = float4(data.diffuseColor, data.subSurfaceRadius);
outGBuffer1 = float4(data.specularColor, data.SpecularOcclusion /*, data.matData1 */);
outGBuffer1 = float4(data.specularColor, data.specularOcclusion /*, data.matData1 */);
// RT2 - 10:10:10:2
// Encode normal on 20bit with oct compression

bsdfData.matData0 = inGBuffer0.a;
bsdfData.fresnel0 = inGBuffer1.rgb;
bsdfData.SpecularOcclusion = inGBuffer1.a;
bsdfData.specularOcclusion = inGBuffer1.a;
// bsdfData.matData1 = ?;
bsdfData.normalWS = UnpackNormalOctEncode(float2(inGBuffer2.r * 2.0 - 1.0, inGBuffer2.g * 2 - 1));

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


//-------------------------------------------------------------------------------------
// Set of users variables
float4 _DiffuseColor;
float4 _SpecColor;
float4 _BaseColor;
sampler2D _BaseColorMap;
sampler2D _AmbientOcclusionMap;
float _Mettalic;
sampler2D MettalicMap;
sampler2D _DiffuseMap;
sampler2D _SmoothnessMap;
sampler2D _SpecularOcclusionMap;
// ... Others
sampler2D _DiffuseLightingMap;
float4 _EmissiveColor;
sampler2D _EmissiveColorMap;
float _EmissiveIntensity;
float _SubSurfaceRadius;
sampler2D _SubSurfaceRadiusMap;
// float _Thickness;
// sampler2D _ThicknessMap;
// float _CoatCoverage;
// sampler2D _CoatCoverageMap;
// float _CoatRoughness;
// sampler2D _CoatRoughnessMap;
float _Cutoff;
//-------------------------------------------------------------------------------------
// Lighting architecture

float3 TransformTangentToWorld(float3 normalTS, float4 tangentToWorld[3])
{
#if 0
// regular normal
float3 normalWS = normalize(tangentToWorld[2].xyz);
#else
// TO check: do we need to normalize ?
float3 normalWS = normalize(mul(normalTS, float3x3(tangentToWorld[0].xyz, tangentToWorld[1].xyz, tangentToWorld[2].xyz)));
#endif
return normalWS;
// TODO check: do we need to normalize ?
return normalize(mul(normalTS, float3x3(tangentToWorld[0].xyz, tangentToWorld[1].xyz, tangentToWorld[2].xyz)));
// 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.
data.diffuseColor = tex2D(_DiffuseMap, input.texCoord0) * _DiffuseColor;
data.matData0 = 0.0;
float3 baseColor = tex2D(_BaseColorMap, input.texCoord0).rgb * _BaseColor.rgb;
float alpha = tex2D(_BaseColorMap, input.texCoord0).a * _BaseColor.a;
#if defined(_ALPHATEST_ON)
clip(alpha - _Cutoff);
#endif
data.ambientOcclusion = tex2D(_AmbientOcclusionMap, input.texCoord0).r;
data.SpecularOcclusion = 1.0;
data.ambientOcclusion = 1.0;
float mettalic = tex2D(MettalicMap, input.texCoord0).r * _Mettalic;
data.perceptualSmoothness = tex2D(_SmoothnessMap, input.texCoord0).r * _Smoothness;
data.specularOcclusion = tex2D(_SpecularOcclusionMap, input.texCoord0).r;
data.specularColor = _SpecColor;
data.perceptualSmoothness = _Smoothness;
data.diffuseColor = baseColor * (1.0f - mettalic);
float f0_dieletric = 0.04;
data.specularColor = lerp(float3(f0_dieletric, f0_dieletric, f0_dieletric), baseColor, mettalic);
#if 1 //_USE_NORMAL_MAP
#if 1 //_USE_NORMAL_MAP_TANGENT_SPACE
// data.normal = input.tangentToWorld[2].xyz;
#else // Object space (TODO: We need to apply the world rotation here!)
data.normalWS = tex2D(_NormalMap, input.texCoord0).rgb;
#endif
#else
data.normalWS = normalize(input.tangentToWorld[2].xyz);
#endif
data.materialId = 0;

data.diffuseLighting = float3(0.0, 0.0, 0.0);
data.diffuseLighting = tex2D(_DiffuseLightingMap, input.texCoord0).rgb;
data.emissiveColor = float3(0.0, 0.0, 0.0);
data.emissiveIntensity = 0.0;
data.emissiveColor = tex2D(_EmissiveColorMap, input.texCoord0).rgb * _EmissiveColor;
data.emissiveIntensity = _EmissiveIntensity;
data.subSurfaceRadius = tex2D(_SubSurfaceRadiusMap, input.texCoord0).r * _SubSurfaceRadius;
// TODO
/*
float _SubSurfaceRadius;
sampler2D _SubSurfaceRadiusMap;
float _Thickness;
sampler2D _ThicknessMap;
float _CoatCoverage;
sampler2D _CoatCoverageMap;
float _CoatRoughness;
sampler2D _CoatRoughnessMap;
*/
// TODO: handle alpha for transparency!
return data;
}

109
Assets/TestScenes/HDTest/Material/test.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: test
m_Shader: {fileID: 4800000, guid: e1a84346ee54f9f4993c2f05c59805a0, type: 3}
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: _EMISSION
m_LightmapFlags: 1
m_CustomRenderQueue: -1

m_TexEnvs:
- first:
name: _AmbientOcclusionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _BaseColorMap
second:
m_Texture: {fileID: 2800000, guid: d734753529ca78148a43944515a64bc5, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _BumpMap
second:

- first:
name: _CoatCoverageMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _CoatRoughnessMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailAlbedoMap
second:
m_Texture: {fileID: 0}

m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DiffuseLightingMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DiffuseMap
second:
m_Texture: {fileID: 2800000, guid: d734753529ca78148a43944515a64bc5, type: 3}

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

m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MettalicMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _NormalMap
second:
m_Texture: {fileID: 2800000, guid: 11f99173903c31f49b05339fc71c7919, type: 3}

m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _SpecularOcclusionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _SubSurfaceRadiusMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _ThicknessMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
name: _BlendMode
second: 0
- first:
name: _CoatCoverage
second: 0
- first:
name: _CoatRoughness
second: 0
- first:
name: _Cutoff
second: 0.5
- first:

name: _DoubleSided
second: 1
- first:
name: _DoubleSidedLigthing
second: 1
- first:
second: 0
- first:
name: _EmissiveIntensity
second: 0
- first:
name: _GlossMapScale

name: _GlossyReflections
second: 1
- first:
name: _MaterialID
second: 0
- first:
name: _MaterialId
second: 0
- first:
second: 0
- first:
name: _Mettalic
second: 0
- first:
name: _Mode

second: 0.02
- first:
name: _Smoothness
second: 0.5
second: 0.524
- first:
name: _SmoothnessTextureChannel
second: 0

name: _SrcBlend
second: 1
- first:
name: _SubSurfaceProfile
second: 0
- first:
name: _SubSurfaceRadius
second: 0
- first:
name: _SurfaceType
second: 0
- first:
name: _Thickness
second: 0
- first:
name: _UVSec
second: 0
- first:

- first:
name: _BaseColor
second: {r: 1, g: 1, b: 1, a: 1}
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
- first:

name: _EmissionColor
second: {r: 0, g: 0, b: 0, a: 1}
- first:
name: _EmissiveColor
second: {r: 0, g: 0, b: 0, a: 1}
- first:
name: _SpecColor
正在加载...
取消
保存