|
|
|
|
|
|
#if !defined(LAYERED_LIT_SHADER) |
|
|
|
|
|
|
|
void GetSurfaceAndBuiltinData(FragInput input, out SurfaceData surfaceData, out BuiltinData builtinData) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifdef _HEIGHTMAP |
|
|
|
// TODO: in case of shader graph, a node like parallax must be nullify if use to generate code for Meta pass |
|
|
|
#ifndef _HEIGHTMAP_AS_DISPLACEMENT |
|
|
|
|
|
|
outWeights[0] = left; |
|
|
|
} |
|
|
|
|
|
|
|
float2 ComputePlanarXZCoord(float3 worldPos, float layerSize) |
|
|
|
{ |
|
|
|
return frac(worldPos.xz / layerSize); |
|
|
|
} |
|
|
|
|
|
|
|
void ComputeLayerCoordinates(out LayerCoordinates outCoord, FragInput input) |
|
|
|
{ |
|
|
|
#if defined(_LAYER_MAPPING_UV1_0) |
|
|
|
outCoord.texcoord[0] = input.texCoord1; |
|
|
|
outCoord.isTriplanar[0] = false; |
|
|
|
#elif defined(_LAYER_MAPPING_PLANAR_0) |
|
|
|
outCoord.texcoord[0] = ComputePlanarXZCoord(input.positionWS, _LayerSize0); |
|
|
|
outCoord.isTriplanar[0] = false; |
|
|
|
#elif defined(_LAYER_MAPPING_TRIPLANAR_0) |
|
|
|
outCoord.texcoord[0] = input.texCoord0; |
|
|
|
outCoord.isTriplanar[0] = true; |
|
|
|
#else |
|
|
|
outCoord.texcoord[0] = input.texCoord0; |
|
|
|
outCoord.isTriplanar[0] = false; |
|
|
|
#endif |
|
|
|
|
|
|
|
#if defined(_LAYER_MAPPING_UV1_1) |
|
|
|
outCoord.texcoord[1] = input.texCoord1; |
|
|
|
outCoord.isTriplanar[1] = false; |
|
|
|
#elif defined(_LAYER_MAPPING_PLANAR_1) |
|
|
|
outCoord.texcoord[1] = ComputePlanarXZCoord(input.positionWS, _LayerSize1); |
|
|
|
outCoord.isTriplanar[1] = false; |
|
|
|
#elif defined(_LAYER_MAPPING_TRIPLANAR_1) |
|
|
|
outCoord.texcoord[1] = input.texCoord0; |
|
|
|
outCoord.isTriplanar[1] = true; |
|
|
|
#else |
|
|
|
outCoord.texcoord[1] = input.texCoord0; |
|
|
|
outCoord.isTriplanar[1] = false; |
|
|
|
#endif |
|
|
|
|
|
|
|
#if defined(_LAYER_MAPPING_UV1_2) |
|
|
|
outCoord.texcoord[2] = input.texCoord1; |
|
|
|
outCoord.isTriplanar[2] = false; |
|
|
|
#elif defined(_LAYER_MAPPING_PLANAR_2) |
|
|
|
outCoord.texcoord[2] = ComputePlanarXZCoord(input.positionWS, _LayerSize2); |
|
|
|
outCoord.isTriplanar[2] = false; |
|
|
|
#elif defined(_LAYER_MAPPING_TRIPLANAR_2) |
|
|
|
outCoord.texcoord[2] = input.texCoord0; |
|
|
|
outCoord.isTriplanar[2] = true; |
|
|
|
#else |
|
|
|
outCoord.texcoord[2] = input.texCoord0; |
|
|
|
outCoord.isTriplanar[2] = false; |
|
|
|
#endif |
|
|
|
|
|
|
|
#if defined(_LAYER_MAPPING_UV1_3) |
|
|
|
outCoord.texcoord[3] = input.texCoord1; |
|
|
|
outCoord.isTriplanar[3] = false; |
|
|
|
#elif defined(_LAYER_MAPPING_PLANAR_3) |
|
|
|
outCoord.texcoord[3] = ComputePlanarXZCoord(input.positionWS, _LayerSize3); |
|
|
|
outCoord.isTriplanar[3] = false; |
|
|
|
#elif defined(_LAYER_MAPPING_TRIPLANAR_3) |
|
|
|
outCoord.texcoord[3] = input.texCoord0; |
|
|
|
outCoord.isTriplanar[3] = true; |
|
|
|
#else |
|
|
|
outCoord.texcoord[3] = input.texCoord0; |
|
|
|
outCoord.isTriplanar[3] = false; |
|
|
|
#endif |
|
|
|
} |
|
|
|
LayerCoordinates layerCoord; |
|
|
|
ComputeLayerCoordinates(layerCoord, input); |
|
|
|
|
|
|
|
// Mask Values : Layer 1, 2, 3 are r, g, b |
|
|
|
float3 maskValues = float3(0.0, 0.0, 0.0);// input.vertexColor; |
|
|
|
|
|
|
|
|
|
|
ComputeMaskWeights(maskValues, weights); |
|
|
|
|
|
|
|
PROP_DECL(float3, baseColor); |
|
|
|
PROP_SAMPLE(baseColor, _BaseColorMap, input.texCoord0, rgb); |
|
|
|
PROP_SAMPLE(baseColor, _BaseColorMap, layerCoord, rgb); |
|
|
|
PROP_MUL(baseColor, _BaseColor, rgb); |
|
|
|
PROP_BLEND_COLOR(baseColor, weights); |
|
|
|
|
|
|
|
|
|
|
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|
|
|
PROP_ASSIGN(alpha, _BaseColor, a); |
|
|
|
#else |
|
|
|
PROP_SAMPLE(alpha, _BaseColorMap, input.texCoord0, a); |
|
|
|
PROP_SAMPLE(alpha, _BaseColorMap, layerCoord, a); |
|
|
|
PROP_MUL(alpha, _BaseColor, a); |
|
|
|
#endif |
|
|
|
PROP_BLEND_SCALAR(alpha, weights); |
|
|
|
|
|
|
PROP_DECL(float, specularOcclusion); |
|
|
|
#ifdef _SPECULAROCCLUSIONMAP |
|
|
|
// TODO: Do something. For now just take alpha channel |
|
|
|
PROP_SAMPLE(specularOcclusion, _SpecularOcclusionMap, input.texCoord0, a); |
|
|
|
PROP_SAMPLE(specularOcclusion, _SpecularOcclusionMap, layerCoord, a); |
|
|
|
#else |
|
|
|
// Horizon Occlusion for Normal Mapped Reflections: http://marmosetco.tumblr.com/post/81245981087 |
|
|
|
//surfaceData.specularOcclusion = saturate(1.0 + horizonFade * dot(r, input.tangentToWorld[2].xyz); |
|
|
|
|
|
|
|
|
|
|
#ifdef _NORMALMAP |
|
|
|
#ifdef _NORMALMAP_TANGENT_SPACE |
|
|
|
float3 normalTS0 = UnpackNormalAG(SAMPLE_TEXTURE2D(_NormalMap0, sampler_NormalMap0, input.texCoord0)); |
|
|
|
float3 normalTS1 = UnpackNormalAG(SAMPLE_TEXTURE2D(_NormalMap1, sampler_NormalMap0, input.texCoord0)); |
|
|
|
float3 normalTS2 = UnpackNormalAG(SAMPLE_TEXTURE2D(_NormalMap2, sampler_NormalMap0, input.texCoord0)); |
|
|
|
float3 normalTS3 = UnpackNormalAG(SAMPLE_TEXTURE2D(_NormalMap3, sampler_NormalMap0, input.texCoord0)); |
|
|
|
float3 normalTS0 = UnpackNormalAG(SampleLayer(TEXTURE2D_PARAM(_NormalMap0, sampler_NormalMap0), layerCoord, 0)); |
|
|
|
float3 normalTS1 = UnpackNormalAG(SampleLayer(TEXTURE2D_PARAM(_NormalMap1, sampler_NormalMap0), layerCoord, 1)); |
|
|
|
float3 normalTS2 = UnpackNormalAG(SampleLayer(TEXTURE2D_PARAM(_NormalMap2, sampler_NormalMap0), layerCoord, 2)); |
|
|
|
float3 normalTS3 = UnpackNormalAG(SampleLayer(TEXTURE2D_PARAM(_NormalMap3, sampler_NormalMap0), layerCoord, 3)); |
|
|
|
|
|
|
|
float3 normalTS = BlendLayeredNormal(normalTS0, normalTS1, normalTS2, normalTS3, weights); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PROP_DECL(float, perceptualSmoothness); |
|
|
|
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A |
|
|
|
PROP_SAMPLE(perceptualSmoothness, _BaseColorMap, input.texCoord0, a); |
|
|
|
PROP_SAMPLE(perceptualSmoothness, _BaseColorMap, layerCoord, a); |
|
|
|
PROP_SAMPLE(perceptualSmoothness, _MaskMap, input.texCoord0, a); |
|
|
|
PROP_SAMPLE(perceptualSmoothness, _MaskMap, layerCoord, a); |
|
|
|
#else |
|
|
|
PROP_ASSIGN_VALUE(perceptualSmoothness, 1.0); |
|
|
|
#endif |
|
|
|
|
|
|
PROP_DECL(float, metallic); |
|
|
|
PROP_DECL(float, ambientOcclusion); |
|
|
|
#ifdef _MASKMAP |
|
|
|
PROP_SAMPLE(metallic, _MaskMap, input.texCoord0, a); |
|
|
|
PROP_SAMPLE(ambientOcclusion, _MaskMap, input.texCoord0, g); |
|
|
|
PROP_SAMPLE(metallic, _MaskMap, layerCoord, a); |
|
|
|
PROP_SAMPLE(ambientOcclusion, _MaskMap, layerCoord, g); |
|
|
|
#else |
|
|
|
PROP_ASSIGN_VALUE(metallic, 1.0); |
|
|
|
PROP_ASSIGN_VALUE(ambientOcclusion, 1.0); |
|
|
|
|
|
|
PROP_DECL(float3, emissiveColor); |
|
|
|
#ifdef _EMISSIVE_COLOR |
|
|
|
#ifdef _EMISSIVE_COLOR_MAP |
|
|
|
PROP_SAMPLE(emissiveColor, _EmissiveColorMap, input.texCoord0, rgb); |
|
|
|
PROP_SAMPLE(emissiveColor, _EmissiveColorMap, layerCoord, rgb); |
|
|
|
PROP_SAMPLE(emissiveColor, _MaskMap, input.texCoord0, bbb); |
|
|
|
PROP_SAMPLE(emissiveColor, _MaskMap, layerCoord, bbb); |
|
|
|
PROP_MUL(emissiveColor, baseColor, rgb); |
|
|
|
#else |
|
|
|
PROP_ASSIGN_VALUE(emissiveColor, float3(0.0, 0.0, 0.0)); |
|
|
|