|
|
|
|
|
|
// SurfaceData and BSDFData |
|
|
|
//----------------------------------------------------------------------------- |
|
|
|
|
|
|
|
// TODO: THis is suppose to be genenerated from enum on C# side, but haven't written the code yet! |
|
|
|
#define LIT_STANDARD 0 |
|
|
|
#define LIT_SSS 1 |
|
|
|
#define LIT_CLEARCOAT 2 |
|
|
|
#define LIT_SPECULAR 3 |
|
|
|
|
|
|
|
// SurfaceData is define in Lit.cs which generate Lit.cs.hlsl |
|
|
|
#include "Lit.cs.hlsl" |
|
|
|
|
|
|
|
|
|
|
bsdfData.roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness); |
|
|
|
bsdfData.materialId = surfaceData.materialId; |
|
|
|
|
|
|
|
if (bsdfData.materialId == LIT_STANDARD) |
|
|
|
if (bsdfData.materialId == MATERIALID_LIT_STANDARD) |
|
|
|
{ |
|
|
|
bsdfData.diffuseColor = surfaceData.baseColor * (1.0 - surfaceData.metalic); |
|
|
|
bsdfData.fresnel0 = lerp(float3(surfaceData.specular, surfaceData.specular, surfaceData.specular), surfaceData.baseColor, surfaceData.metalic); |
|
|
|
|
|
|
ConvertAnisotropyToRoughness(bsdfData.roughness, surfaceData.anisotropy, bsdfData.roughnessT, bsdfData.roughnessB); |
|
|
|
} |
|
|
|
else if (bsdfData.materialId == LIT_SSS) |
|
|
|
else if (bsdfData.materialId == MATERIALID_LIT_SSS) |
|
|
|
{ |
|
|
|
bsdfData.diffuseColor = surfaceData.baseColor; |
|
|
|
bsdfData.fresnel0 = 0.028; // TODO take from subSurfaceProfile |
|
|
|
|
|
|
else if (bsdfData.materialId == LIT_CLEARCOAT) |
|
|
|
else if (bsdfData.materialId == MATERIALID_LIT_CLEAR_COAT) |
|
|
|
{ |
|
|
|
bsdfData.diffuseColor = surfaceData.baseColor * (1.0 - surfaceData.metalic); |
|
|
|
bsdfData.fresnel0 = lerp(float3(surfaceData.specular, surfaceData.specular, surfaceData.specular), surfaceData.baseColor, surfaceData.metalic); |
|
|
|
|
|
|
else if (bsdfData.materialId == LIT_SPECULAR) |
|
|
|
else if (bsdfData.materialId == MATERIALID_LIT_SPECULAR) |
|
|
|
{ |
|
|
|
bsdfData.diffuseColor = surfaceData.baseColor; |
|
|
|
bsdfData.fresnel0 = surfaceData.specularColor; |
|
|
|
|
|
|
{ |
|
|
|
float3 diffuseColor; |
|
|
|
|
|
|
|
if (surfaceData.materialId == LIT_STANDARD) |
|
|
|
if (surfaceData.materialId == MATERIALID_LIT_STANDARD) |
|
|
|
else if (surfaceData.materialId == LIT_SSS) |
|
|
|
else if (surfaceData.materialId == MATERIALID_LIT_SSS) |
|
|
|
else if (surfaceData.materialId == LIT_CLEARCOAT) |
|
|
|
else if (surfaceData.materialId == MATERIALID_LIT_CLEAR_COAT) |
|
|
|
else if (surfaceData.materialId == LIT_SPECULAR) |
|
|
|
else if (surfaceData.materialId == MATERIALID_LIT_SPECULAR) |
|
|
|
{ |
|
|
|
diffuseColor = surfaceData.baseColor; |
|
|
|
} |
|
|
|
|
|
|
outGBuffer1 = float4(octNormalWS * 0.5 + 0.5, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness), PackMaterialId(surfaceData.materialId)); |
|
|
|
|
|
|
|
// RT2 - 8:8:8:8 |
|
|
|
if (surfaceData.materialId == LIT_STANDARD) |
|
|
|
if (surfaceData.materialId == MATERIALID_LIT_STANDARD) |
|
|
|
{ |
|
|
|
// Encode tangent on 16bit with oct compression |
|
|
|
float2 octTangentWS = PackNormalOctEncode(surfaceData.tangentWS); |
|
|
|
|
|
|
else if (surfaceData.materialId == LIT_SSS) |
|
|
|
else if (surfaceData.materialId == MATERIALID_LIT_SSS) |
|
|
|
else if (surfaceData.materialId == LIT_CLEARCOAT) |
|
|
|
else if (surfaceData.materialId == MATERIALID_LIT_CLEAR_COAT) |
|
|
|
{ |
|
|
|
// Encode coat normal on 16bit with oct compression |
|
|
|
float2 octCoatNormalWS = PackNormalOctEncode(surfaceData.coatNormalWS); |
|
|
|
|
|
|
else if (surfaceData.materialId == LIT_SPECULAR) |
|
|
|
else if (surfaceData.materialId == MATERIALID_LIT_SPECULAR) |
|
|
|
{ |
|
|
|
outGBuffer2 = float4(surfaceData.specularColor, 0.0); |
|
|
|
} |
|
|
|
|
|
|
bsdfData.roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness); |
|
|
|
bsdfData.materialId = UnpackMaterialId(inGBuffer1.a); |
|
|
|
|
|
|
|
if (bsdfData.materialId == LIT_STANDARD) |
|
|
|
if (bsdfData.materialId == MATERIALID_LIT_STANDARD) |
|
|
|
{ |
|
|
|
float metalic = inGBuffer2.a; |
|
|
|
// TODO extract spec |
|
|
|
|
|
|
bsdfData.bitangentWS = cross(bsdfData.normalWS, bsdfData.tangentWS); |
|
|
|
ConvertAnisotropyToRoughness(bsdfData.roughness, anisotropy, bsdfData.roughnessT, bsdfData.roughnessB); |
|
|
|
} |
|
|
|
else if (bsdfData.materialId == LIT_SSS) |
|
|
|
else if (bsdfData.materialId == MATERIALID_LIT_SSS) |
|
|
|
{ |
|
|
|
bsdfData.diffuseColor = baseColor; |
|
|
|
bsdfData.fresnel0 = 0.028; // TODO take from subSurfaceProfile |
|
|
|
|
|
|
else if (bsdfData.materialId == LIT_CLEARCOAT) |
|
|
|
else if (bsdfData.materialId == MATERIALID_LIT_CLEAR_COAT) |
|
|
|
{ |
|
|
|
float metalic = inGBuffer2.a; |
|
|
|
// TODO extract spec |
|
|
|
|
|
|
bsdfData.coatNormalWS = UnpackNormalOctEncode(float2(inGBuffer2.rg * 2.0 - 1.0)); |
|
|
|
bsdfData.coatRoughness = inGBuffer2.b; |
|
|
|
} |
|
|
|
else if (bsdfData.materialId == LIT_SPECULAR) |
|
|
|
else if (bsdfData.materialId == MATERIALID_LIT_SPECULAR) |
|
|
|
{ |
|
|
|
bsdfData.diffuseColor = baseColor; |
|
|
|
bsdfData.fresnel0 = inGBuffer2.rgb; |
|
|
|
|
|
|
{ |
|
|
|
switch (paramId) |
|
|
|
{ |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_BASECOLOR: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_BASE_COLOR: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_SPECULAROCCLUSION: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_SPECULAR_OCCLUSION: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_NORMALWS: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_NORMAL_WS: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_PERCEPTUALSMOOTHNESS: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_PERCEPTUAL_SMOOTHNESS: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_MATERIALID: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_MATERIAL_ID: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_AMBIENTOCCLUSION: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_AMBIENT_OCCLUSION: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_TANGENTWS: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_TANGENT_WS: |
|
|
|
result = surfaceData.tangentWS * 0.5 + 0.5; |
|
|
|
break; |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_ANISOTROPY: |
|
|
|
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_SPECULAR: |
|
|
|
result = surfaceData.specular.xxx; |
|
|
|
break; |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_SUBSURFACERADIUS: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_SUB_SURFACE_RADIUS: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_SUBSURFACEPROFILE: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_SUB_SURFACE_PROFILE: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_COATNORMALWS: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_COAT_NORMAL_WS: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_COATPERCEPTUALSMOOTHNESS: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_COAT_PERCEPTUAL_SMOOTHNESS: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_SPECULARCOLOR: |
|
|
|
case DEBUGVIEW_LIT_SURFACEDATA_SPECULAR_COLOR: |
|
|
|
result = surfaceData.specularColor; needLinearToSRGB = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
{ |
|
|
|
switch (paramId) |
|
|
|
{ |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_DIFFUSECOLOR: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_DIFFUSE_COLOR: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_SPECULAROCCLUSION: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_SPECULAR_OCCLUSION: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_NORMALWS: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_NORMAL_WS: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_PERCEPTUALROUGHNESS: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_PERCEPTUAL_ROUGHNESS: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_MATERIALID: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_MATERIAL_ID: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_TANGENTWS: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_TANGENT_WS: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_BITANGENTWS: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_BITANGENT_WS: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESST: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS_T: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESSB: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS_B: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_SUBSURFACERADIUS: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_SUB_SURFACE_RADIUS: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_SUBSURFACEPROFILE: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_SUB_SURFACE_PROFILE: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_COATNORMALWS: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_COAT_NORMAL_WS: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_COATROUGHNESS: |
|
|
|
case DEBUGVIEW_LIT_BSDFDATA_COAT_ROUGHNESS: |
|
|
|
result = bsdfData.coatRoughness.xxx; |
|
|
|
break; |
|
|
|
} |
|
|
|