1
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
Shader "%SHADERNAME%"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
%PROPERTIES%
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
%TAGS%
|
||||
|
||||
%PASSFORWARD%
|
||||
%PASSFORWARDADD%
|
||||
%PASSGBUFFER%
|
||||
%PASSSHADOW%
|
||||
%PASSMETA%
|
||||
UsePass "Hidden/Nature/Terrain/Utilities/PICKING"
|
||||
UsePass "Hidden/Nature/Terrain/Utilities/SELECTION"
|
||||
|
||||
}
|
||||
%DEPENDENCY%
|
||||
%FALLBACK%
|
||||
%CUSTOMEDITOR%
|
||||
}
|
@@ -0,0 +1,515 @@
|
||||
// If your looking in here and thinking WTF, yeah, I know. These are taken from the SRPs, to allow us to use the same
|
||||
// texturing library they use. However, since they are not included in the standard pipeline by default, there is no
|
||||
// way to include them in and they have to be inlined, since someone could copy this shader onto another machine without
|
||||
// MicroSplat installed. Unfortunate, but I'd rather do this and have a nice library for texture sampling instead
|
||||
// of the patchy one Unity provides being inlined/emulated in HDRP/URP. Strangely, PSSL and XBoxOne libraries are not
|
||||
// included in the standard SRP code, but they are in tons of Unity own projects on the web, so I grabbed them from there.
|
||||
|
||||
#if defined(SHADER_API_GAMECORE)
|
||||
|
||||
#define ZERO_INITIALIZE(type, name) name = (type)0;
|
||||
#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } }
|
||||
|
||||
// Texture util abstraction
|
||||
|
||||
#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2)
|
||||
|
||||
// Texture abstraction
|
||||
|
||||
#define TEXTURE2D(textureName) Texture2D textureName
|
||||
#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName
|
||||
#define TEXTURECUBE(textureName) TextureCube textureName
|
||||
#define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName
|
||||
#define TEXTURE3D(textureName) Texture3D textureName
|
||||
|
||||
#define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName)
|
||||
#define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
#define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName)
|
||||
#define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName)
|
||||
#define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName)
|
||||
|
||||
#define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName)
|
||||
#define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
#define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName)
|
||||
#define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName)
|
||||
#define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName)
|
||||
|
||||
#define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName)
|
||||
#define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
#define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName)
|
||||
#define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName)
|
||||
|
||||
#define RW_TEXTURE2D(type, textureName) RWTexture2D<type> textureName
|
||||
#define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray<type> textureName
|
||||
#define RW_TEXTURE3D(type, textureName) RWTexture3D<type> textureName
|
||||
|
||||
#define SAMPLER(samplerName) SamplerState samplerName
|
||||
#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName
|
||||
#define ASSIGN_SAMPLER(samplerName, samplerValue) samplerName = samplerValue
|
||||
|
||||
#define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName)
|
||||
#define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName)
|
||||
#define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName)
|
||||
#define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName)
|
||||
#define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName)
|
||||
|
||||
#define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName)
|
||||
#define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName)
|
||||
#define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName)
|
||||
#define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName)
|
||||
|
||||
#define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName
|
||||
#define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName
|
||||
#define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName
|
||||
#define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName
|
||||
#define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName
|
||||
|
||||
#define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName
|
||||
#define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName
|
||||
#define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName
|
||||
#define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName
|
||||
|
||||
#define PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
|
||||
#define PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod)
|
||||
#define PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias)
|
||||
#define PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy)
|
||||
#define PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index))
|
||||
#define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod)
|
||||
#define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias)
|
||||
#define PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy)
|
||||
#define PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3)
|
||||
#define PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod)
|
||||
#define PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias)
|
||||
#define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index))
|
||||
#define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod)
|
||||
#define PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias)
|
||||
#define PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3)
|
||||
#define PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod)
|
||||
|
||||
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) PLATFORM_SAMPLE_TEXTURE2D(textureName, samplerName, coord2)
|
||||
#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) PLATFORM_SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod)
|
||||
#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) PLATFORM_SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias)
|
||||
#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) PLATFORM_SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) PLATFORM_SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy)
|
||||
#define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURECUBE(textureName, samplerName, coord3)
|
||||
#define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod)
|
||||
#define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) PLATFORM_SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias)
|
||||
#define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index)
|
||||
#define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod)
|
||||
#define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) PLATFORM_SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias)
|
||||
#define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) PLATFORM_SAMPLE_TEXTURE3D(textureName, samplerName, coord3)
|
||||
#define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) PLATFORM_SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod)
|
||||
|
||||
#define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z)
|
||||
#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w)
|
||||
#define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w)
|
||||
|
||||
#define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r
|
||||
#define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r
|
||||
|
||||
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
|
||||
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
|
||||
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
|
||||
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
|
||||
#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex)
|
||||
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
|
||||
#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0))
|
||||
#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod))
|
||||
|
||||
#define PLATFORM_SUPPORT_GATHER
|
||||
#define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2)
|
||||
#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index))
|
||||
#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3)
|
||||
#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index))
|
||||
#define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2)
|
||||
#define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2)
|
||||
#define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2)
|
||||
#define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2)
|
||||
|
||||
|
||||
#elif defined(SHADER_API_XBOXONE)
|
||||
|
||||
// Initialize arbitrary structure with zero values.
|
||||
// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0
|
||||
#define ZERO_INITIALIZE(type, name) name = (type)0;
|
||||
#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } }
|
||||
|
||||
// Texture util abstraction
|
||||
|
||||
#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2)
|
||||
|
||||
// Texture abstraction
|
||||
|
||||
#define TEXTURE2D(textureName) Texture2D textureName
|
||||
#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName
|
||||
|
||||
#define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName)
|
||||
#define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
|
||||
#define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName)
|
||||
#define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
|
||||
|
||||
#define SAMPLER(samplerName) SamplerState samplerName
|
||||
#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName
|
||||
|
||||
|
||||
|
||||
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
|
||||
#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod)
|
||||
#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias)
|
||||
#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index))
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy)
|
||||
|
||||
|
||||
#elif defined(SHADER_API_PSSL)
|
||||
|
||||
// Initialize arbitrary structure with zero values.
|
||||
// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0
|
||||
#define ZERO_INITIALIZE(type, name) name = (type)0;
|
||||
#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } }
|
||||
|
||||
// Texture util abstraction
|
||||
|
||||
#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.GetLOD(samplerName, coord2)
|
||||
|
||||
// Texture abstraction
|
||||
|
||||
#define TEXTURE2D(textureName) Texture2D textureName
|
||||
#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName
|
||||
|
||||
#define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName)
|
||||
#define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
|
||||
#define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName)
|
||||
#define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
|
||||
|
||||
#define SAMPLER(samplerName) SamplerState samplerName
|
||||
#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName
|
||||
|
||||
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
|
||||
#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod)
|
||||
#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias)
|
||||
#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index))
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy)
|
||||
|
||||
|
||||
#elif defined(SHADER_API_D3D11)
|
||||
|
||||
// Initialize arbitrary structure with zero values.
|
||||
// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0
|
||||
#define ZERO_INITIALIZE(type, name) name = (type)0;
|
||||
#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } }
|
||||
|
||||
// Texture util abstraction
|
||||
|
||||
#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2)
|
||||
|
||||
// Texture abstraction
|
||||
|
||||
#define TEXTURE2D(textureName) Texture2D textureName
|
||||
#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName
|
||||
|
||||
#define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName)
|
||||
#define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
|
||||
#define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName)
|
||||
#define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
|
||||
#define SAMPLER(samplerName) SamplerState samplerName
|
||||
#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName
|
||||
|
||||
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
|
||||
#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod)
|
||||
#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias)
|
||||
#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index))
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy)
|
||||
|
||||
#elif defined(SHADER_API_METAL)
|
||||
|
||||
// Initialize arbitrary structure with zero values.
|
||||
// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0
|
||||
#define ZERO_INITIALIZE(type, name) name = (type)0;
|
||||
#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } }
|
||||
|
||||
// Texture util abstraction
|
||||
|
||||
#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2)
|
||||
|
||||
// Texture abstraction
|
||||
|
||||
#define TEXTURE2D(textureName) Texture2D textureName
|
||||
#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName
|
||||
|
||||
#define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName
|
||||
#define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added
|
||||
|
||||
#define TEXTURE2D_HALF(textureName) Texture2D_half textureName
|
||||
#define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added
|
||||
|
||||
#define SAMPLER(samplerName) SamplerState samplerName
|
||||
#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName
|
||||
|
||||
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
|
||||
#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod)
|
||||
#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias)
|
||||
#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index))
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy)
|
||||
|
||||
#elif defined(SHADER_API_VULKAN)
|
||||
// This file assume SHADER_API_VULKAN is defined
|
||||
// TODO: This is a straight copy from D3D11.hlsl. Go through all this stuff and adjust where needed.
|
||||
|
||||
|
||||
// Initialize arbitrary structure with zero values.
|
||||
// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0
|
||||
#define ZERO_INITIALIZE(type, name) name = (type)0;
|
||||
#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } }
|
||||
|
||||
// Texture util abstraction
|
||||
|
||||
#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2)
|
||||
|
||||
// Texture abstraction
|
||||
|
||||
#define TEXTURE2D(textureName) Texture2D textureName
|
||||
#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName
|
||||
|
||||
#define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName
|
||||
#define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added
|
||||
|
||||
#define TEXTURE2D_HALF(textureName) Texture2D_half textureName
|
||||
#define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added
|
||||
|
||||
#define SAMPLER(samplerName) SamplerState samplerName
|
||||
#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName
|
||||
|
||||
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
|
||||
#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod)
|
||||
#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias)
|
||||
#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index))
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy)
|
||||
|
||||
#elif defined(SHADER_API_SWITCH)
|
||||
// This file assume SHADER_API_SWITCH is defined
|
||||
|
||||
// Initialize arbitrary structure with zero values.
|
||||
// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0
|
||||
#define ZERO_INITIALIZE(type, name) name = (type)0;
|
||||
#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } }
|
||||
|
||||
// Texture util abstraction
|
||||
|
||||
#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2)
|
||||
|
||||
// Texture abstraction
|
||||
|
||||
#define TEXTURE2D(textureName) Texture2D textureName
|
||||
#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName
|
||||
|
||||
#define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName
|
||||
#define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added
|
||||
|
||||
#define TEXTURE2D_HALF(textureName) Texture2D_half textureName
|
||||
#define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added
|
||||
|
||||
#define SAMPLER(samplerName) SamplerState samplerName
|
||||
#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName
|
||||
|
||||
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
|
||||
#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod)
|
||||
#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias)
|
||||
#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index))
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy)
|
||||
|
||||
#elif defined(SHADER_API_GLCORE)
|
||||
|
||||
// OpenGL 4.1 SM 5.0 https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html
|
||||
#if (SHADER_TARGET >= 46)
|
||||
#define OPENGL4_1_SM5 1
|
||||
#else
|
||||
#define OPENGL4_1_SM5 0
|
||||
#endif
|
||||
|
||||
// Initialize arbitrary structure with zero values.
|
||||
// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0
|
||||
#define ZERO_INITIALIZE(type, name) name = (type)0;
|
||||
#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } }
|
||||
|
||||
// Texture util abstraction
|
||||
|
||||
#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2)
|
||||
|
||||
// Texture abstraction
|
||||
|
||||
#define TEXTURE2D(textureName) Texture2D textureName
|
||||
#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName
|
||||
|
||||
#define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName)
|
||||
#define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
|
||||
#define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName)
|
||||
#define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
|
||||
|
||||
#define SAMPLER(samplerName) SamplerState samplerName
|
||||
#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName
|
||||
|
||||
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
|
||||
#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod)
|
||||
#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias)
|
||||
#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index))
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy)
|
||||
|
||||
#elif defined(SHADER_API_GLES3)
|
||||
|
||||
// GLES 3.1 + AEP shader feature https://docs.unity3d.com/Manual/SL-ShaderCompileTargets.html
|
||||
#if (SHADER_TARGET >= 40)
|
||||
#define GLES3_1_AEP 1
|
||||
#else
|
||||
#define GLES3_1_AEP 0
|
||||
#endif
|
||||
|
||||
// Initialize arbitrary structure with zero values.
|
||||
// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0
|
||||
#define ZERO_INITIALIZE(type, name) name = (type)0;
|
||||
#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } }
|
||||
|
||||
// Texture util abstraction
|
||||
|
||||
#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) textureName.CalculateLevelOfDetail(samplerName, coord2)
|
||||
|
||||
// Texture abstraction
|
||||
|
||||
#define TEXTURE2D(textureName) Texture2D textureName
|
||||
#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName
|
||||
|
||||
#define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName
|
||||
#define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray textureName // no support to _float on Array, it's being added
|
||||
|
||||
#define TEXTURE2D_HALF(textureName) Texture2D_half textureName
|
||||
#define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray textureName // no support to _float on Array, it's being added
|
||||
|
||||
#define SAMPLER(samplerName) SamplerState samplerName
|
||||
#define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName
|
||||
|
||||
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
|
||||
#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod)
|
||||
#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias)
|
||||
#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) textureName.SampleGrad(samplerName, coord2, ddx, ddy)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index))
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy)
|
||||
|
||||
#elif defined(SHADER_API_GLES)
|
||||
|
||||
|
||||
#define uint int
|
||||
|
||||
#define rcp(x) 1.0 / (x)
|
||||
#define ddx_fine ddx
|
||||
#define ddy_fine ddy
|
||||
#define asfloat
|
||||
#define asuint(x) asint(x)
|
||||
#define f32tof16
|
||||
#define f16tof32
|
||||
|
||||
#define ERROR_ON_UNSUPPORTED_FUNCTION(funcName) #error #funcName is not supported on GLES 2.0
|
||||
|
||||
// Initialize arbitrary structure with zero values.
|
||||
// Do not exist on some platform, in this case we need to have a standard name that call a function that will initialize all parameters to 0
|
||||
#define ZERO_INITIALIZE(type, name) name = (type)0;
|
||||
#define ZERO_INITIALIZE_ARRAY(type, name, arraySize) { for (int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { name[arrayIndex] = (type)0; } }
|
||||
|
||||
|
||||
// Texture util abstraction
|
||||
|
||||
#define CALCULATE_TEXTURE2D_LOD(textureName, samplerName, coord2) #error calculate Level of Detail not supported in GLES2
|
||||
|
||||
// Texture abstraction
|
||||
|
||||
#define TEXTURE2D(textureName) sampler2D textureName
|
||||
#define TEXTURE2D_ARRAY(textureName) samplerCUBE textureName // No support to texture2DArray
|
||||
#define TEXTURECUBE(textureName) samplerCUBE textureName
|
||||
#define TEXTURECUBE_ARRAY(textureName) samplerCUBE textureName // No supoport to textureCubeArray and can't emulate with texture2DArray
|
||||
#define TEXTURE3D(textureName) sampler3D textureName
|
||||
|
||||
#define TEXTURE2D_FLOAT(textureName) sampler2D_float textureName
|
||||
#define TEXTURECUBE_FLOAT(textureName) samplerCUBE_float textureName
|
||||
#define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURECUBE_FLOAT(textureName) // No support to texture2DArray
|
||||
|
||||
#define TEXTURE2D_HALF(textureName) sampler2D_half textureName
|
||||
#define TEXTURE2D_ARRAY_HALF(textureName) TEXTURECUBE_HALF(textureName) // No support to texture2DArray
|
||||
|
||||
#define SAMPLER(samplerName)
|
||||
#define SAMPLER_CMP(samplerName)
|
||||
|
||||
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) tex2D(textureName, coord2)
|
||||
|
||||
#if (SHADER_TARGET >= 30)
|
||||
#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) tex2Dlod(textureName, float4(coord2, 0, lod))
|
||||
#else
|
||||
// No lod support. Very poor approximation with bias.
|
||||
#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, lod)
|
||||
#endif
|
||||
|
||||
#define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) tex2Dbias(textureName, float4(coord2, 0, bias))
|
||||
#define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, ddx, ddy) SAMPLE_TEXTURE2D(textureName, samplerName, coord2)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_LOD)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_BIAS)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) ERROR_ON_UNSUPPORTED_FUNCTION(SAMPLE_TEXTURE2D_ARRAY_GRAD)
|
||||
|
||||
|
||||
#else
|
||||
#error unsupported shader api
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
// default flow control attributes
|
||||
#ifndef UNITY_BRANCH
|
||||
# define UNITY_BRANCH
|
||||
#endif
|
||||
#ifndef UNITY_FLATTEN
|
||||
# define UNITY_FLATTEN
|
||||
#endif
|
||||
#ifndef UNITY_UNROLL
|
||||
# define UNITY_UNROLL
|
||||
#endif
|
||||
#ifndef UNITY_UNROLLX
|
||||
# define UNITY_UNROLLX(_x)
|
||||
#endif
|
||||
#ifndef UNITY_LOOP
|
||||
# define UNITY_LOOP
|
||||
#endif
|
||||
|
||||
|
@@ -0,0 +1,333 @@
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "FORWARD"
|
||||
Tags { "LightMode" = "ForwardBase" }
|
||||
%FORWARDBASEBLEND%
|
||||
|
||||
CGPROGRAM
|
||||
// compile directives
|
||||
%PRAGMAS%
|
||||
|
||||
#pragma target %SHADERTARGET%
|
||||
#pragma multi_compile_instancing
|
||||
#pragma multi_compile_local __ _ALPHATEST_ON
|
||||
#pragma multi_compile_fog
|
||||
#pragma multi_compile_fwdbase
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
#define _PASSFORWARD 1
|
||||
|
||||
#include "UnityShaderVariables.cginc"
|
||||
#include "UnityShaderUtilities.cginc"
|
||||
// -------- variant for: <when no other keywords are defined>
|
||||
|
||||
%DEFINES%
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#if _NOMINDIELETRIC
|
||||
// for Standard
|
||||
#ifdef unity_ColorSpaceDielectricSpec
|
||||
#undef unity_ColorSpaceDielectricSpec
|
||||
#endif
|
||||
#define unity_ColorSpaceDielectricSpec half4(0,0,0,1)
|
||||
#endif
|
||||
#include "Lighting.cginc"
|
||||
#include "UnityPBSLighting.cginc"
|
||||
#include "AutoLight.cginc"
|
||||
|
||||
|
||||
|
||||
|
||||
#if _MICROTERRAIN && !_TERRAINBLENDABLESHADER
|
||||
#define UNITY_ASSUME_UNIFORM_SCALING
|
||||
#define UNITY_DONT_INSTANCE_OBJECT_MATRICES
|
||||
#define UNITY_INSTANCED_LOD_FADE
|
||||
#else
|
||||
#define UNITY_INSTANCED_LOD_FADE
|
||||
#define UNITY_INSTANCED_SH
|
||||
#define UNITY_INSTANCED_LIGHTMAPSTS
|
||||
#endif
|
||||
|
||||
|
||||
// data across stages, stripped like the above.
|
||||
struct VertexToPixel
|
||||
{
|
||||
UNITY_POSITION(pos);
|
||||
float3 worldPos : TEXCOORD0;
|
||||
float3 worldNormal : TEXCOORD1;
|
||||
float4 worldTangent : TEXCOORD2;
|
||||
%UV0% float4 texcoord0 : TEXCCOORD3;
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
%UV1% float4 texcoord1 : TEXCCOORD4;
|
||||
%UV2% float4 texcoord2 : TEXCCOORD5;
|
||||
#endif
|
||||
%UV3% float4 texcoord3 : TEXCCOORD6;
|
||||
%SCREENPOS% float4 screenPos : TEXCOORD7;
|
||||
%VERTEXCOLOR% float4 vertexColor : COLOR;
|
||||
float4 lmap : TEXCOORD8;
|
||||
#if UNITY_SHOULD_SAMPLE_SH
|
||||
half3 sh : TEXCOORD9; // SH
|
||||
#endif
|
||||
#ifdef LIGHTMAP_ON
|
||||
UNITY_LIGHTING_COORDS(10,11)
|
||||
UNITY_FOG_COORDS(12)
|
||||
#else
|
||||
UNITY_FOG_COORDS(10)
|
||||
UNITY_SHADOW_COORDS(11)
|
||||
#endif
|
||||
|
||||
%EXTRAV2F0% float4 extraV2F0 : TEXCOORD13;
|
||||
%EXTRAV2F1% float4 extraV2F1 : TEXCOORD14;
|
||||
%EXTRAV2F2% float4 extraV2F2 : TEXCOORD15;
|
||||
%EXTRAV2F3% float4 extraV2F3 : TEXCOORD16;
|
||||
%EXTRAV2F4% float4 extraV2F4 : TEXCOORD17;
|
||||
%EXTRAV2F5% float4 extraV2F5 : TEXCOORD18;
|
||||
%EXTRAV2F6% float4 extraV2F6 : TEXCOORD19;
|
||||
%EXTRAV2F7% float4 extraV2F7 : TEXCOORD20;
|
||||
|
||||
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
%TEMPLATE_SHARED%
|
||||
|
||||
%CBUFFER%
|
||||
|
||||
%CODE%
|
||||
|
||||
%SHADERDESC%
|
||||
|
||||
// vertex shader
|
||||
VertexToPixel Vert (VertexData v)
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
VertexToPixel o;
|
||||
UNITY_INITIALIZE_OUTPUT(VertexToPixel,o);
|
||||
UNITY_TRANSFER_INSTANCE_ID(v,o);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
#if !_TESSELLATION_ON
|
||||
ChainModifyVertex(v, o);
|
||||
#endif
|
||||
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
%UV0% o.texcoord0 = v.texcoord0;
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
%UV1% o.texcoord1 = v.texcoord1;
|
||||
%UV2% o.texcoord2 = v.texcoord2;
|
||||
#endif
|
||||
%UV3% o.texcoord3 = v.texcoord3;
|
||||
%VERTEXCOLOR% o.vertexColor = v.vertexColor;
|
||||
%SCREENPOS% o.screenPos = ComputeScreenPos(o.pos);
|
||||
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
|
||||
o.worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
o.worldTangent.xyz = UnityObjectToWorldDir(v.tangent.xyz);
|
||||
fixed tangentSign = v.tangent.w * unity_WorldTransformParams.w;
|
||||
o.worldTangent.w = tangentSign;
|
||||
#endif
|
||||
|
||||
// MS Only
|
||||
ApplyTerrainTangent(o);
|
||||
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
float2 uv1 = v.texcoord1.xy;
|
||||
float2 uv2 = v.texcoord2.xy;
|
||||
#else
|
||||
float2 uv1 = v.texcoord0.xy;
|
||||
float2 uv2 = uv1;
|
||||
#endif
|
||||
|
||||
#ifdef DYNAMICLIGHTMAP_ON
|
||||
o.lmap.zw = uv2 * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
|
||||
#endif
|
||||
#ifdef LIGHTMAP_ON
|
||||
o.lmap.xy = uv1 * unity_LightmapST.xy + unity_LightmapST.zw;
|
||||
#endif
|
||||
|
||||
// SH/ambient and vertex lights
|
||||
#ifndef LIGHTMAP_ON
|
||||
#if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL
|
||||
o.sh = 0;
|
||||
// Approximated illumination from non-important point lights
|
||||
#ifdef VERTEXLIGHT_ON
|
||||
o.sh += Shade4PointLights (
|
||||
unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
|
||||
unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
|
||||
unity_4LightAtten0, o.worldPos, o.worldNormal);
|
||||
#endif
|
||||
o.sh = ShadeSHPerVertex (o.worldNormal, o.sh);
|
||||
#endif
|
||||
#endif // !LIGHTMAP_ON
|
||||
|
||||
UNITY_TRANSFER_LIGHTING(o, uv1.xy); // pass shadow and, possibly, light cookie coordinates to pixel shader
|
||||
#ifdef FOG_COMBINED_WITH_TSPACE
|
||||
UNITY_TRANSFER_FOG_COMBINED_WITH_TSPACE(o,o.pos); // pass fog coordinates to pixel shader
|
||||
#elif defined (FOG_COMBINED_WITH_WORLD_POS)
|
||||
UNITY_TRANSFER_FOG_COMBINED_WITH_WORLD_POS(o,o.pos); // pass fog coordinates to pixel shader
|
||||
#else
|
||||
UNITY_TRANSFER_FOG(o,o.pos); // pass fog coordinates to pixel shader
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
%TESSELLATION%
|
||||
|
||||
// fragment shader
|
||||
fixed4 Frag (VertexToPixel IN) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(IN);
|
||||
// prepare and unpack data
|
||||
#ifdef FOG_COMBINED_WITH_TSPACE
|
||||
UNITY_EXTRACT_FOG_FROM_TSPACE(IN);
|
||||
#elif defined (FOG_COMBINED_WITH_WORLD_POS)
|
||||
UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN);
|
||||
#else
|
||||
UNITY_EXTRACT_FOG(IN);
|
||||
#endif
|
||||
|
||||
ShaderData d = CreateShaderData(IN);
|
||||
|
||||
Surface l = (Surface)0;
|
||||
|
||||
l.Albedo = half3(0.5, 0.5, 0.5);
|
||||
l.Normal = float3(0,0,1);
|
||||
l.Occlusion = 1;
|
||||
l.Alpha = 1;
|
||||
|
||||
ChainSurfaceFunction(l, d);
|
||||
|
||||
|
||||
#ifndef USING_DIRECTIONAL_LIGHT
|
||||
fixed3 lightDir = normalize(UnityWorldSpaceLightDir(d.worldSpacePosition));
|
||||
#else
|
||||
fixed3 lightDir = _WorldSpaceLightPos0.xyz;
|
||||
#endif
|
||||
|
||||
// compute lighting & shadowing factor
|
||||
UNITY_LIGHT_ATTENUATION(atten, IN, d.worldSpacePosition)
|
||||
|
||||
|
||||
|
||||
#if _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC
|
||||
#ifdef UNITY_COMPILER_HLSL
|
||||
SurfaceOutputStandardSpecular o = (SurfaceOutputStandardSpecular)0;
|
||||
#else
|
||||
SurfaceOutputStandardSpecular o;
|
||||
#endif
|
||||
o.Specular = l.Specular;
|
||||
#elif _BDRFLAMBERT || _BDRF3
|
||||
#ifdef UNITY_COMPILER_HLSL
|
||||
SurfaceOutput o = (SurfaceOutput)0;
|
||||
#else
|
||||
SurfaceOutput o;
|
||||
#endif
|
||||
#else
|
||||
#ifdef UNITY_COMPILER_HLSL
|
||||
SurfaceOutputStandard o = (SurfaceOutputStandard)0;
|
||||
#else
|
||||
SurfaceOutputStandard o;
|
||||
#endif
|
||||
o.Metallic = l.Metallic;
|
||||
#endif
|
||||
|
||||
o.Albedo = l.Albedo;
|
||||
o.Emission = l.Emission;
|
||||
o.Alpha = l.Alpha;
|
||||
o.Normal = normalize(TangentToWorldSpace(d, l.Normal));
|
||||
|
||||
#if _BDRFLAMBERT || _BDRF3
|
||||
o.Specular = l.Specular;
|
||||
o.Gloss = l.Smoothness;
|
||||
#elif _SPECULARFROMMETALLIC
|
||||
o.Occlusion = l.Occlusion;
|
||||
o.Smoothness = l.Smoothness;
|
||||
o.Albedo = MicroSplatDiffuseAndSpecularFromMetallic(l.Albedo, l.Metallic, o.Specular, o.Smoothness);
|
||||
o.Smoothness = 1-o.Smoothness;
|
||||
#elif _USESPECULARWORKFLOW
|
||||
o.Occlusion = l.Occlusion;
|
||||
o.Smoothness = l.Smoothness;
|
||||
o.Specular = l.Specular;
|
||||
#else
|
||||
o.Smoothness = l.Smoothness;
|
||||
o.Metallic = l.Metallic;
|
||||
o.Occlusion = l.Occlusion;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !_UNLIT
|
||||
fixed4 c = 0;
|
||||
// Setup lighting environment
|
||||
UnityGI gi;
|
||||
UNITY_INITIALIZE_OUTPUT(UnityGI, gi);
|
||||
gi.indirect.diffuse = 0;
|
||||
gi.indirect.specular = 0;
|
||||
gi.light.color = _LightColor0.rgb;
|
||||
gi.light.dir = lightDir;
|
||||
// Call GI (lightmaps/SH/reflections) lighting function
|
||||
UnityGIInput giInput;
|
||||
UNITY_INITIALIZE_OUTPUT(UnityGIInput, giInput);
|
||||
giInput.light = gi.light;
|
||||
giInput.worldPos = d.worldSpacePosition;
|
||||
giInput.worldViewDir = d.worldSpaceViewDir;
|
||||
giInput.atten = atten;
|
||||
#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)
|
||||
giInput.lightmapUV = IN.lmap;
|
||||
#else
|
||||
giInput.lightmapUV = 0;
|
||||
#endif
|
||||
#if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL
|
||||
giInput.ambient = IN.sh;
|
||||
#else
|
||||
giInput.ambient.rgb = 0.0;
|
||||
#endif
|
||||
giInput.probeHDR[0] = unity_SpecCube0_HDR;
|
||||
giInput.probeHDR[1] = unity_SpecCube1_HDR;
|
||||
#if defined(UNITY_SPECCUBE_BLENDING) || defined(UNITY_SPECCUBE_BOX_PROJECTION)
|
||||
giInput.boxMin[0] = unity_SpecCube0_BoxMin; // .w holds lerp value for blending
|
||||
#endif
|
||||
#ifdef UNITY_SPECCUBE_BOX_PROJECTION
|
||||
giInput.boxMax[0] = unity_SpecCube0_BoxMax;
|
||||
giInput.probePosition[0] = unity_SpecCube0_ProbePosition;
|
||||
giInput.boxMax[1] = unity_SpecCube1_BoxMax;
|
||||
giInput.boxMin[1] = unity_SpecCube1_BoxMin;
|
||||
giInput.probePosition[1] = unity_SpecCube1_ProbePosition;
|
||||
#endif
|
||||
|
||||
#if _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC
|
||||
LightingStandardSpecular_GI(o, giInput, gi);
|
||||
c += LightingStandardSpecular (o, d.worldSpaceViewDir, gi);
|
||||
#elif _BDRFLAMBERT
|
||||
LightingLambert_GI(o, giInput, gi);
|
||||
c += LightingLambert (o, gi);
|
||||
#elif _BDRF3
|
||||
LightingBlinnPhong_GI(o, giInput, gi);
|
||||
c += LightingBlinnPhong (o, d.worldSpaceViewDir, gi);
|
||||
#else
|
||||
LightingStandard_GI(o, giInput, gi);
|
||||
c += LightingStandard (o, d.worldSpaceViewDir, gi);
|
||||
#endif
|
||||
|
||||
c.rgb += o.Emission;
|
||||
|
||||
UNITY_APPLY_FOG(_unity_fogCoord, c); // apply fog
|
||||
#else
|
||||
fixed4 c = fixed4(o.Albedo.rgb, o.Alpha);
|
||||
UNITY_APPLY_FOG(_unity_fogCoord, c); // apply fog
|
||||
#endif
|
||||
#if !_ALPHABLEND_ON
|
||||
UNITY_OPAQUE_ALPHA(c.a);
|
||||
#endif
|
||||
|
||||
ChainFinalColorForward(l, d, c);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
@@ -0,0 +1,266 @@
|
||||
|
||||
// ---- forward rendering additive lights pass:
|
||||
Pass
|
||||
{
|
||||
Name "FORWARD"
|
||||
Tags { "LightMode" = "ForwardAdd" }
|
||||
ZWrite Off Blend One One
|
||||
%FORWARDADDBLEND%
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
%PRAGMAS%
|
||||
|
||||
// compile directives
|
||||
#pragma target %SHADERTARGET%
|
||||
#pragma multi_compile_instancing
|
||||
#pragma multi_compile_fog
|
||||
#pragma multi_compile_local __ _ALPHATEST_ON
|
||||
#pragma multi_compile_fwdadd_fullshadows
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
|
||||
#include "UnityShaderVariables.cginc"
|
||||
#include "UnityShaderUtilities.cginc"
|
||||
|
||||
#define _PASSFORWARD 1
|
||||
|
||||
%DEFINES%
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#if _NOMINDIELETRIC
|
||||
// for Standard
|
||||
#ifdef unity_ColorSpaceDielectricSpec
|
||||
#undef unity_ColorSpaceDielectricSpec
|
||||
#endif
|
||||
#define unity_ColorSpaceDielectricSpec half4(0,0,0,1)
|
||||
#endif
|
||||
|
||||
#include "Lighting.cginc"
|
||||
#include "UnityPBSLighting.cginc"
|
||||
#include "AutoLight.cginc"
|
||||
|
||||
|
||||
|
||||
#if _MICROTERRAIN && !_TERRAINBLENDABLESHADER
|
||||
#define UNITY_ASSUME_UNIFORM_SCALING
|
||||
#define UNITY_DONT_INSTANCE_OBJECT_MATRICES
|
||||
#define UNITY_INSTANCED_LOD_FADE
|
||||
#else
|
||||
#define UNITY_INSTANCED_LOD_FADE
|
||||
#define UNITY_INSTANCED_SH
|
||||
#define UNITY_INSTANCED_LIGHTMAPSTS
|
||||
#endif
|
||||
|
||||
// data across stages, stripped like the above.
|
||||
struct VertexToPixel
|
||||
{
|
||||
UNITY_POSITION(pos); // must be named pos because Unity does stupid macro stuff
|
||||
float3 worldPos : TEXCOORD0;
|
||||
float3 worldNormal : TEXCOORD1;
|
||||
float4 worldTangent : TEXCOORD2;
|
||||
%UV0% float4 texcoord0 : TEXCCOORD3;
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
%UV1% float4 texcoord1 : TEXCCOORD4;
|
||||
%UV2% float4 texcoord2 : TEXCCOORD5;
|
||||
#endif
|
||||
%UV3% float4 texcoord3 : TEXCCOORD6;
|
||||
%SCREENPOS% float4 screenPos : TEXCOORD7;
|
||||
%VERTEXCOLOR% float4 vertexColor : COLOR;
|
||||
|
||||
UNITY_LIGHTING_COORDS(8,9)
|
||||
UNITY_FOG_COORDS(10)
|
||||
|
||||
%EXTRAV2F0% float4 extraV2F0 : TEXCOORD11;
|
||||
%EXTRAV2F1% float4 extraV2F1 : TEXCOORD12;
|
||||
%EXTRAV2F2% float4 extraV2F2 : TEXCOORD13;
|
||||
%EXTRAV2F3% float4 extraV2F3 : TEXCOORD14;
|
||||
%EXTRAV2F4% float4 extraV2F4 : TEXCOORD15;
|
||||
%EXTRAV2F5% float4 extraV2F5 : TEXCOORD16;
|
||||
%EXTRAV2F6% float4 extraV2F6 : TEXCOORD17;
|
||||
%EXTRAV2F7% float4 extraV2F7 : TEXCOORD18;
|
||||
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
|
||||
};
|
||||
|
||||
%TEMPLATE_SHARED%
|
||||
|
||||
%CBUFFER%
|
||||
|
||||
%CODE%
|
||||
|
||||
%SHADERDESC%
|
||||
|
||||
// vertex shader
|
||||
VertexToPixel Vert (VertexData v)
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
VertexToPixel o;
|
||||
UNITY_INITIALIZE_OUTPUT(VertexToPixel,o);
|
||||
UNITY_TRANSFER_INSTANCE_ID(v,o);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
#if !_TESSELLATION_ON
|
||||
ChainModifyVertex(v, o);
|
||||
#endif
|
||||
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
%UV0% o.texcoord0 = v.texcoord0;
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
%UV1% o.texcoord1 = v.texcoord1;
|
||||
%UV2% o.texcoord2 = v.texcoord2;
|
||||
#endif
|
||||
%UV3% o.texcoord3 = v.texcoord3;
|
||||
%VERTEXCOLOR% o.vertexColor = v.vertexColor;
|
||||
%SCREENPOS% o.screenPos = ComputeScreenPos(o.pos);
|
||||
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
|
||||
o.worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
o.worldTangent.xyz = UnityObjectToWorldDir(v.tangent.xyz);
|
||||
fixed tangentSign = v.tangent.w * unity_WorldTransformParams.w;
|
||||
o.worldTangent.w = tangentSign;
|
||||
#endif
|
||||
|
||||
// MS Only
|
||||
ApplyTerrainTangent(o);
|
||||
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
float2 uv1 = v.texcoord1.xy;
|
||||
float2 uv2 = v.texcoord2.xy;
|
||||
#else
|
||||
float2 uv1 = v.texcoord0.xy;
|
||||
float2 uv2 = uv1;
|
||||
#endif
|
||||
|
||||
UNITY_TRANSFER_LIGHTING(o,uv1); // pass shadow and, possibly, light cookie coordinates to pixel shader
|
||||
UNITY_TRANSFER_FOG(o,o.pos); // pass fog coordinates to pixel shader
|
||||
return o;
|
||||
}
|
||||
|
||||
%TESSELLATION%
|
||||
|
||||
// fragment shader
|
||||
fixed4 Frag (VertexToPixel IN) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(IN);
|
||||
// prepare and unpack data
|
||||
|
||||
#ifdef FOG_COMBINED_WITH_TSPACE
|
||||
UNITY_EXTRACT_FOG_FROM_TSPACE(IN);
|
||||
#elif defined (FOG_COMBINED_WITH_WORLD_POS)
|
||||
UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN);
|
||||
#else
|
||||
UNITY_EXTRACT_FOG(IN);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
ShaderData d = CreateShaderData(IN);
|
||||
|
||||
Surface l = (Surface)0;
|
||||
|
||||
l.Albedo = half3(0.5, 0.5, 0.5);
|
||||
l.Normal = float3(0,0,1);
|
||||
l.Occlusion = 1;
|
||||
l.Alpha = 1;
|
||||
|
||||
ChainSurfaceFunction(l, d);
|
||||
|
||||
|
||||
#ifndef USING_DIRECTIONAL_LIGHT
|
||||
fixed3 lightDir = normalize(UnityWorldSpaceLightDir(d.worldSpacePosition));
|
||||
#else
|
||||
fixed3 lightDir = _WorldSpaceLightPos0.xyz;
|
||||
#endif
|
||||
float3 worldViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition));
|
||||
|
||||
#if _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC
|
||||
#ifdef UNITY_COMPILER_HLSL
|
||||
SurfaceOutputStandardSpecular o = (SurfaceOutputStandardSpecular)0;
|
||||
#else
|
||||
SurfaceOutputStandardSpecular o;
|
||||
#endif
|
||||
o.Specular = l.Specular;
|
||||
#elif _BDRFLAMBERT || _BDRF3
|
||||
#ifdef UNITY_COMPILER_HLSL
|
||||
SurfaceOutput o = (SurfaceOutput)0;
|
||||
#else
|
||||
SurfaceOutput o;
|
||||
#endif
|
||||
#else
|
||||
#ifdef UNITY_COMPILER_HLSL
|
||||
SurfaceOutputStandard o = (SurfaceOutputStandard)0;
|
||||
#else
|
||||
SurfaceOutputStandard o;
|
||||
#endif
|
||||
o.Metallic = l.Metallic;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
o.Albedo = l.Albedo;
|
||||
o.Emission = l.Emission;
|
||||
o.Alpha = l.Alpha;
|
||||
o.Normal = normalize(TangentToWorldSpace(d, l.Normal));
|
||||
|
||||
#if _BDRFLAMBERT || _BDRF3
|
||||
o.Specular = l.Specular;
|
||||
o.Gloss = l.Smoothness;
|
||||
#elif _SPECULARFROMMETALLIC
|
||||
o.Occlusion = l.Occlusion;
|
||||
o.Smoothness = l.Smoothness;
|
||||
o.Albedo = MicroSplatDiffuseAndSpecularFromMetallic(l.Albedo, l.Metallic, o.Specular, o.Smoothness);
|
||||
o.Smoothness = 1-o.Smoothness;
|
||||
#elif _USESPECULARWORKFLOW
|
||||
o.Occlusion = l.Occlusion;
|
||||
o.Smoothness = l.Smoothness;
|
||||
o.Specular = l.Specular;
|
||||
#else
|
||||
o.Smoothness = l.Smoothness;
|
||||
o.Metallic = l.Metallic;
|
||||
o.Occlusion = l.Occlusion;
|
||||
#endif
|
||||
|
||||
|
||||
UNITY_LIGHT_ATTENUATION(atten, IN, d.worldSpacePosition)
|
||||
half4 c = 0;
|
||||
|
||||
// Setup lighting environment
|
||||
UnityGI gi;
|
||||
UNITY_INITIALIZE_OUTPUT(UnityGI, gi);
|
||||
gi.indirect.diffuse = 0;
|
||||
gi.indirect.specular = 0;
|
||||
gi.light.color = _LightColor0.rgb;
|
||||
gi.light.dir = lightDir;
|
||||
gi.light.color *= atten;
|
||||
|
||||
#if _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC
|
||||
c += LightingStandardSpecular (o, worldViewDir, gi);
|
||||
#elif _BDRFLAMBERT
|
||||
c += LightingLambert(o, gi);
|
||||
c.a = 0;
|
||||
#elif _BDRF3
|
||||
c += LightingBlinnPhong (o, worldViewDir, gi);
|
||||
#else
|
||||
c += LightingStandard (o, worldViewDir, gi);
|
||||
#endif
|
||||
|
||||
ChainFinalColorForward(l, d, c);
|
||||
|
||||
UNITY_APPLY_FOG(_unity_fogCoord, c); // apply fog
|
||||
|
||||
#if !_ALPHABLEND_ON
|
||||
UNITY_OPAQUE_ALPHA(c.a);
|
||||
#endif
|
||||
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
}
|
@@ -0,0 +1,352 @@
|
||||
|
||||
// ---- deferred shading pass:
|
||||
Pass
|
||||
{
|
||||
Name "DEFERRED"
|
||||
Tags { "LightMode" = "Deferred" }
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
%PRAGMAS%
|
||||
|
||||
// compile directives
|
||||
#pragma target %SHADERTARGET%
|
||||
#pragma multi_compile_instancing
|
||||
#pragma exclude_renderers nomrt
|
||||
#pragma multi_compile_local __ _ALPHATEST_ON
|
||||
#pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
|
||||
#pragma multi_compile_prepassfinal
|
||||
#include "HLSLSupport.cginc"
|
||||
#include "UnityShaderVariables.cginc"
|
||||
#include "UnityShaderUtilities.cginc"
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#define _PASSGBUFFER 1
|
||||
|
||||
%DEFINES%
|
||||
|
||||
#if _NOMINDIELETRIC
|
||||
// for Standard
|
||||
#ifdef unity_ColorSpaceDielectricSpec
|
||||
#undef unity_ColorSpaceDielectricSpec
|
||||
#endif
|
||||
#define unity_ColorSpaceDielectricSpec half4(0,0,0,1)
|
||||
#endif
|
||||
|
||||
#include "Lighting.cginc"
|
||||
#include "UnityPBSLighting.cginc"
|
||||
|
||||
#if _MICROTERRAIN && !_TERRAINBLENDABLESHADER
|
||||
#define UNITY_ASSUME_UNIFORM_SCALING
|
||||
#define UNITY_DONT_INSTANCE_OBJECT_MATRICES
|
||||
#define UNITY_INSTANCED_LOD_FADE
|
||||
#else
|
||||
#define UNITY_INSTANCED_LOD_FADE
|
||||
#define UNITY_INSTANCED_SH
|
||||
#define UNITY_INSTANCED_LIGHTMAPSTS
|
||||
#endif
|
||||
|
||||
|
||||
// data across stages, stripped like the above.
|
||||
struct VertexToPixel
|
||||
{
|
||||
UNITY_POSITION(pos); // must be named pos because Unity does stupid macro stuff
|
||||
float3 worldPos : TEXCOORD0;
|
||||
float3 worldNormal : TEXCOORD1;
|
||||
float4 worldTangent : TEXCOORD2;
|
||||
%UV0% float4 texcoord0 : TEXCCOORD3;
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
%UV1% float4 texcoord1 : TEXCCOORD4;
|
||||
%UV2% float4 texcoord2 : TEXCCOORD5;
|
||||
#endif
|
||||
%UV3% float4 texcoord3 : TEXCCOORD6;
|
||||
%SCREENPOS% float4 screenPos : TEXCOORD7;
|
||||
%VERTEXCOLOR% float4 vertexColor : COLOR;
|
||||
|
||||
#ifndef DIRLIGHTMAP_OFF
|
||||
float3 viewDir : TEXCOORD8;
|
||||
#endif
|
||||
float4 lmap : TEXCOORD9;
|
||||
#ifndef LIGHTMAP_ON
|
||||
#if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL
|
||||
half3 sh : TEXCOORD10; // SH
|
||||
#endif
|
||||
#else
|
||||
#ifdef DIRLIGHTMAP_OFF
|
||||
float4 lmapFadePos : TEXCOORD11;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
%EXTRAV2F0% float4 extraV2F0 : TEXCOORD12;
|
||||
%EXTRAV2F1% float4 extraV2F1 : TEXCOORD13;
|
||||
%EXTRAV2F2% float4 extraV2F2 : TEXCOORD14;
|
||||
%EXTRAV2F3% float4 extraV2F3 : TEXCOORD15;
|
||||
%EXTRAV2F4% float4 extraV2F4 : TEXCOORD16;
|
||||
%EXTRAV2F5% float4 extraV2F5 : TEXCOORD17;
|
||||
%EXTRAV2F6% float4 extraV2F6 : TEXCOORD18;
|
||||
%EXTRAV2F7% float4 extraV2F7 : TEXCOORD19;
|
||||
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
%TEMPLATE_SHARED%
|
||||
|
||||
%CBUFFER%
|
||||
|
||||
%CODE%
|
||||
|
||||
%SHADERDESC%
|
||||
|
||||
|
||||
// vertex shader
|
||||
VertexToPixel Vert (VertexData v)
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
VertexToPixel o;
|
||||
UNITY_INITIALIZE_OUTPUT(VertexToPixel,o);
|
||||
UNITY_TRANSFER_INSTANCE_ID(v,o);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
#if !_TESSELLATION_ON
|
||||
ChainModifyVertex(v, o);
|
||||
#endif
|
||||
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
%UV0% o.texcoord0 = v.texcoord0;
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
%UV1% o.texcoord1 = v.texcoord1;
|
||||
%UV2% o.texcoord2 = v.texcoord2;
|
||||
#endif
|
||||
%UV3% o.texcoord3 = v.texcoord3;
|
||||
%VERTEXCOLOR% o.vertexColor = v.vertexColor;
|
||||
%SCREENPOS% o.screenPos = ComputeScreenPos(o.pos);
|
||||
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
|
||||
o.worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
o.worldTangent.xyz = UnityObjectToWorldDir(v.tangent.xyz);
|
||||
fixed tangentSign = v.tangent.w * unity_WorldTransformParams.w;
|
||||
float3 worldBinormal = cross(o.worldNormal, o.worldTangent.xyz) * tangentSign;
|
||||
o.worldTangent.w = tangentSign;
|
||||
#else
|
||||
// MS Only
|
||||
ApplyTerrainTangent(o);
|
||||
float3 worldBinormal = cross(o.worldNormal, o.worldTangent.xyz) * unity_WorldTransformParams.w;
|
||||
#endif
|
||||
|
||||
float3 viewDirForLight = UnityWorldSpaceViewDir(o.worldPos);
|
||||
#ifndef DIRLIGHTMAP_OFF
|
||||
o.viewDir.x = dot(viewDirForLight, o.worldTangent.xyz);
|
||||
o.viewDir.y = dot(viewDirForLight, worldBinormal);
|
||||
o.viewDir.z = dot(viewDirForLight, o.worldNormal);
|
||||
#endif
|
||||
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
float2 uv1 = v.texcoord1.xy;
|
||||
float2 uv2 = v.texcoord2.xy;
|
||||
#else
|
||||
float2 uv1 = v.texcoord0.xy;
|
||||
float2 uv2 = uv1;
|
||||
#endif
|
||||
|
||||
#ifdef DYNAMICLIGHTMAP_ON
|
||||
o.lmap.zw = uv2 * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
|
||||
#else
|
||||
o.lmap.zw = 0;
|
||||
#endif
|
||||
#ifdef LIGHTMAP_ON
|
||||
o.lmap.xy = uv1 * unity_LightmapST.xy + unity_LightmapST.zw;
|
||||
#ifdef DIRLIGHTMAP_OFF
|
||||
o.lmapFadePos.xyz = (mul(unity_ObjectToWorld, v.vertex).xyz - unity_ShadowFadeCenterAndType.xyz) * unity_ShadowFadeCenterAndType.w;
|
||||
o.lmapFadePos.w = (-UnityObjectToViewPos(v.vertex).z) * (1.0 - unity_ShadowFadeCenterAndType.w);
|
||||
#endif
|
||||
#else
|
||||
o.lmap.xy = 0;
|
||||
#if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL
|
||||
o.sh = 0;
|
||||
o.sh = ShadeSHPerVertex (o.worldNormal, o.sh);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
%TESSELLATION%
|
||||
|
||||
#ifdef LIGHTMAP_ON
|
||||
float4 unity_LightmapFade;
|
||||
#endif
|
||||
fixed4 unity_Ambient;
|
||||
|
||||
|
||||
|
||||
// fragment shader
|
||||
void Frag (VertexToPixel IN,
|
||||
out half4 outGBuffer0 : SV_Target0,
|
||||
out half4 outGBuffer1 : SV_Target1,
|
||||
out half4 outGBuffer2 : SV_Target2,
|
||||
out half4 outEmission : SV_Target3
|
||||
#if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4)
|
||||
, out half4 outShadowMask : SV_Target4
|
||||
#endif
|
||||
)
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(IN);
|
||||
// prepare and unpack data
|
||||
|
||||
#ifdef FOG_COMBINED_WITH_TSPACE
|
||||
UNITY_EXTRACT_FOG_FROM_TSPACE(IN);
|
||||
#elif defined (FOG_COMBINED_WITH_WORLD_POS)
|
||||
UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN);
|
||||
#else
|
||||
UNITY_EXTRACT_FOG(IN);
|
||||
#endif
|
||||
|
||||
|
||||
ShaderData d = CreateShaderData(IN);
|
||||
|
||||
Surface l = (Surface)0;
|
||||
|
||||
l.Albedo = half3(0.5, 0.5, 0.5);
|
||||
l.Normal = float3(0,0,1);
|
||||
l.Occlusion = 1;
|
||||
l.Alpha = 1;
|
||||
|
||||
ChainSurfaceFunction(l, d);
|
||||
|
||||
|
||||
|
||||
#ifndef USING_DIRECTIONAL_LIGHT
|
||||
fixed3 lightDir = normalize(UnityWorldSpaceLightDir(d.worldSpacePosition));
|
||||
#else
|
||||
fixed3 lightDir = _WorldSpaceLightPos0.xyz;
|
||||
#endif
|
||||
float3 worldViewDir = normalize(UnityWorldSpaceViewDir(d.worldSpacePosition));
|
||||
|
||||
#if _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC
|
||||
#ifdef UNITY_COMPILER_HLSL
|
||||
SurfaceOutputStandardSpecular o = (SurfaceOutputStandardSpecular)0;
|
||||
#else
|
||||
SurfaceOutputStandardSpecular o;
|
||||
#endif
|
||||
o.Specular = l.Specular;
|
||||
#elif _BDRFLAMBERT || _BDRF3
|
||||
#ifdef UNITY_COMPILER_HLSL
|
||||
SurfaceOutput o = (SurfaceOutput)0;
|
||||
#else
|
||||
SurfaceOutput o;
|
||||
#endif
|
||||
#else
|
||||
#ifdef UNITY_COMPILER_HLSL
|
||||
SurfaceOutputStandard o = (SurfaceOutputStandard)0;
|
||||
#else
|
||||
SurfaceOutputStandard o;
|
||||
#endif
|
||||
o.Metallic = l.Metallic;
|
||||
#endif
|
||||
|
||||
o.Albedo = l.Albedo;
|
||||
o.Emission = l.Emission;
|
||||
o.Alpha = l.Alpha;
|
||||
o.Normal = normalize(TangentToWorldSpace(d, l.Normal));
|
||||
|
||||
#if _BDRFLAMBERT || _BDRF3
|
||||
o.Specular = l.Occlusion;
|
||||
o.Gloss = l.Smoothness;
|
||||
#elif _SPECULARFROMMETALLIC
|
||||
o.Occlusion = l.Occlusion;
|
||||
o.Smoothness = l.Smoothness;
|
||||
o.Albedo = MicroSplatDiffuseAndSpecularFromMetallic(l.Albedo, l.Metallic, o.Specular, o.Smoothness);
|
||||
o.Smoothness = 1-o.Smoothness;
|
||||
#elif _USESPECULARWORKFLOW
|
||||
o.Occlusion = l.Occlusion;
|
||||
o.Smoothness = l.Smoothness;
|
||||
o.Specular = l.Specular;
|
||||
#else
|
||||
o.Smoothness = l.Smoothness;
|
||||
o.Metallic = l.Metallic;
|
||||
o.Occlusion = l.Occlusion;
|
||||
#endif
|
||||
|
||||
|
||||
half atten = 1;
|
||||
|
||||
// Setup lighting environment
|
||||
UnityGI gi;
|
||||
UNITY_INITIALIZE_OUTPUT(UnityGI, gi);
|
||||
gi.indirect.diffuse = 0;
|
||||
gi.indirect.specular = 0;
|
||||
gi.light.color = 0;
|
||||
gi.light.dir = half3(0,1,0);
|
||||
// Call GI (lightmaps/SH/reflections) lighting function
|
||||
UnityGIInput giInput;
|
||||
UNITY_INITIALIZE_OUTPUT(UnityGIInput, giInput);
|
||||
giInput.light = gi.light;
|
||||
giInput.worldPos = d.worldSpacePosition;
|
||||
giInput.worldViewDir = worldViewDir;
|
||||
giInput.atten = atten;
|
||||
#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)
|
||||
giInput.lightmapUV = IN.lmap;
|
||||
#else
|
||||
giInput.lightmapUV = 0.0;
|
||||
#endif
|
||||
#if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL
|
||||
giInput.ambient = IN.sh;
|
||||
#else
|
||||
giInput.ambient.rgb = 0.0;
|
||||
#endif
|
||||
giInput.probeHDR[0] = unity_SpecCube0_HDR;
|
||||
giInput.probeHDR[1] = unity_SpecCube1_HDR;
|
||||
#if defined(UNITY_SPECCUBE_BLENDING) || defined(UNITY_SPECCUBE_BOX_PROJECTION)
|
||||
giInput.boxMin[0] = unity_SpecCube0_BoxMin; // .w holds lerp value for blending
|
||||
#endif
|
||||
#ifdef UNITY_SPECCUBE_BOX_PROJECTION
|
||||
giInput.boxMax[0] = unity_SpecCube0_BoxMax;
|
||||
giInput.probePosition[0] = unity_SpecCube0_ProbePosition;
|
||||
giInput.boxMax[1] = unity_SpecCube1_BoxMax;
|
||||
giInput.boxMin[1] = unity_SpecCube1_BoxMin;
|
||||
giInput.probePosition[1] = unity_SpecCube1_ProbePosition;
|
||||
#endif
|
||||
|
||||
#if _USESPECULAR || _USESPECULARWORKFLOW || _SPECULARFROMMETALLIC
|
||||
LightingStandardSpecular_GI(o, giInput, gi);
|
||||
|
||||
// call lighting function to output g-buffer
|
||||
outEmission = LightingStandardSpecular_Deferred (o, worldViewDir, gi, outGBuffer0, outGBuffer1, outGBuffer2);
|
||||
#if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4)
|
||||
outShadowMask = UnityGetRawBakedOcclusions (IN.lmap.xy, d.worldSpacePosition);
|
||||
#endif
|
||||
#ifndef UNITY_HDR_ON
|
||||
outEmission.rgb = exp2(-outEmission.rgb);
|
||||
#endif
|
||||
#else
|
||||
LightingStandard_GI(o, giInput, gi);
|
||||
|
||||
// call lighting function to output g-buffer
|
||||
outEmission = LightingStandard_Deferred (o, worldViewDir, gi, outGBuffer0, outGBuffer1, outGBuffer2);
|
||||
#if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4)
|
||||
outShadowMask = UnityGetRawBakedOcclusions (IN.lmap.xy, d.worldSpacePosition);
|
||||
#endif
|
||||
#ifndef UNITY_HDR_ON
|
||||
outEmission.rgb = exp2(-outEmission.rgb);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4)
|
||||
ChainFinalGBufferStandard(l, d, outGBuffer0, outGBuffer1, outGBuffer2, outEmission, outShadowMask);
|
||||
#else
|
||||
half4 outShadowMask = 0;
|
||||
ChainFinalGBufferStandard(l, d, outGBuffer0, outGBuffer1, outGBuffer2, outEmission, outShadowMask);
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ENDCG
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,197 @@
|
||||
|
||||
// ---- meta information extraction pass:
|
||||
Pass
|
||||
{
|
||||
Name "Meta"
|
||||
Tags { "LightMode" = "Meta" }
|
||||
Cull Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
%PRAGMAS%
|
||||
|
||||
// compile directives
|
||||
#pragma target %SHADERTARGET%
|
||||
#pragma multi_compile_instancing
|
||||
#pragma multi_compile_local __ _ALPHATEST_ON
|
||||
#pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
|
||||
#pragma shader_feature EDITOR_VISUALIZATION
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
#include "UnityShaderVariables.cginc"
|
||||
#include "UnityShaderUtilities.cginc"
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#define _PASSMETA 1
|
||||
|
||||
%DEFINES%
|
||||
|
||||
#if _NOMINDIELETRIC
|
||||
// for Standard
|
||||
#ifdef unity_ColorSpaceDielectricSpec
|
||||
#undef unity_ColorSpaceDielectricSpec
|
||||
#endif
|
||||
#define unity_ColorSpaceDielectricSpec half4(0,0,0,1)
|
||||
#endif
|
||||
|
||||
#include "Lighting.cginc"
|
||||
#include "UnityPBSLighting.cginc"
|
||||
#include "UnityMetaPass.cginc"
|
||||
|
||||
|
||||
#if _MICROTERRAIN && !_TERRAINBLENDABLESHADER
|
||||
#define UNITY_ASSUME_UNIFORM_SCALING
|
||||
#define UNITY_DONT_INSTANCE_OBJECT_MATRICES
|
||||
#define UNITY_INSTANCED_LOD_FADE
|
||||
#else
|
||||
#define UNITY_INSTANCED_LOD_FADE
|
||||
#define UNITY_INSTANCED_SH
|
||||
#define UNITY_INSTANCED_LIGHTMAPSTS
|
||||
#endif
|
||||
|
||||
// data across stages, stripped like the above.
|
||||
struct VertexToPixel
|
||||
{
|
||||
UNITY_POSITION(pos);
|
||||
float3 worldPos : TEXCOORD0;
|
||||
float3 worldNormal : TEXCOORD1;
|
||||
float4 worldTangent : TEXCOORD2;
|
||||
%UV0% float4 texcoord0 : TEXCCOORD3;
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
%UV1% float4 texcoord1 : TEXCCOORD4;
|
||||
%UV2% float4 texcoord2 : TEXCCOORD5;
|
||||
#endif
|
||||
%UV3% float4 texcoord3 : TEXCCOORD6;
|
||||
%SCREENPOS% float4 screenPos : TEXCOORD7;
|
||||
%VERTEXCOLOR% float4 vertexColor : COLOR;
|
||||
#ifdef EDITOR_VISUALIZATION
|
||||
float2 vizUV : TEXCOORD8;
|
||||
float4 lightCoord : TEXCOORD9;
|
||||
#endif
|
||||
|
||||
%EXTRAV2F0% float4 extraV2F0 : TEXCOORD10;
|
||||
%EXTRAV2F1% float4 extraV2F1 : TEXCOORD11;
|
||||
%EXTRAV2F2% float4 extraV2F2 : TEXCOORD12;
|
||||
%EXTRAV2F3% float4 extraV2F3 : TEXCOORD13;
|
||||
%EXTRAV2F4% float4 extraV2F4 : TEXCOORD14;
|
||||
%EXTRAV2F5% float4 extraV2F5 : TEXCOORD15;
|
||||
%EXTRAV2F6% float4 extraV2F6 : TEXCOORD16;
|
||||
%EXTRAV2F7% float4 extraV2F7 : TEXCOORD17;
|
||||
|
||||
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
%TEMPLATE_SHARED%
|
||||
|
||||
%CBUFFER%
|
||||
|
||||
%CODE%
|
||||
|
||||
%SHADERDESC%
|
||||
|
||||
// vertex shader
|
||||
VertexToPixel Vert (VertexData v)
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
VertexToPixel o;
|
||||
UNITY_INITIALIZE_OUTPUT(VertexToPixel,o);
|
||||
UNITY_TRANSFER_INSTANCE_ID(v,o);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
#if !_TESSELLATION_ON
|
||||
ChainModifyVertex(v, o);
|
||||
#endif
|
||||
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
float2 uv1 = v.texcoord1.xy;
|
||||
float2 uv2 = v.texcoord2.xy;
|
||||
#else
|
||||
float2 uv1 = v.texcoord0.xy;
|
||||
float2 uv2 = uv1;
|
||||
#endif
|
||||
|
||||
o.pos = UnityMetaVertexPosition(v.vertex, uv1, uv2, unity_LightmapST, unity_DynamicLightmapST);
|
||||
|
||||
#ifdef EDITOR_VISUALIZATION
|
||||
o.vizUV = 0;
|
||||
o.lightCoord = 0;
|
||||
if (unity_VisualizationMode == EDITORVIZ_TEXTURE)
|
||||
o.vizUV = UnityMetaVizUV(unity_EditorViz_UVIndex, v.texcoord0.xy, uv1, uv2, unity_EditorViz_Texture_ST);
|
||||
else if (unity_VisualizationMode == EDITORVIZ_SHOWLIGHTMASK)
|
||||
{
|
||||
o.vizUV = uv1 * unity_LightmapST.xy + unity_LightmapST.zw;
|
||||
o.lightCoord = mul(unity_EditorViz_WorldToLight, mul(unity_ObjectToWorld, float4(v.vertex.xyz, 1)));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
%UV0% o.texcoord0 = v.texcoord0;
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
%UV1% o.texcoord1 = v.texcoord1;
|
||||
%UV2% o.texcoord2 = v.texcoord2;
|
||||
#endif
|
||||
%UV3% o.texcoord3 = v.texcoord3;
|
||||
%VERTEXCOLOR% o.vertexColor = v.vertexColor;
|
||||
%SCREENPOS% o.screenPos = ComputeScreenPos(o.pos);
|
||||
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
|
||||
o.worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
o.worldTangent.xyz = UnityObjectToWorldDir(v.tangent.xyz);
|
||||
fixed tangentSign = v.tangent.w * unity_WorldTransformParams.w;
|
||||
o.worldTangent.w = tangentSign;
|
||||
#endif
|
||||
|
||||
// MS Only
|
||||
ApplyTerrainTangent(o);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
%TESSELLATION%
|
||||
|
||||
// fragment shader
|
||||
fixed4 Frag (VertexToPixel IN) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(IN);
|
||||
|
||||
#ifdef FOG_COMBINED_WITH_TSPACE
|
||||
UNITY_EXTRACT_FOG_FROM_TSPACE(IN);
|
||||
#elif defined (FOG_COMBINED_WITH_WORLD_POS)
|
||||
UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN);
|
||||
#else
|
||||
UNITY_EXTRACT_FOG(IN);
|
||||
#endif
|
||||
|
||||
ShaderData d = CreateShaderData(IN);
|
||||
|
||||
Surface l = (Surface)0;
|
||||
|
||||
l.Albedo = half3(0.5, 0.5, 0.5);
|
||||
l.Normal = float3(0,0,1);
|
||||
l.Occlusion = 1;
|
||||
l.Alpha = 1;
|
||||
|
||||
|
||||
ChainSurfaceFunction(l, d);
|
||||
|
||||
UnityMetaInput metaIN;
|
||||
UNITY_INITIALIZE_OUTPUT(UnityMetaInput, metaIN);
|
||||
metaIN.Albedo = l.Albedo;
|
||||
metaIN.Emission = l.Emission;
|
||||
|
||||
#if _USESPECULAR
|
||||
metaIN.SpecularColor = l.Specular;
|
||||
#endif
|
||||
|
||||
#ifdef EDITOR_VISUALIZATION
|
||||
metaIN.VizUV = IN.vizUV;
|
||||
metaIN.LightCoord = IN.lightCoord;
|
||||
#endif
|
||||
return UnityMetaFragment(metaIN);
|
||||
}
|
||||
ENDCG
|
||||
|
||||
}
|
@@ -0,0 +1,155 @@
|
||||
|
||||
Pass {
|
||||
Name "ShadowCaster"
|
||||
Tags { "LightMode" = "ShadowCaster" }
|
||||
ZWrite On ZTest LEqual
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
%PRAGMAS%
|
||||
// compile directives
|
||||
#pragma target %SHADERTARGET%
|
||||
#pragma multi_compile_instancing
|
||||
#pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
|
||||
#pragma multi_compile_shadowcaster
|
||||
#pragma multi_compile_local __ _ALPHATEST_ON
|
||||
#include "HLSLSupport.cginc"
|
||||
#include "UnityShaderVariables.cginc"
|
||||
#include "UnityShaderUtilities.cginc"
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Lighting.cginc"
|
||||
#include "UnityPBSLighting.cginc"
|
||||
|
||||
#define _PASSSHADOW 1
|
||||
|
||||
%DEFINES%
|
||||
|
||||
#if _MICROTERRAIN && !_TERRAINBLENDABLESHADER
|
||||
#define UNITY_ASSUME_UNIFORM_SCALING
|
||||
#define UNITY_DONT_INSTANCE_OBJECT_MATRICES
|
||||
#define UNITY_INSTANCED_LOD_FADE
|
||||
#else
|
||||
#define UNITY_INSTANCED_LOD_FADE
|
||||
#define UNITY_INSTANCED_SH
|
||||
#define UNITY_INSTANCED_LIGHTMAPSTS
|
||||
#endif
|
||||
|
||||
|
||||
// data across stages, stripped like the above.
|
||||
struct VertexToPixel
|
||||
{
|
||||
V2F_SHADOW_CASTER;
|
||||
float3 worldPos : TEXCOORD0;
|
||||
float3 worldNormal : TEXCOORD1;
|
||||
float4 worldTangent : TEXCOORD2;
|
||||
%UV0% float4 texcoord0 : TEXCCOORD3;
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
%UV1% float4 texcoord1 : TEXCCOORD4;
|
||||
%UV2% float4 texcoord2 : TEXCCOORD5;
|
||||
#endif
|
||||
%UV3% float4 texcoord3 : TEXCCOORD6;
|
||||
%SCREENPOS% float4 screenPos : TEXCOORD7;
|
||||
%VERTEXCOLOR% float4 vertexColor : COLOR;
|
||||
|
||||
%EXTRAV2F0% float4 extraV2F0 : TEXCOORD8;
|
||||
%EXTRAV2F1% float4 extraV2F1 : TEXCOORD9;
|
||||
%EXTRAV2F2% float4 extraV2F2 : TEXCOORD10;
|
||||
%EXTRAV2F3% float4 extraV2F3 : TEXCOORD11;
|
||||
%EXTRAV2F4% float4 extraV2F4 : TEXCOORD12;
|
||||
%EXTRAV2F5% float4 extraV2F5 : TEXCOORD13;
|
||||
%EXTRAV2F6% float4 extraV2F6 : TEXCOORD14;
|
||||
%EXTRAV2F7% float4 extraV2F7 : TEXCOORD15;
|
||||
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
%TEMPLATE_SHARED%
|
||||
|
||||
%CBUFFER%
|
||||
|
||||
%CODE%
|
||||
|
||||
%SHADERDESC%
|
||||
|
||||
|
||||
// vertex shader
|
||||
VertexToPixel Vert (VertexData v)
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
VertexToPixel o;
|
||||
UNITY_INITIALIZE_OUTPUT(VertexToPixel,o);
|
||||
UNITY_TRANSFER_INSTANCE_ID(v,o);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
#if !_TESSELLATION_ON
|
||||
ChainModifyVertex(v, o);
|
||||
#endif
|
||||
|
||||
%UV0% o.texcoord0 = v.texcoord0;
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
%UV1% o.texcoord1 = v.texcoord1;
|
||||
%UV2% o.texcoord2 = v.texcoord2;
|
||||
#endif
|
||||
%UV3% o.texcoord3 = v.texcoord3;
|
||||
%VERTEXCOLOR% o.vertexColor = v.vertexColor;
|
||||
|
||||
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
|
||||
o.worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
o.worldTangent.xyz = UnityObjectToWorldDir(v.tangent.xyz);
|
||||
fixed tangentSign = v.tangent.w * unity_WorldTransformParams.w;
|
||||
o.worldTangent.w = tangentSign;
|
||||
#endif
|
||||
|
||||
// MS Only
|
||||
ApplyTerrainTangent(o);
|
||||
|
||||
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
|
||||
|
||||
%SCREENPOS% o.screenPos = ComputeScreenPos(o.pos);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
%TESSELLATION%
|
||||
|
||||
// fragment shader
|
||||
fixed4 Frag (VertexToPixel IN) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(IN);
|
||||
// prepare and unpack data
|
||||
|
||||
#ifdef FOG_COMBINED_WITH_TSPACE
|
||||
UNITY_EXTRACT_FOG_FROM_TSPACE(IN);
|
||||
#elif defined (FOG_COMBINED_WITH_WORLD_POS)
|
||||
UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN);
|
||||
#else
|
||||
UNITY_EXTRACT_FOG(IN);
|
||||
#endif
|
||||
|
||||
#ifndef USING_DIRECTIONAL_LIGHT
|
||||
fixed3 lightDir = normalize(UnityWorldSpaceLightDir(IN.worldPos));
|
||||
#else
|
||||
fixed3 lightDir = _WorldSpaceLightPos0.xyz;
|
||||
#endif
|
||||
|
||||
ShaderData d = CreateShaderData(IN);
|
||||
|
||||
Surface l = (Surface)0;
|
||||
|
||||
l.Albedo = half3(0.5, 0.5, 0.5);
|
||||
l.Normal = float3(0,0,1);
|
||||
l.Occlusion = 1;
|
||||
l.Alpha = 1;
|
||||
|
||||
ChainSurfaceFunction(l, d);
|
||||
|
||||
SHADOW_CASTER_FRAGMENT(IN)
|
||||
}
|
||||
|
||||
|
||||
ENDCG
|
||||
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
|
||||
|
||||
#if _MESHSUBARRAY
|
||||
half4 _MeshSubArrayIndexes;
|
||||
#endif
|
||||
|
||||
float4 _Diffuse_TexelSize;
|
||||
float4 _NormalSAO_TexelSize;
|
||||
|
||||
#if _HYBRIDHEIGHTBLEND
|
||||
float _HybridHeightBlendDistance;
|
||||
#endif
|
||||
|
||||
#if _PACKINGHQ
|
||||
float4 _SmoothAO_TexelSize;
|
||||
#endif
|
||||
|
||||
#ifdef _ALPHATEST_ON
|
||||
float4 _TerrainHolesTexture_TexelSize;
|
||||
#endif
|
||||
|
||||
#if _USESPECULARWORKFLOW
|
||||
float4 _Specular_TexelSize;
|
||||
#endif
|
||||
|
||||
#if _USEEMISSIVEMETAL
|
||||
float4 _EmissiveMetal_TexelSize;
|
||||
#endif
|
||||
|
||||
#if _USEEMISSIVEMETAL
|
||||
half _EmissiveMult;
|
||||
#endif
|
||||
|
||||
#if _AUTONORMAL
|
||||
half _AutoNormalHeightScale;
|
||||
#endif
|
||||
|
||||
float4 _UVScale; // scale and offset
|
||||
|
||||
half _Contrast;
|
||||
|
||||
|
||||
|
||||
#if _VSSHADOWMAP
|
||||
float4 gVSSunDirection;
|
||||
#endif
|
||||
|
||||
#if _FORCELOCALSPACE && _PLANETVECTORS
|
||||
float4x4 _PQSToLocal;
|
||||
#endif
|
||||
|
||||
#if _ORIGINSHIFT
|
||||
float4x4 _GlobalOriginMTX;
|
||||
#endif
|
||||
|
||||
float4 _Control0_TexelSize;
|
||||
#if _CUSTOMSPLATTEXTURES
|
||||
float4 _CustomControl0_TexelSize;
|
||||
#endif
|
||||
float4 _PerPixelNormal_TexelSize;
|
||||
|
||||
#if _CONTROLNOISEUV || _GLOBALNOISEUV
|
||||
float2 _NoiseUVParams;
|
||||
#endif
|
||||
|
||||
float4 _PerTexProps_TexelSize;
|
||||
|
||||
#if _SURFACENORMALS
|
||||
float3 surfTangent;
|
||||
float3 surfBitangent;
|
||||
float3 surfNormal;
|
||||
#endif
|
@@ -0,0 +1,16 @@
|
||||
|
||||
|
||||
// Splats
|
||||
[NoScaleOffset]_Diffuse ("Diffuse Array", 2DArray) = "white" {}
|
||||
[NoScaleOffset]_NormalSAO ("Normal Array", 2DArray) = "bump" {}
|
||||
[NoScaleOffset]_PerTexProps("Per Texture Properties", 2D) = "black" {}
|
||||
[HideInInspector] _TerrainHolesTexture("Holes Map (RGB)", 2D) = "white" {}
|
||||
[HideInInspector] _PerPixelNormal("Per Pixel Normal", 2D) = "bump" {}
|
||||
_Contrast("Blend Contrast", Range(0.01, 0.99)) = 0.4
|
||||
_UVScale("UV Scales", Vector) = (45, 45, 0, 0)
|
||||
|
||||
// for Unity 2020.3 bug
|
||||
_MainTex("Unity Bug", 2D) = "white" {}
|
||||
|
||||
_TerrainHeightmapTexture("", 2D) = "black" {}
|
||||
_TerrainNormalmapTexture("", 2D) = "bump" {}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
#undef WorldNormalVector
|
||||
#define WorldNormalVector(data, normal) mul(normal, data.TBN)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -0,0 +1,51 @@
|
||||
// CHAINS
|
||||
|
||||
void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p)
|
||||
{
|
||||
ExtraV2F d = (ExtraV2F)0;
|
||||
ModifyVertex(v, d);
|
||||
|
||||
%EXTRAV2F0% v2p.extraV2F0 = d.extraV2F0;
|
||||
%EXTRAV2F1% v2p.extraV2F1 = d.extraV2F1;
|
||||
%EXTRAV2F2% v2p.extraV2F2 = d.extraV2F2;
|
||||
%EXTRAV2F3% v2p.extraV2F3 = d.extraV2F3;
|
||||
%EXTRAV2F4% v2p.extraV2F4 = d.extraV2F4;
|
||||
%EXTRAV2F5% v2p.extraV2F5 = d.extraV2F5;
|
||||
%EXTRAV2F6% v2p.extraV2F6 = d.extraV2F6;
|
||||
%EXTRAV2F7% v2p.extraV2F7 = d.extraV2F7;
|
||||
}
|
||||
|
||||
void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p)
|
||||
{
|
||||
ExtraV2F d = (ExtraV2F)0;
|
||||
%EXTRAV2F0% d.extraV2F0 = v2p.extraV2F0;
|
||||
%EXTRAV2F1% d.extraV2F1 = v2p.extraV2F1;
|
||||
%EXTRAV2F2% d.extraV2F2 = v2p.extraV2F2;
|
||||
%EXTRAV2F3% d.extraV2F3 = v2p.extraV2F3;
|
||||
%EXTRAV2F4% d.extraV2F4 = v2p.extraV2F4;
|
||||
%EXTRAV2F5% d.extraV2F5 = v2p.extraV2F5;
|
||||
%EXTRAV2F6% d.extraV2F6 = v2p.extraV2F6;
|
||||
%EXTRAV2F7% d.extraV2F7 = v2p.extraV2F7;
|
||||
|
||||
ModifyTessellatedVertex(v, d);
|
||||
|
||||
%EXTRAV2F0% v2p.extraV2F0 = d.extraV2F0;
|
||||
%EXTRAV2F1% v2p.extraV2F1 = d.extraV2F1;
|
||||
%EXTRAV2F2% v2p.extraV2F2 = d.extraV2F2;
|
||||
%EXTRAV2F3% v2p.extraV2F3 = d.extraV2F3;
|
||||
%EXTRAV2F4% v2p.extraV2F4 = d.extraV2F4;
|
||||
%EXTRAV2F5% v2p.extraV2F5 = d.extraV2F5;
|
||||
%EXTRAV2F6% v2p.extraV2F6 = d.extraV2F6;
|
||||
%EXTRAV2F7% v2p.extraV2F7 = d.extraV2F7;
|
||||
}
|
||||
|
||||
|
||||
void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask)
|
||||
{
|
||||
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
// SHADERDESC
|
||||
|
||||
ShaderData CreateShaderData(VertexToPixel i)
|
||||
{
|
||||
ShaderData d = (ShaderData)0;
|
||||
d.worldSpacePosition = i.worldPos;
|
||||
|
||||
d.worldSpaceNormal = i.worldNormal;
|
||||
d.worldSpaceTangent = i.worldTangent.xyz;
|
||||
float3 bitangent = cross(i.worldTangent.xyz, i.worldNormal) * i.worldTangent.w * -1;
|
||||
|
||||
|
||||
d.TBNMatrix = float3x3(d.worldSpaceTangent, bitangent, d.worldSpaceNormal);
|
||||
d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - i.worldPos);
|
||||
d.tangentSpaceViewDir = mul(d.worldSpaceViewDir, d.TBNMatrix);
|
||||
%UV0% d.texcoord0 = i.texcoord0;
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
%UV1% d.texcoord1 = i.texcoord1;
|
||||
%UV2% d.texcoord2 = i.texcoord2;
|
||||
#endif
|
||||
%UV3% d.texcoord3 = i.texcoord3;
|
||||
%VERTEXCOLOR% d.vertexColor = i.vertexColor;
|
||||
|
||||
// these rarely get used, so we back transform them. Usually will be stripped.
|
||||
#if _HDRP
|
||||
%LOCALSPACEPOSITION% d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(i.worldPos), 1));
|
||||
#else
|
||||
%LOCALSPACEPOSITION% d.localSpacePosition = mul(unity_WorldToObject, float4(i.worldPos, 1));
|
||||
#endif
|
||||
%LOCALSPACENORMAL% d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, i.worldNormal));
|
||||
%LOCALSPACETANGENT% d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, i.worldTangent.xyz));
|
||||
|
||||
%SCREENPOS% d.screenPos = i.screenPos;
|
||||
%SCREENPOS% d.screenUV = i.screenPos.xy / i.screenPos.w;
|
||||
|
||||
%EXTRAV2F0% d.extraV2F0 = i.extraV2F0;
|
||||
%EXTRAV2F1% d.extraV2F1 = i.extraV2F1;
|
||||
%EXTRAV2F2% d.extraV2F2 = i.extraV2F2;
|
||||
%EXTRAV2F3% d.extraV2F3 = i.extraV2F3;
|
||||
%EXTRAV2F4% d.extraV2F4 = i.extraV2F4;
|
||||
%EXTRAV2F5% d.extraV2F5 = i.extraV2F5;
|
||||
%EXTRAV2F6% d.extraV2F6 = i.extraV2F6;
|
||||
%EXTRAV2F7% d.extraV2F7 = i.extraV2F7;
|
||||
|
||||
return d;
|
||||
}
|
||||
|
@@ -0,0 +1,229 @@
|
||||
// TEMPLATE_SHARED
|
||||
|
||||
// data describing the user output of a pixel
|
||||
struct Surface
|
||||
{
|
||||
half3 Albedo;
|
||||
half Height;
|
||||
half3 Normal;
|
||||
half Smoothness;
|
||||
half3 Emission;
|
||||
half Metallic;
|
||||
half3 Specular;
|
||||
half Occlusion;
|
||||
half Alpha;
|
||||
// HDRP Only
|
||||
half SpecularOcclusion;
|
||||
half SubsurfaceMask;
|
||||
half Thickness;
|
||||
half CoatMask;
|
||||
half Anisotropy;
|
||||
half IridescenceMask;
|
||||
half IridescenceThickness;
|
||||
};
|
||||
|
||||
// data the user might need, this will grow to be big. But easy to strip
|
||||
struct ShaderData
|
||||
{
|
||||
float3 localSpacePosition;
|
||||
float3 localSpaceNormal;
|
||||
float3 localSpaceTangent;
|
||||
|
||||
float3 worldSpacePosition;
|
||||
float3 worldSpaceNormal;
|
||||
float3 worldSpaceTangent;
|
||||
|
||||
float3 worldSpaceViewDir;
|
||||
float3 tangentSpaceViewDir;
|
||||
|
||||
float4 texcoord0;
|
||||
float4 texcoord1;
|
||||
float4 texcoord2;
|
||||
float4 texcoord3;
|
||||
|
||||
float2 screenUV;
|
||||
float4 screenPos;
|
||||
|
||||
float4 vertexColor;
|
||||
|
||||
float4 extraV2F0;
|
||||
float4 extraV2F1;
|
||||
float4 extraV2F2;
|
||||
float4 extraV2F3;
|
||||
float4 extraV2F4;
|
||||
float4 extraV2F5;
|
||||
float4 extraV2F6;
|
||||
float4 extraV2F7;
|
||||
|
||||
float3x3 TBNMatrix;
|
||||
};
|
||||
|
||||
struct VertexData
|
||||
{
|
||||
#if SHADER_TARGET > 30 && _PLANETCOMPUTE
|
||||
// %VERTEXID% uint vertexID : SV_VertexID;
|
||||
#endif
|
||||
float4 vertex : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
float4 texcoord0 : TEXCOORD0;
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
float4 tangent : TANGENT;
|
||||
float4 texcoord1 : TEXCOORD1;
|
||||
float4 texcoord2 : TEXCOORD2;
|
||||
#endif
|
||||
%UV3% float4 texcoord3 : TEXCOORD3;
|
||||
%VERTEXCOLOR% float4 vertexColor : COLOR;
|
||||
|
||||
|
||||
#if _HDRP && (_PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
|
||||
float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example)
|
||||
#if defined (_ADD_PRECOMPUTED_VELOCITY)
|
||||
float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side).
|
||||
#endif
|
||||
#endif
|
||||
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct TessVertex
|
||||
{
|
||||
float4 vertex : INTERNALTESSPOS;
|
||||
float3 normal : NORMAL;
|
||||
float4 texcoord0 : TEXCOORD0;
|
||||
#if !_MICROTERRAIN || _TERRAINBLENDABLESHADER
|
||||
float4 tangent : TANGENT;
|
||||
float4 texcoord1 : TEXCOORD1;
|
||||
float4 texcoord2 : TEXCOORD2;
|
||||
#endif
|
||||
%UV3% float4 texcoord3 : TEXCOORD3;
|
||||
%VERTEXCOLOR% float4 vertexColor : COLOR;
|
||||
|
||||
|
||||
%EXTRAV2F0% float4 extraV2F0 : TEXCOORD4;
|
||||
%EXTRAV2F1% float4 extraV2F1 : TEXCOORD5;
|
||||
%EXTRAV2F2% float4 extraV2F2 : TEXCOORD6;
|
||||
%EXTRAV2F3% float4 extraV2F3 : TEXCOORD7;
|
||||
%EXTRAV2F4% float4 extraV2F4 : TEXCOORD8;
|
||||
%EXTRAV2F5% float4 extraV2F5 : TEXCOORD9;
|
||||
%EXTRAV2F6% float4 extraV2F6 : TEXCOORD10;
|
||||
%EXTRAV2F7% float4 extraV2F7 : TEXCOORD11;
|
||||
|
||||
#if _HDRP && (_PASSMOTIONVECTOR || (_PASSFORWARD && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
|
||||
float3 previousPositionOS : TEXCOORD12; // Contain previous transform position (in case of skinning for example)
|
||||
#if defined (_ADD_PRECOMPUTED_VELOCITY)
|
||||
float3 precomputedVelocity : TEXCOORD13;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
struct ExtraV2F
|
||||
{
|
||||
float4 extraV2F0;
|
||||
float4 extraV2F1;
|
||||
float4 extraV2F2;
|
||||
float4 extraV2F3;
|
||||
float4 extraV2F4;
|
||||
float4 extraV2F5;
|
||||
float4 extraV2F6;
|
||||
float4 extraV2F7;
|
||||
};
|
||||
|
||||
|
||||
float3 WorldToTangentSpace(ShaderData d, float3 normal)
|
||||
{
|
||||
return mul(d.TBNMatrix, normal);
|
||||
}
|
||||
|
||||
float3 TangentToWorldSpace(ShaderData d, float3 normal)
|
||||
{
|
||||
return mul(normal, d.TBNMatrix);
|
||||
}
|
||||
|
||||
// in this case, make standard more like SRPs, because we can't fix
|
||||
// unity_WorldToObject in HDRP, since it already does macro-fu there
|
||||
|
||||
#if _STANDARD
|
||||
float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); };
|
||||
float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); };
|
||||
float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); };
|
||||
float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); };
|
||||
float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; }
|
||||
float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; }
|
||||
#endif
|
||||
|
||||
float3 GetCameraWorldPosition()
|
||||
{
|
||||
#if _HDRP
|
||||
return GetCameraRelativePositionWS(_WorldSpaceCameraPos);
|
||||
#else
|
||||
return _WorldSpaceCameraPos;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if _HDRP
|
||||
|
||||
half3 UnpackNormalmapRGorAG(half4 packednormal)
|
||||
{
|
||||
// This do the trick
|
||||
packednormal.x *= packednormal.w;
|
||||
|
||||
half3 normal;
|
||||
normal.xy = packednormal.xy * 2 - 1;
|
||||
normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
|
||||
return normal;
|
||||
}
|
||||
half3 UnpackNormal(half4 packednormal)
|
||||
{
|
||||
#if defined(UNITY_NO_DXT5nm)
|
||||
return packednormal.xyz * 2 - 1;
|
||||
#else
|
||||
return UnpackNormalmapRGorAG(packednormal);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if _HDRP || _URP
|
||||
|
||||
half3 UnpackScaleNormal(half4 packednormal, half scale)
|
||||
{
|
||||
#ifndef UNITY_NO_DXT5nm
|
||||
// Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1)
|
||||
// Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5
|
||||
packednormal.x *= packednormal.w;
|
||||
#endif
|
||||
half3 normal;
|
||||
normal.xy = (packednormal.xy * 2 - 1) * scale;
|
||||
normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
|
||||
return normal;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void GetSun(out float3 lightDir, out float3 color)
|
||||
{
|
||||
lightDir = float3(0.5, 0.5, 0);
|
||||
color = 1;
|
||||
#if _HDRP
|
||||
if (_DirectionalLightCount > 0)
|
||||
{
|
||||
DirectionalLightData light = _DirectionalLightDatas[0];
|
||||
lightDir = -light.forward.xyz;
|
||||
color = light.color;
|
||||
}
|
||||
#elif _STANDARD
|
||||
lightDir = normalize(_WorldSpaceLightPos0.xyz);
|
||||
color = _LightColor0.rgb;
|
||||
#elif _URP
|
||||
Light light = GetMainLight();
|
||||
lightDir = light.direction;
|
||||
color = light.color;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,103 @@
|
||||
|
||||
|
||||
|
||||
void SurfaceFunction(inout Surface o, inout ShaderData d)
|
||||
{
|
||||
|
||||
float3 worldNormalVertex = d.worldSpaceNormal;
|
||||
#if _MICROVERSEPREVIEW
|
||||
float2 sampleCoords = d.texcoord0.xy;
|
||||
#if _TOONHARDEDGENORMAL
|
||||
sampleCoords = ToonEdgeUV(d.texcoord0.xy);
|
||||
#endif
|
||||
|
||||
float3 geomNormal = normalize(SAMPLE_TEXTURE2D(_TerrainNormalmapTexture, shared_linear_clamp_sampler, sampleCoords).xyz * 2 - 1);
|
||||
float3 geomTangent = normalize(cross(geomNormal, float3(0, 0, 1)));
|
||||
float3 geomBitangent = normalize(cross(geomNormal, geomTangent)) * -1;
|
||||
worldNormalVertex = geomNormal;
|
||||
d.worldSpaceNormal = geomNormal;
|
||||
d.worldSpaceTangent = geomTangent;
|
||||
|
||||
d.TBNMatrix = float3x3(geomTangent, geomBitangent, geomNormal);
|
||||
d.tangentSpaceViewDir = mul(d.worldSpaceViewDir, d.TBNMatrix);
|
||||
|
||||
#elif (defined(UNITY_INSTANCING_ENABLED) && _MICROTERRAIN && !_TERRAINBLENDABLESHADER)
|
||||
float2 sampleCoords = (d.texcoord0.xy / _TerrainHeightmapRecipSize.zw + 0.5f) * _TerrainHeightmapRecipSize.xy;
|
||||
#if _TOONHARDEDGENORMAL
|
||||
sampleCoords = ToonEdgeUV(d.texcoord0.xy);
|
||||
#endif
|
||||
|
||||
float3 geomNormal = normalize(SAMPLE_TEXTURE2D(_TerrainNormalmapTexture, shared_linear_clamp_sampler, sampleCoords).xyz * 2 - 1);
|
||||
float3 geomTangent = normalize(cross(geomNormal, float3(0, 0, 1)));
|
||||
float3 geomBitangent = normalize(cross(geomNormal, geomTangent)) * -1;
|
||||
worldNormalVertex = geomNormal;
|
||||
d.worldSpaceNormal = geomNormal;
|
||||
d.worldSpaceTangent = geomTangent;
|
||||
|
||||
d.TBNMatrix = float3x3(geomTangent, geomBitangent, geomNormal);
|
||||
d.tangentSpaceViewDir = mul(d.worldSpaceViewDir, d.TBNMatrix);
|
||||
|
||||
#elif _PERPIXNORMAL && (_MICROTERRAIN || _MICROMESHTERRAIN) && !_TERRAINBLENDABLESHADER
|
||||
float2 sampleCoords = (d.texcoord0.xy * _PerPixelNormal_TexelSize.zw + 0.5f) * _PerPixelNormal_TexelSize.xy;
|
||||
#if _TOONHARDEDGENORMAL
|
||||
sampleCoords = ToonEdgeUV(d.texcoord0.xy);
|
||||
#endif
|
||||
|
||||
float3 geomNormal = normalize(SAMPLE_TEXTURE2D(_PerPixelNormal, shared_linear_clamp_sampler, sampleCoords).xyz * 2 - 1);
|
||||
|
||||
float3 geomTangent = normalize(cross(geomNormal, float3(0, 0, 1)));
|
||||
|
||||
float3 geomBitangent = normalize(cross(geomTangent, geomNormal)) * -1;
|
||||
#if _MICROMESHTERRAIN
|
||||
geomBitangent *= -1;
|
||||
#endif
|
||||
|
||||
worldNormalVertex = geomNormal;
|
||||
d.worldSpaceNormal = geomNormal;
|
||||
d.worldSpaceTangent = geomTangent;
|
||||
d.TBNMatrix = float3x3(geomTangent, geomBitangent, geomNormal);
|
||||
d.tangentSpaceViewDir = mul(d.worldSpaceViewDir, d.TBNMatrix);
|
||||
|
||||
#endif
|
||||
|
||||
#if _TOONPOLYEDGE
|
||||
FlatShade(d);
|
||||
#endif
|
||||
|
||||
Input i = DescToInput(d);
|
||||
|
||||
|
||||
|
||||
#if _SRPTERRAINBLEND
|
||||
MicroSplatLayer l = BlendWithTerrain(d);
|
||||
|
||||
#if _DEBUG_WORLDNORMAL
|
||||
ClearAllButAlbedo(l, normalize(TangentToWorldSpace(d, l.Normal)) * saturate(l.Albedo.z+1));
|
||||
#endif
|
||||
#else
|
||||
MicroSplatLayer l = SurfImpl(i, worldNormalVertex);
|
||||
#endif
|
||||
|
||||
DoDebugOutput(l);
|
||||
|
||||
|
||||
|
||||
|
||||
o.Albedo = l.Albedo;
|
||||
o.Normal = l.Normal;
|
||||
o.Smoothness = l.Smoothness;
|
||||
o.Occlusion = l.Occlusion;
|
||||
o.Metallic = l.Metallic;
|
||||
o.Emission = l.Emission;
|
||||
#if _USESPECULARWORKFLOW
|
||||
o.Specular = l.Specular;
|
||||
#endif
|
||||
o.Height = l.Height;
|
||||
o.Alpha = l.Alpha;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -0,0 +1,2 @@
|
||||
|
||||
|
@@ -0,0 +1,41 @@
|
||||
|
||||
|
||||
|
||||
Input DescToInput(ShaderData IN)
|
||||
{
|
||||
Input s = (Input)0;
|
||||
s.shaderData = IN;
|
||||
s.TBN = IN.TBNMatrix;
|
||||
s.worldNormal = IN.worldSpaceNormal;
|
||||
s.worldPos = IN.worldSpacePosition;
|
||||
s.viewDir = IN.tangentSpaceViewDir;
|
||||
s.uv_Control0 = IN.texcoord0.xy;
|
||||
|
||||
s.worldUpVector = float3(0,1,0);
|
||||
s.worldHeight = IN.worldSpacePosition.y;
|
||||
|
||||
#if _PLANETVECTORS
|
||||
float3 rwp = mul(_PQSToLocal, float4(IN.worldSpacePosition, 1));
|
||||
s.worldHeight = distance(rwp, float3(0,0,0));
|
||||
s.worldUpVector = normalize(rwp);
|
||||
#endif
|
||||
|
||||
#if _MICROMESH && _MESHUV2
|
||||
s.uv2_Diffuse = IN.texcoord1.xy;
|
||||
#endif
|
||||
|
||||
#if _MEGASPLAT
|
||||
UnpackMegaSplat(s, IN);
|
||||
#endif
|
||||
|
||||
#if _MICROVERTEXMESH || _MICRODIGGERMESH
|
||||
UnpackVertexWorkflow(s, IN);
|
||||
#endif
|
||||
|
||||
#if _PLANETVECTORS
|
||||
DoPlanetDataInputCopy(s, IN);
|
||||
#endif
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@@ -0,0 +1,114 @@
|
||||
|
||||
|
||||
|
||||
|
||||
float4 ConstructTerrainTangent(float3 normal, float3 positiveZ)
|
||||
{
|
||||
// Consider a flat terrain. It should have tangent be (1, 0, 0) and bitangent be (0, 0, 1) as the UV of the terrain grid mesh is a scale of the world XZ position.
|
||||
// In CreateTangentToWorld function (in SpaceTransform.hlsl), it is cross(normal, tangent) * sgn for the bitangent vector.
|
||||
// It is not true in a left-handed coordinate system for the terrain bitangent, if we provide 1 as the tangent.w. It would produce (0, 0, -1) instead of (0, 0, 1).
|
||||
// Also terrain's tangent calculation was wrong in a left handed system because cross((0,0,1), terrainNormalOS) points to the wrong direction as negative X.
|
||||
// Therefore all the 4 xyzw components of the tangent needs to be flipped to correct the tangent frame.
|
||||
// (See TerrainLitData.hlsl - GetSurfaceAndBuiltinData)
|
||||
float3 tangent = normalize(cross(normal, positiveZ));
|
||||
return float4(tangent, -1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TerrainInstancing(inout float4 vertex, inout float3 normal, inout float2 uv)
|
||||
{
|
||||
#if _MICROTERRAIN && defined(UNITY_INSTANCING_ENABLED) && !_TERRAINBLENDABLESHADER
|
||||
|
||||
float2 patchVertex = vertex.xy;
|
||||
float4 instanceData = UNITY_ACCESS_INSTANCED_PROP(Terrain, _TerrainPatchInstanceData);
|
||||
|
||||
float2 sampleCoords = (patchVertex.xy + instanceData.xy) * instanceData.z; // (xy + float2(xBase,yBase)) * skipScale
|
||||
uv = sampleCoords * _TerrainHeightmapRecipSize.zw;
|
||||
|
||||
float2 sampleUV = (uv / _TerrainHeightmapRecipSize.zw + 0.5f) * _TerrainHeightmapRecipSize.xy;
|
||||
|
||||
float height = UnpackHeightmap(SAMPLE_TEXTURE2D_LOD(_TerrainHeightmapTexture, shared_linear_clamp_sampler, sampleUV, 0));
|
||||
|
||||
vertex.xz = sampleCoords * _TerrainHeightmapScale.xz;
|
||||
vertex.y = height * _TerrainHeightmapScale.y;
|
||||
|
||||
|
||||
normal = float3(0, 1, 0);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void ApplyMeshModification(inout VertexData input)
|
||||
{
|
||||
#if _MICROTERRAIN && !_TERRAINBLENDABLESHADER
|
||||
float2 uv = input.texcoord0.xy;
|
||||
TerrainInstancing(input.vertex, input.normal, uv);
|
||||
input.texcoord0.xy = uv;
|
||||
#endif
|
||||
#if _PERPIXNORMAL && !_TERRAINBLENDABLESHADER
|
||||
input.normal = float3(0,1,0);
|
||||
#endif
|
||||
|
||||
#if _MICROVERSEPREVIEW
|
||||
float4 recipSize = _TerrainHeightmapTexture_TexelSize;
|
||||
recipSize.zw = (1.0f / (_TerrainHeightmapTexture_TexelSize.zw-1));
|
||||
float2 sampleCoords = (input.texcoord0.xy / recipSize.zw + 0.5f) * recipSize.xy;
|
||||
float height = UnpackHeightmap(SAMPLE_TEXTURE2D_LOD(_TerrainHeightmapTexture, shared_linear_clamp_sampler, sampleCoords, 0));
|
||||
input.vertex.xyz += float3(0,1,0) * height * _TerrainHeight * 2;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
// called by the template, so we can remove tangent from VertexData
|
||||
void ApplyTerrainTangent(inout VertexToPixel input)
|
||||
{
|
||||
#if (_MICROTERRAIN || _PERPIXNORMAL) && !_TERRAINBLENDABLESHADER
|
||||
input.worldTangent = ConstructTerrainTangent(input.worldNormal, float3(0, 0, 1));
|
||||
#endif
|
||||
|
||||
// digger meshes ain't got no tangent either..
|
||||
#if _MICRODIGGERMESH && !_TERRAINBLENDABLESHADER
|
||||
input.worldTangent = ConstructTerrainTangent(input.worldNormal, float3(0, 0, 1));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void ModifyVertex(inout VertexData v, inout ExtraV2F d)
|
||||
{
|
||||
ApplyMeshModification(v);
|
||||
|
||||
#if _MICROVERTEXMESH || _MICRODIGGERMESH
|
||||
EncodeVertexWorkflow(v, d);
|
||||
#elif _MEGASPLAT
|
||||
EncodeMegaSplatVertex(v, d);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ModifyTessellatedVertex(inout VertexData v, inout ExtraV2F d)
|
||||
{
|
||||
#if _MICROVERSEPREVIEW
|
||||
v.vertex.y = OffsetVertex(v, d).y;
|
||||
#elif _TESSDISTANCE || _TESSEDGE
|
||||
v.vertex.xyz += OffsetVertex(v, d);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
float3 GetTessFactors ()
|
||||
{
|
||||
#if _TESSEDGE
|
||||
return float3(_TessData1.x, _TessData1.w, 0);
|
||||
#endif
|
||||
#if _TESSDISTANCE
|
||||
return float3(_TessData2.x, _TessData2.y, _TessData1.x);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -0,0 +1,38 @@
|
||||
// This contains functions that the MicroSplat compiler explicitly strips so that we
|
||||
// don't add more cruft to the v2f structure. I'm not crazy about the way this is done,
|
||||
// but without BS having a proper code parser this works.. Note that in most cases,
|
||||
// the module system naturally doesn't add code it's not using to the shader, so
|
||||
// the only stuff that has to go here is stuff that happens in the vertex stage.
|
||||
|
||||
|
||||
void UnpackVertexWorkflow(inout Input i, ShaderData d)
|
||||
{
|
||||
i.w0.xy = d.texcoord0.zw;
|
||||
i.w0.zw = d.texcoord1.zw;
|
||||
%MAX8% i.w1 = d.vertexColor;
|
||||
%MAX12% i.w2 = d.extraV2F0;
|
||||
%MAX16% i.w3 = d.extraV2F1;
|
||||
%MAX20% i.w4 = d.extraV2F2;
|
||||
%MAX24% i.w5 = d.extraV2F3;
|
||||
%MAX28% i.w6 = d.extraV2F4;
|
||||
%FX% i.fx = d.extraV2F5;
|
||||
}
|
||||
|
||||
void EncodeVertexWorkflow(inout VertexData i, inout ExtraV2F d)
|
||||
{
|
||||
float4 data0 = DecodeToFloat4(i.vertexColor.r);
|
||||
|
||||
|
||||
%MAX12% d.extraV2F0 = DecodeToFloat4(i.vertexColor.b);
|
||||
%MAX16% d.extraV2F1 = DecodeToFloat4(i.vertexColor.a);
|
||||
%MAX8% i.vertexColor = DecodeToFloat4(i.vertexColor.g);
|
||||
|
||||
%MAX20% d.extraV2F2 = DecodeToFloat4(i.texcoord1.z);
|
||||
%MAX24% d.extraV2F3 = DecodeToFloat4(i.texcoord1.w);
|
||||
%MAX28% d.extraV2F4 = DecodeToFloat4(i.texcoord2.z);
|
||||
%FX% d.extraV2F5 = DecodeToFloat4(i.texcoord2.w);
|
||||
|
||||
i.texcoord0.zw = data0.xy;
|
||||
i.texcoord1.zw = data0.zw;
|
||||
}
|
||||
|
Reference in New Issue
Block a user