|
|
|
|
|
|
_DiffuseColor("Diffuse", Color) = (1,1,1,1) |
|
|
|
_DiffuseMap("Diffuse", 2D) = "white" {} |
|
|
|
|
|
|
|
_SpecColor("Specular", Color) = (0.2,0.2,0.2) |
|
|
|
_SpecColor("Specular", Color) = (0.04,0.04,0.04) |
|
|
|
_SpecMap("Specular", 2D) = "white" {} |
|
|
|
|
|
|
|
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5 |
|
|
|
|
|
|
#pragma vertex MainVS |
|
|
|
#pragma fragment MainPS |
|
|
|
|
|
|
|
|
|
|
|
float4 _DiffuseColor; |
|
|
|
float4 _SpecColor; |
|
|
|
float _Smoothness; |
|
|
|
sampler2D _DiffuseMap; |
|
|
|
sampler2D _NormalMap; |
|
|
|
|
|
|
|
PunctualLightData _lightData[4]; |
|
|
|
float _LightCount; |
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------- |
|
|
|
// Input functions |
|
|
|
|
|
|
|
|
|
|
struct VSOutput |
|
|
|
{ |
|
|
|
float4 positionHS : SV_POSITION; |
|
|
|
float2 texCoord0 : TEXCOORD0; |
|
|
|
float4 tangentToWorld[3] : TEXCOORD1; // [3x3:tangentToWorld | 1x3:viewDirForParallax] |
|
|
|
float3 positionWS : TEXCOORD0; |
|
|
|
float2 texCoord0 : TEXCOORD1; |
|
|
|
float4 tangentToWorld[3] : TEXCOORD2; // [3x3:tangentToWorld | 1x3:viewDirForParallax] |
|
|
|
VSOutput MainVS( VSInput i ) |
|
|
|
VSOutput MainVS(VSInput input) |
|
|
|
VSOutput o; |
|
|
|
VSOutput output; |
|
|
|
float3 positionWS = TransformObjectToWorld(i.positionOS.xyz); |
|
|
|
output.positionWS = TransformObjectToWorld(input.positionOS.xyz); |
|
|
|
o.positionHS = TransformWorldToHClip(positionWS); |
|
|
|
output.positionHS = TransformWorldToHClip(output.positionWS); |
|
|
|
float3 normalWS = TransformObjectToWorldNormal(i.normalOS); |
|
|
|
float3 normalWS = TransformObjectToWorldNormal(input.normalOS); |
|
|
|
o.texCoord0 = i.uv0; |
|
|
|
output.texCoord0 = input.uv0; |
|
|
|
|
|
|
|
// #ifdef _TANGENT_TO_WORLD |
|
|
|
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w); |
|
|
|
|
|
|
|
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w); |
|
|
|
output.tangentToWorld[0].xyz = tangentToWorld[0]; |
|
|
|
output.tangentToWorld[1].xyz = tangentToWorld[1]; |
|
|
|
output.tangentToWorld[2].xyz = tangentToWorld[2]; |
|
|
|
// #else |
|
|
|
// output.tangentToWorld[0].xyz = 0; |
|
|
|
// output.tangentToWorld[1].xyz = 0; |
|
|
|
// output.tangentToWorld[2].xyz = normalWS; |
|
|
|
// #endif |
|
|
|
|
|
|
|
output.tangentToWorld[0].w = 0; |
|
|
|
output.tangentToWorld[1].w = 0; |
|
|
|
output.tangentToWorld[2].w = 0; |
|
|
|
|
|
|
|
return output; |
|
|
|
} |
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
// This function is either hand written or generate by the material graph |
|
|
|
DisneyGGXSurfaceData GetSurfaceData(VSOutput input) |
|
|
|
{ |
|
|
|
DisneyGGXSurfaceData data; |
|
|
|
|
|
|
|
data.diffuseColor = tex2D(_DiffuseMap, input.texCoord0) * _DiffuseColor; |
|
|
|
data.occlusion = 1.0; |
|
|
|
#ifdef _TANGENT_TO_WORLD |
|
|
|
float4 tangentWS = float4(TransformObjectToWorldDir(i.tangentOS.xyz), i.tangentOS.w); |
|
|
|
data.specularColor = _SpecColor; |
|
|
|
data.smoothness = _Smoothness; |
|
|
|
float3x3 tangentToWorld = CreateTangentToWorld(normalWorld, tangentWorld.xyz, tangentWorld.w); |
|
|
|
o.tangentToWorld[0].xyz = tangentToWorld[0]; |
|
|
|
o.tangentToWorld[1].xyz = tangentToWorld[1]; |
|
|
|
o.tangentToWorld[2].xyz = tangentToWorld[2]; |
|
|
|
#else |
|
|
|
o.tangentToWorld[0].xyz = 0; |
|
|
|
o.tangentToWorld[1].xyz = 0; |
|
|
|
o.tangentToWorld[2].xyz = normalWS; |
|
|
|
#endif |
|
|
|
data.normal = UnpackNormalDXT5nm(tex2D(_NormalMap, input.texCoord0)); |
|
|
|
return o; |
|
|
|
return data; |
|
|
|
float4 MainPS( VSOutput i ) : SV_Target |
|
|
|
//------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
float4 MainPS(VSOutput input) : SV_Target |
|
|
|
return float4( 1.0, 0.0, 0.0, 0.0 ); |
|
|
|
float3 V = GetWorldSpaceNormalizeViewDir(input.positionWS); |
|
|
|
|
|
|
|
DisneyGGXSurfaceData surfaceData = GetSurfaceData(input); |
|
|
|
DisneyGGXBSDFData BSDFData = ConvertSurfaceDataToBSDFData(surfaceData); |
|
|
|
|
|
|
|
float4 outDiffuseLighting; |
|
|
|
float4 outSpecularLighting; |
|
|
|
|
|
|
|
for (int i = 0; i < _LightCount; ++i) |
|
|
|
{ |
|
|
|
float4 diffuseLighting; |
|
|
|
float4 specularLighting; |
|
|
|
EvaluateBSDF_Punctual_DisneyGGX(V, input.positionWS, _lightData[i], BSDFData, diffuseLighting, specularLighting); |
|
|
|
|
|
|
|
outDiffuseLighting += diffuseLighting; |
|
|
|
outSpecularLighting += specularLighting; |
|
|
|
} |
|
|
|
|
|
|
|
return outDiffuseLighting + outSpecularLighting; |
|
|
|
} |
|
|
|
|
|
|
|
ENDCG |
|
|
|