136 lines
4.7 KiB
HLSL
136 lines
4.7 KiB
HLSL
//Unity Toon Shader/HDRP
|
|
//nobuyuki@unity3d.com
|
|
//toshiyuki@unity3d.com (Universal RP/HDRP)
|
|
|
|
#undef unity_ObjectToWorld
|
|
#undef unity_WorldToObject
|
|
|
|
float4 _LightColor0; // not referenced in c# code ??
|
|
|
|
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl"
|
|
|
|
// PackedVaryingsType
|
|
// https://github.com/Unity-Technologies/Graphics/blob/e4117c07b479adafed38237f3407a363eefb4590/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl#L120
|
|
|
|
PackedVaryingsType Vert(AttributesMesh inputMesh, AttributesPass inputPass)
|
|
{
|
|
// VaryingsType
|
|
// https://github.com/Unity-Technologies/Graphics/blob/e4117c07b479adafed38237f3407a363eefb4590/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl#L118
|
|
|
|
VaryingsType varyingsType;
|
|
varyingsType.vmesh = VertMesh(inputMesh);
|
|
varyingsType.vmesh.
|
|
#include "HDRPToonOutlineVertMain.hlsl"
|
|
|
|
return MotionVectorVS(varyingsType, inputMesh, inputPass);
|
|
}
|
|
|
|
#else // _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl"
|
|
|
|
PackedVaryingsType Vert(AttributesMesh inputMesh)
|
|
{
|
|
VaryingsType varyingsType;
|
|
varyingsType.vmesh = VertMesh(inputMesh);
|
|
#include "HDRPToonOutlineVertMain.hlsl"
|
|
|
|
return PackVaryingsType(varyingsType);
|
|
}
|
|
|
|
#endif // _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
#define VT_BUFFER_TARGET SV_Target1
|
|
#define EXTRA_BUFFER_TARGET SV_Target2
|
|
#else
|
|
#define EXTRA_BUFFER_TARGET SV_Target1
|
|
#endif
|
|
|
|
|
|
|
|
void Frag(PackedVaryingsToPS packedInput,
|
|
#ifdef OUTPUT_SPLIT_LIGHTING
|
|
out float4 outColor : SV_Target0, // outSpecularLighting
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
out float4 outVTFeedback : VT_BUFFER_TARGET,
|
|
#endif
|
|
out float4 outDiffuseLighting : EXTRA_BUFFER_TARGET,
|
|
OUTPUT_SSSBUFFER(outSSSBuffer)
|
|
#else
|
|
out float4 outColor : SV_Target0
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
, out float4 outVTFeedback : VT_BUFFER_TARGET
|
|
#endif
|
|
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
, out float4 outMotionVec : EXTRA_BUFFER_TARGET
|
|
#endif // _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
#endif // OUTPUT_SPLIT_LIGHTING
|
|
#ifdef _DEPTHOFFSET_ON
|
|
, out float outputDepth : SV_Depth
|
|
#endif
|
|
)
|
|
|
|
{
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
|
|
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
|
|
#ifdef _IS_CLIPPING_MASK
|
|
if (_ClippingMaskMode != 0)
|
|
{
|
|
discard;
|
|
}
|
|
#endif
|
|
#ifdef _IS_CLIPPING_MATTE
|
|
if (_ClippingMatteMode != 0)
|
|
{
|
|
discard;
|
|
}
|
|
#endif // _IS_CLIPPING_MATTE
|
|
#if defined(UTS_DEBUG_SHADOWMAP_NO_OUTLINE)
|
|
discard;
|
|
#endif
|
|
|
|
float4 objPos = mul(unity_ObjectToWorld, float4(0, 0, 0, 1));
|
|
float4 uv0 = input.texCoord0;
|
|
|
|
float3 envLightSource_GradientEquator = ShadeSH9(float4(0, 1, 0, 0));
|
|
float3 envLightSource_SkyboxIntensity = max(
|
|
SampleBakedGI_UTS_OutLine(objPos.xyz, float3(0.0, 1.0, 0.0), input.texCoord1.xy, input.texCoord2.xy),
|
|
SampleBakedGI_UTS_OutLine(objPos.xyz, float3(0.0, -1.0, -0.0), input.texCoord1.xy, input.texCoord2.xy)
|
|
).rgb;
|
|
float3 ambientSkyColor = envLightSource_SkyboxIntensity.rgb > 0.0 ? envLightSource_SkyboxIntensity : envLightSource_GradientEquator;
|
|
ambientSkyColor *= GetCurrentExposureMultiplier() * _SkyColorIntensity;
|
|
|
|
float3 baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, TRANSFORM_TEX(uv0, _BaseColorMap)).rgb;
|
|
baseColor *= _BaseColor.rgb;
|
|
|
|
float4 outlineColor = _OutlineColor;
|
|
outlineColor.rgb = lerp(outlineColor.rgb, outlineColor.rgb + ambientSkyColor, _SkyColorAffectOutline);
|
|
#if _OUTLINECOLORMAP
|
|
outlineColor *= SAMPLE_TEXTURE2D(_OutlineColorMap, sampler_OutlineColorMap, TRANSFORM_TEX(uv0, _BaseColorMap)).rgb;
|
|
#endif
|
|
outlineColor.rgb = lerp(outlineColor.rgb, outlineColor.rgb * baseColor, _AlbedoAffectOutline);
|
|
|
|
float3 volColor, volOpacity;
|
|
|
|
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
|
|
// input.positionSS is SV_Position
|
|
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
|
|
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
|
|
|
EvaluateAtmosphericScattering(posInput, V, volColor, volOpacity); // Premultiplied alpha
|
|
outlineColor.rgb = outlineColor.rgb * (1 - volOpacity) + volColor;
|
|
outColor = outlineColor;
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
outputDepth = posInput.deviceDepth;
|
|
#endif
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
outVTFeedback = builtinData.vtPackedFeedback;
|
|
#endif
|
|
}
|
|
// End of File
|
|
|