Created
April 17, 2021 06:27
-
-
Save itspacchu/8a9772c6f469812412724d1bbdf0a271 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Made with Amplify Shader Editor | |
// Available at the Unity Asset Store - http://u3d.as/y3X | |
Shader "SubsurfaceTest" | |
{ | |
Properties | |
{ | |
[HideInInspector] _AlphaCutoff("Alpha Cutoff ", Range(0, 1)) = 0.5 | |
[HideInInspector] _EmissionColor("Emission Color", Color) = (1,1,1,1) | |
[ASEBegin]_MainColor("Main Color", Color) = (0.3921569,0.3921569,0.3921569,1) | |
_SpecularColor("Specular Color", Color) = (0.3921569,0.3921569,0.3921569,1) | |
_Shininess("Shininess", Range( 0.01 , 1)) = 0.1 | |
_Float4("Float 4", Float) = 1 | |
_subsurface("subsurface", Float) = 0.6 | |
[ASEEnd]_green_leaves_PNG3615("green_leaves_PNG3615", 2D) = "white" {} | |
[HideInInspector] _texcoord( "", 2D ) = "white" {} | |
//_TessPhongStrength( "Tess Phong Strength", Range( 0, 1 ) ) = 0.5 | |
//_TessValue( "Tess Max Tessellation", Range( 1, 32 ) ) = 16 | |
//_TessMin( "Tess Min Distance", Float ) = 10 | |
//_TessMax( "Tess Max Distance", Float ) = 25 | |
//_TessEdgeLength ( "Tess Edge length", Range( 2, 50 ) ) = 16 | |
//_TessMaxDisp( "Tess Max Displacement", Float ) = 25 | |
} | |
SubShader | |
{ | |
LOD 0 | |
Tags { "RenderPipeline"="UniversalPipeline" "RenderType"="Opaque" "Queue"="Geometry" } | |
Cull Off | |
AlphaToMask Off | |
HLSLINCLUDE | |
#pragma target 2.0 | |
float4 FixedTess( float tessValue ) | |
{ | |
return tessValue; | |
} | |
float CalcDistanceTessFactor (float4 vertex, float minDist, float maxDist, float tess, float4x4 o2w, float3 cameraPos ) | |
{ | |
float3 wpos = mul(o2w,vertex).xyz; | |
float dist = distance (wpos, cameraPos); | |
float f = clamp(1.0 - (dist - minDist) / (maxDist - minDist), 0.01, 1.0) * tess; | |
return f; | |
} | |
float4 CalcTriEdgeTessFactors (float3 triVertexFactors) | |
{ | |
float4 tess; | |
tess.x = 0.5 * (triVertexFactors.y + triVertexFactors.z); | |
tess.y = 0.5 * (triVertexFactors.x + triVertexFactors.z); | |
tess.z = 0.5 * (triVertexFactors.x + triVertexFactors.y); | |
tess.w = (triVertexFactors.x + triVertexFactors.y + triVertexFactors.z) / 3.0f; | |
return tess; | |
} | |
float CalcEdgeTessFactor (float3 wpos0, float3 wpos1, float edgeLen, float3 cameraPos, float4 scParams ) | |
{ | |
float dist = distance (0.5 * (wpos0+wpos1), cameraPos); | |
float len = distance(wpos0, wpos1); | |
float f = max(len * scParams.y / (edgeLen * dist), 1.0); | |
return f; | |
} | |
float DistanceFromPlane (float3 pos, float4 plane) | |
{ | |
float d = dot (float4(pos,1.0f), plane); | |
return d; | |
} | |
bool WorldViewFrustumCull (float3 wpos0, float3 wpos1, float3 wpos2, float cullEps, float4 planes[6] ) | |
{ | |
float4 planeTest; | |
planeTest.x = (( DistanceFromPlane(wpos0, planes[0]) > -cullEps) ? 1.0f : 0.0f ) + | |
(( DistanceFromPlane(wpos1, planes[0]) > -cullEps) ? 1.0f : 0.0f ) + | |
(( DistanceFromPlane(wpos2, planes[0]) > -cullEps) ? 1.0f : 0.0f ); | |
planeTest.y = (( DistanceFromPlane(wpos0, planes[1]) > -cullEps) ? 1.0f : 0.0f ) + | |
(( DistanceFromPlane(wpos1, planes[1]) > -cullEps) ? 1.0f : 0.0f ) + | |
(( DistanceFromPlane(wpos2, planes[1]) > -cullEps) ? 1.0f : 0.0f ); | |
planeTest.z = (( DistanceFromPlane(wpos0, planes[2]) > -cullEps) ? 1.0f : 0.0f ) + | |
(( DistanceFromPlane(wpos1, planes[2]) > -cullEps) ? 1.0f : 0.0f ) + | |
(( DistanceFromPlane(wpos2, planes[2]) > -cullEps) ? 1.0f : 0.0f ); | |
planeTest.w = (( DistanceFromPlane(wpos0, planes[3]) > -cullEps) ? 1.0f : 0.0f ) + | |
(( DistanceFromPlane(wpos1, planes[3]) > -cullEps) ? 1.0f : 0.0f ) + | |
(( DistanceFromPlane(wpos2, planes[3]) > -cullEps) ? 1.0f : 0.0f ); | |
return !all (planeTest); | |
} | |
float4 DistanceBasedTess( float4 v0, float4 v1, float4 v2, float tess, float minDist, float maxDist, float4x4 o2w, float3 cameraPos ) | |
{ | |
float3 f; | |
f.x = CalcDistanceTessFactor (v0,minDist,maxDist,tess,o2w,cameraPos); | |
f.y = CalcDistanceTessFactor (v1,minDist,maxDist,tess,o2w,cameraPos); | |
f.z = CalcDistanceTessFactor (v2,minDist,maxDist,tess,o2w,cameraPos); | |
return CalcTriEdgeTessFactors (f); | |
} | |
float4 EdgeLengthBasedTess( float4 v0, float4 v1, float4 v2, float edgeLength, float4x4 o2w, float3 cameraPos, float4 scParams ) | |
{ | |
float3 pos0 = mul(o2w,v0).xyz; | |
float3 pos1 = mul(o2w,v1).xyz; | |
float3 pos2 = mul(o2w,v2).xyz; | |
float4 tess; | |
tess.x = CalcEdgeTessFactor (pos1, pos2, edgeLength, cameraPos, scParams); | |
tess.y = CalcEdgeTessFactor (pos2, pos0, edgeLength, cameraPos, scParams); | |
tess.z = CalcEdgeTessFactor (pos0, pos1, edgeLength, cameraPos, scParams); | |
tess.w = (tess.x + tess.y + tess.z) / 3.0f; | |
return tess; | |
} | |
float4 EdgeLengthBasedTessCull( float4 v0, float4 v1, float4 v2, float edgeLength, float maxDisplacement, float4x4 o2w, float3 cameraPos, float4 scParams, float4 planes[6] ) | |
{ | |
float3 pos0 = mul(o2w,v0).xyz; | |
float3 pos1 = mul(o2w,v1).xyz; | |
float3 pos2 = mul(o2w,v2).xyz; | |
float4 tess; | |
if (WorldViewFrustumCull(pos0, pos1, pos2, maxDisplacement, planes)) | |
{ | |
tess = 0.0f; | |
} | |
else | |
{ | |
tess.x = CalcEdgeTessFactor (pos1, pos2, edgeLength, cameraPos, scParams); | |
tess.y = CalcEdgeTessFactor (pos2, pos0, edgeLength, cameraPos, scParams); | |
tess.z = CalcEdgeTessFactor (pos0, pos1, edgeLength, cameraPos, scParams); | |
tess.w = (tess.x + tess.y + tess.z) / 3.0f; | |
} | |
return tess; | |
} | |
ENDHLSL | |
Pass | |
{ | |
Name "Forward" | |
Tags { "LightMode"="UniversalForward" } | |
Blend One Zero, One Zero | |
ZWrite On | |
ZTest LEqual | |
Offset 0 , 0 | |
ColorMask RGBA | |
HLSLPROGRAM | |
#pragma multi_compile_instancing | |
#define _ALPHATEST_ON 1 | |
#define ASE_SRP_VERSION 999999 | |
#pragma prefer_hlslcc gles | |
#pragma exclude_renderers d3d11_9x | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" | |
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" | |
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" | |
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl" | |
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" | |
#if ASE_SRP_VERSION <= 70108 | |
#define REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR | |
#endif | |
#define ASE_NEEDS_FRAG_WORLD_POSITION | |
#define ASE_NEEDS_VERT_NORMAL | |
#define ASE_NEEDS_FRAG_SHADOWCOORDS | |
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS | |
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE | |
#pragma multi_compile _ _SHADOWS_SOFT | |
#pragma multi_compile _ DIRLIGHTMAP_COMBINED | |
#pragma multi_compile _ LIGHTMAP_ON | |
#pragma multi_compile_instancing | |
struct VertexInput | |
{ | |
float4 vertex : POSITION; | |
float3 ase_normal : NORMAL; | |
float4 ase_tangent : TANGENT; | |
float4 texcoord1 : TEXCOORD1; | |
float4 ase_texcoord : TEXCOORD0; | |
UNITY_VERTEX_INPUT_INSTANCE_ID | |
}; | |
struct VertexOutput | |
{ | |
float4 clipPos : SV_POSITION; | |
#if defined(ASE_NEEDS_FRAG_WORLD_POSITION) | |
float3 worldPos : TEXCOORD0; | |
#endif | |
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS) | |
float4 shadowCoord : TEXCOORD1; | |
#endif | |
#ifdef ASE_FOG | |
float fogFactor : TEXCOORD2; | |
#endif | |
float4 ase_texcoord3 : TEXCOORD3; | |
float4 ase_texcoord4 : TEXCOORD4; | |
float4 ase_texcoord5 : TEXCOORD5; | |
float4 lightmapUVOrVertexSH : TEXCOORD6; | |
float4 ase_texcoord7 : TEXCOORD7; | |
UNITY_VERTEX_INPUT_INSTANCE_ID | |
UNITY_VERTEX_OUTPUT_STEREO | |
}; | |
CBUFFER_START(UnityPerMaterial) | |
float4 _SpecularColor; | |
float4 _MainColor; | |
float _Shininess; | |
float _subsurface; | |
#ifdef TESSELLATION_ON | |
float _TessPhongStrength; | |
float _TessValue; | |
float _TessMin; | |
float _TessMax; | |
float _TessEdgeLength; | |
float _TessMaxDisp; | |
#endif | |
CBUFFER_END | |
sampler2D _green_leaves_PNG3615; | |
SAMPLER(sampler_green_leaves_PNG3615); | |
UNITY_INSTANCING_BUFFER_START(SubsurfaceTest) | |
UNITY_DEFINE_INSTANCED_PROP(float4, _green_leaves_PNG3615_ST) | |
UNITY_DEFINE_INSTANCED_PROP(float, _Float4) | |
UNITY_INSTANCING_BUFFER_END(SubsurfaceTest) | |
float3 ASEIndirectDiffuse( float2 uvStaticLightmap, float3 normalWS ) | |
{ | |
#ifdef LIGHTMAP_ON | |
return SampleLightmap( uvStaticLightmap, normalWS ); | |
#else | |
return SampleSH(normalWS); | |
#endif | |
} | |
VertexOutput VertexFunction ( VertexInput v ) | |
{ | |
VertexOutput o = (VertexOutput)0; | |
UNITY_SETUP_INSTANCE_ID(v); | |
UNITY_TRANSFER_INSTANCE_ID(v, o); | |
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); | |
float3 ase_worldTangent = TransformObjectToWorldDir(v.ase_tangent.xyz); | |
o.ase_texcoord3.xyz = ase_worldTangent; | |
float3 ase_worldNormal = TransformObjectToWorldNormal(v.ase_normal); | |
o.ase_texcoord4.xyz = ase_worldNormal; | |
float ase_vertexTangentSign = v.ase_tangent.w * unity_WorldTransformParams.w; | |
float3 ase_worldBitangent = cross( ase_worldNormal, ase_worldTangent ) * ase_vertexTangentSign; | |
o.ase_texcoord5.xyz = ase_worldBitangent; | |
OUTPUT_LIGHTMAP_UV( v.texcoord1, unity_LightmapST, o.lightmapUVOrVertexSH.xy ); | |
OUTPUT_SH( ase_worldNormal, o.lightmapUVOrVertexSH.xyz ); | |
o.ase_texcoord7.xy = v.ase_texcoord.xy; | |
//setting value to unused interpolator channels and avoid initialization warnings | |
o.ase_texcoord3.w = 0; | |
o.ase_texcoord4.w = 0; | |
o.ase_texcoord5.w = 0; | |
o.ase_texcoord7.zw = 0; | |
#ifdef ASE_ABSOLUTE_VERTEX_POS | |
float3 defaultVertexValue = v.vertex.xyz; | |
#else | |
float3 defaultVertexValue = float3(0, 0, 0); | |
#endif | |
float3 vertexValue = defaultVertexValue; | |
#ifdef ASE_ABSOLUTE_VERTEX_POS | |
v.vertex.xyz = vertexValue; | |
#else | |
v.vertex.xyz += vertexValue; | |
#endif | |
v.ase_normal = v.ase_normal; | |
float3 positionWS = TransformObjectToWorld( v.vertex.xyz ); | |
float4 positionCS = TransformWorldToHClip( positionWS ); | |
#if defined(ASE_NEEDS_FRAG_WORLD_POSITION) | |
o.worldPos = positionWS; | |
#endif | |
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS) | |
VertexPositionInputs vertexInput = (VertexPositionInputs)0; | |
vertexInput.positionWS = positionWS; | |
vertexInput.positionCS = positionCS; | |
o.shadowCoord = GetShadowCoord( vertexInput ); | |
#endif | |
#ifdef ASE_FOG | |
o.fogFactor = ComputeFogFactor( positionCS.z ); | |
#endif | |
o.clipPos = positionCS; | |
return o; | |
} | |
#if defined(TESSELLATION_ON) | |
struct VertexControl | |
{ | |
float4 vertex : INTERNALTESSPOS; | |
float3 ase_normal : NORMAL; | |
float4 ase_tangent : TANGENT; | |
float4 texcoord1 : TEXCOORD1; | |
float4 ase_texcoord : TEXCOORD0; | |
UNITY_VERTEX_INPUT_INSTANCE_ID | |
}; | |
struct TessellationFactors | |
{ | |
float edge[3] : SV_TessFactor; | |
float inside : SV_InsideTessFactor; | |
}; | |
VertexControl vert ( VertexInput v ) | |
{ | |
VertexControl o; | |
UNITY_SETUP_INSTANCE_ID(v); | |
UNITY_TRANSFER_INSTANCE_ID(v, o); | |
o.vertex = v.vertex; | |
o.ase_normal = v.ase_normal; | |
o.ase_tangent = v.ase_tangent; | |
o.texcoord1 = v.texcoord1; | |
o.ase_texcoord = v.ase_texcoord; | |
return o; | |
} | |
TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v) | |
{ | |
TessellationFactors o; | |
float4 tf = 1; | |
float tessValue = _TessValue; float tessMin = _TessMin; float tessMax = _TessMax; | |
float edgeLength = _TessEdgeLength; float tessMaxDisp = _TessMaxDisp; | |
#if defined(ASE_FIXED_TESSELLATION) | |
tf = FixedTess( tessValue ); | |
#elif defined(ASE_DISTANCE_TESSELLATION) | |
tf = DistanceBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), _WorldSpaceCameraPos ); | |
#elif defined(ASE_LENGTH_TESSELLATION) | |
tf = EdgeLengthBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams ); | |
#elif defined(ASE_LENGTH_CULL_TESSELLATION) | |
tf = EdgeLengthBasedTessCull(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams, unity_CameraWorldClipPlanes ); | |
#endif | |
o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w; | |
return o; | |
} | |
[domain("tri")] | |
[partitioning("fractional_odd")] | |
[outputtopology("triangle_cw")] | |
[patchconstantfunc("TessellationFunction")] | |
[outputcontrolpoints(3)] | |
VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID) | |
{ | |
return patch[id]; | |
} | |
[domain("tri")] | |
VertexOutput DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation) | |
{ | |
VertexInput o = (VertexInput) 0; | |
o.vertex = patch[0].vertex * bary.x + patch[1].vertex * bary.y + patch[2].vertex * bary.z; | |
o.ase_normal = patch[0].ase_normal * bary.x + patch[1].ase_normal * bary.y + patch[2].ase_normal * bary.z; | |
o.ase_tangent = patch[0].ase_tangent * bary.x + patch[1].ase_tangent * bary.y + patch[2].ase_tangent * bary.z; | |
o.texcoord1 = patch[0].texcoord1 * bary.x + patch[1].texcoord1 * bary.y + patch[2].texcoord1 * bary.z; | |
o.ase_texcoord = patch[0].ase_texcoord * bary.x + patch[1].ase_texcoord * bary.y + patch[2].ase_texcoord * bary.z; | |
#if defined(ASE_PHONG_TESSELLATION) | |
float3 pp[3]; | |
for (int i = 0; i < 3; ++i) | |
pp[i] = o.vertex.xyz - patch[i].ase_normal * (dot(o.vertex.xyz, patch[i].ase_normal) - dot(patch[i].vertex.xyz, patch[i].ase_normal)); | |
float phongStrength = _TessPhongStrength; | |
o.vertex.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.vertex.xyz; | |
#endif | |
UNITY_TRANSFER_INSTANCE_ID(patch[0], o); | |
return VertexFunction(o); | |
} | |
#else | |
VertexOutput vert ( VertexInput v ) | |
{ | |
return VertexFunction( v ); | |
} | |
#endif | |
half4 frag ( VertexOutput IN ) : SV_Target | |
{ | |
UNITY_SETUP_INSTANCE_ID( IN ); | |
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX( IN ); | |
#if defined(ASE_NEEDS_FRAG_WORLD_POSITION) | |
float3 WorldPosition = IN.worldPos; | |
#endif | |
float4 ShadowCoords = float4( 0, 0, 0, 0 ); | |
#if defined(ASE_NEEDS_FRAG_SHADOWCOORDS) | |
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) | |
ShadowCoords = IN.shadowCoord; | |
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) | |
ShadowCoords = TransformWorldToShadowCoord( WorldPosition ); | |
#endif | |
#endif | |
float4 temp_output_43_0_g2 = _SpecularColor; | |
float3 ase_worldViewDir = ( _WorldSpaceCameraPos.xyz - WorldPosition ); | |
ase_worldViewDir = normalize(ase_worldViewDir); | |
float3 normalizeResult4_g3 = normalize( ( ase_worldViewDir + _MainLightPosition.xyz ) ); | |
float3 ase_worldTangent = IN.ase_texcoord3.xyz; | |
float3 ase_worldNormal = IN.ase_texcoord4.xyz; | |
float3 ase_worldBitangent = IN.ase_texcoord5.xyz; | |
float3 tanToWorld0 = float3( ase_worldTangent.x, ase_worldBitangent.x, ase_worldNormal.x ); | |
float3 tanToWorld1 = float3( ase_worldTangent.y, ase_worldBitangent.y, ase_worldNormal.y ); | |
float3 tanToWorld2 = float3( ase_worldTangent.z, ase_worldBitangent.z, ase_worldNormal.z ); | |
float3 tanNormal12_g2 = float3(0,0,1); | |
float3 worldNormal12_g2 = float3(dot(tanToWorld0,tanNormal12_g2), dot(tanToWorld1,tanNormal12_g2), dot(tanToWorld2,tanNormal12_g2)); | |
float3 normalizeResult64_g2 = normalize( worldNormal12_g2 ); | |
float dotResult19_g2 = dot( normalizeResult4_g3 , normalizeResult64_g2 ); | |
float ase_lightAtten = 0; | |
Light ase_lightAtten_mainLight = GetMainLight( ShadowCoords ); | |
ase_lightAtten = ase_lightAtten_mainLight.distanceAttenuation * ase_lightAtten_mainLight.shadowAttenuation; | |
float4 temp_output_40_0_g2 = ( _MainLightColor * ase_lightAtten ); | |
float dotResult14_g2 = dot( normalizeResult64_g2 , _MainLightPosition.xyz ); | |
float3 bakedGI34_g2 = ASEIndirectDiffuse( IN.lightmapUVOrVertexSH.xy, normalizeResult64_g2); | |
float4 temp_output_42_0_g2 = _MainColor; | |
float fresnelNdotV15 = dot( ase_worldNormal, ase_worldViewDir ); | |
float fresnelNode15 = ( 0.0 + 3.0 * pow( 1.0 - fresnelNdotV15, 1.0 ) ); | |
float _Float4_Instance = UNITY_ACCESS_INSTANCED_PROP(SubsurfaceTest,_Float4); | |
float dotResult11 = dot( ase_worldViewDir , ( _MainLightPosition.xyz + ( ase_worldNormal * _Float4_Instance ) ) ); | |
float4 color22 = IsGammaSpace() ? float4(0.4449075,1,0.3160377,0) : float4(0.1665441,1,0.08143245,0); | |
float4 _green_leaves_PNG3615_ST_Instance = UNITY_ACCESS_INSTANCED_PROP(SubsurfaceTest,_green_leaves_PNG3615_ST); | |
float2 uv_green_leaves_PNG3615 = IN.ase_texcoord7.xy * _green_leaves_PNG3615_ST_Instance.xy + _green_leaves_PNG3615_ST_Instance.zw; | |
float3 BakedAlbedo = 0; | |
float3 BakedEmission = 0; | |
float3 Color = ( ( ( ( ( float4( (temp_output_43_0_g2).rgb , 0.0 ) * (temp_output_43_0_g2).a * pow( max( dotResult19_g2 , 0.0 ) , ( _Shininess * 128.0 ) ) * temp_output_40_0_g2 ) + ( ( ( temp_output_40_0_g2 * max( dotResult14_g2 , 0.0 ) ) + float4( bakedGI34_g2 , 0.0 ) ) * float4( (temp_output_42_0_g2).rgb , 0.0 ) ) ) * 2.0 ) + ( ( fresnelNode15 * saturate( -dotResult11 ) ) * _subsurface ) ) * color22 ).rgb; | |
float Alpha = tex2D( _green_leaves_PNG3615, uv_green_leaves_PNG3615 ).a; | |
float AlphaClipThreshold = 0.5; | |
float AlphaClipThresholdShadow = 0.5; | |
#ifdef _ALPHATEST_ON | |
clip( Alpha - AlphaClipThreshold ); | |
#endif | |
#ifdef LOD_FADE_CROSSFADE | |
LODDitheringTransition( IN.clipPos.xyz, unity_LODFade.x ); | |
#endif | |
#ifdef ASE_FOG | |
Color = MixFog( Color, IN.fogFactor ); | |
#endif | |
return half4( Color, Alpha ); | |
} | |
ENDHLSL | |
} | |
Pass | |
{ | |
Name "ShadowCaster" | |
Tags { "LightMode"="ShadowCaster" } | |
ZWrite On | |
ZTest LEqual | |
AlphaToMask Off | |
HLSLPROGRAM | |
#pragma multi_compile_instancing | |
#define _ALPHATEST_ON 1 | |
#define ASE_SRP_VERSION 999999 | |
#pragma prefer_hlslcc gles | |
#pragma exclude_renderers d3d11_9x | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" | |
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" | |
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" | |
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" | |
#pragma multi_compile_instancing | |
struct VertexInput | |
{ | |
float4 vertex : POSITION; | |
float3 ase_normal : NORMAL; | |
float4 ase_texcoord : TEXCOORD0; | |
UNITY_VERTEX_INPUT_INSTANCE_ID | |
}; | |
struct VertexOutput | |
{ | |
float4 clipPos : SV_POSITION; | |
#if defined(ASE_NEEDS_FRAG_WORLD_POSITION) | |
float3 worldPos : TEXCOORD0; | |
#endif | |
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS) | |
float4 shadowCoord : TEXCOORD1; | |
#endif | |
float4 ase_texcoord2 : TEXCOORD2; | |
UNITY_VERTEX_INPUT_INSTANCE_ID | |
UNITY_VERTEX_OUTPUT_STEREO | |
}; | |
CBUFFER_START(UnityPerMaterial) | |
float4 _SpecularColor; | |
float4 _MainColor; | |
float _Shininess; | |
float _subsurface; | |
#ifdef TESSELLATION_ON | |
float _TessPhongStrength; | |
float _TessValue; | |
float _TessMin; | |
float _TessMax; | |
float _TessEdgeLength; | |
float _TessMaxDisp; | |
#endif | |
CBUFFER_END | |
sampler2D _green_leaves_PNG3615; | |
SAMPLER(sampler_green_leaves_PNG3615); | |
UNITY_INSTANCING_BUFFER_START(SubsurfaceTest) | |
UNITY_DEFINE_INSTANCED_PROP(float4, _green_leaves_PNG3615_ST) | |
UNITY_INSTANCING_BUFFER_END(SubsurfaceTest) | |
float3 _LightDirection; | |
VertexOutput VertexFunction( VertexInput v ) | |
{ | |
VertexOutput o; | |
UNITY_SETUP_INSTANCE_ID(v); | |
UNITY_TRANSFER_INSTANCE_ID(v, o); | |
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( o ); | |
o.ase_texcoord2.xy = v.ase_texcoord.xy; | |
//setting value to unused interpolator channels and avoid initialization warnings | |
o.ase_texcoord2.zw = 0; | |
#ifdef ASE_ABSOLUTE_VERTEX_POS | |
float3 defaultVertexValue = v.vertex.xyz; | |
#else | |
float3 defaultVertexValue = float3(0, 0, 0); | |
#endif | |
float3 vertexValue = defaultVertexValue; | |
#ifdef ASE_ABSOLUTE_VERTEX_POS | |
v.vertex.xyz = vertexValue; | |
#else | |
v.vertex.xyz += vertexValue; | |
#endif | |
v.ase_normal = v.ase_normal; | |
float3 positionWS = TransformObjectToWorld( v.vertex.xyz ); | |
#if defined(ASE_NEEDS_FRAG_WORLD_POSITION) | |
o.worldPos = positionWS; | |
#endif | |
float3 normalWS = TransformObjectToWorldDir( v.ase_normal ); | |
float4 clipPos = TransformWorldToHClip( ApplyShadowBias( positionWS, normalWS, _LightDirection ) ); | |
#if UNITY_REVERSED_Z | |
clipPos.z = min(clipPos.z, clipPos.w * UNITY_NEAR_CLIP_VALUE); | |
#else | |
clipPos.z = max(clipPos.z, clipPos.w * UNITY_NEAR_CLIP_VALUE); | |
#endif | |
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS) | |
VertexPositionInputs vertexInput = (VertexPositionInputs)0; | |
vertexInput.positionWS = positionWS; | |
vertexInput.positionCS = clipPos; | |
o.shadowCoord = GetShadowCoord( vertexInput ); | |
#endif | |
o.clipPos = clipPos; | |
return o; | |
} | |
#if defined(TESSELLATION_ON) | |
struct VertexControl | |
{ | |
float4 vertex : INTERNALTESSPOS; | |
float3 ase_normal : NORMAL; | |
float4 ase_texcoord : TEXCOORD0; | |
UNITY_VERTEX_INPUT_INSTANCE_ID | |
}; | |
struct TessellationFactors | |
{ | |
float edge[3] : SV_TessFactor; | |
float inside : SV_InsideTessFactor; | |
}; | |
VertexControl vert ( VertexInput v ) | |
{ | |
VertexControl o; | |
UNITY_SETUP_INSTANCE_ID(v); | |
UNITY_TRANSFER_INSTANCE_ID(v, o); | |
o.vertex = v.vertex; | |
o.ase_normal = v.ase_normal; | |
o.ase_texcoord = v.ase_texcoord; | |
return o; | |
} | |
TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v) | |
{ | |
TessellationFactors o; | |
float4 tf = 1; | |
float tessValue = _TessValue; float tessMin = _TessMin; float tessMax = _TessMax; | |
float edgeLength = _TessEdgeLength; float tessMaxDisp = _TessMaxDisp; | |
#if defined(ASE_FIXED_TESSELLATION) | |
tf = FixedTess( tessValue ); | |
#elif defined(ASE_DISTANCE_TESSELLATION) | |
tf = DistanceBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), _WorldSpaceCameraPos ); | |
#elif defined(ASE_LENGTH_TESSELLATION) | |
tf = EdgeLengthBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams ); | |
#elif defined(ASE_LENGTH_CULL_TESSELLATION) | |
tf = EdgeLengthBasedTessCull(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams, unity_CameraWorldClipPlanes ); | |
#endif | |
o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w; | |
return o; | |
} | |
[domain("tri")] | |
[partitioning("fractional_odd")] | |
[outputtopology("triangle_cw")] | |
[patchconstantfunc("TessellationFunction")] | |
[outputcontrolpoints(3)] | |
VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID) | |
{ | |
return patch[id]; | |
} | |
[domain("tri")] | |
VertexOutput DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation) | |
{ | |
VertexInput o = (VertexInput) 0; | |
o.vertex = patch[0].vertex * bary.x + patch[1].vertex * bary.y + patch[2].vertex * bary.z; | |
o.ase_normal = patch[0].ase_normal * bary.x + patch[1].ase_normal * bary.y + patch[2].ase_normal * bary.z; | |
o.ase_texcoord = patch[0].ase_texcoord * bary.x + patch[1].ase_texcoord * bary.y + patch[2].ase_texcoord * bary.z; | |
#if defined(ASE_PHONG_TESSELLATION) | |
float3 pp[3]; | |
for (int i = 0; i < 3; ++i) | |
pp[i] = o.vertex.xyz - patch[i].ase_normal * (dot(o.vertex.xyz, patch[i].ase_normal) - dot(patch[i].vertex.xyz, patch[i].ase_normal)); | |
float phongStrength = _TessPhongStrength; | |
o.vertex.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.vertex.xyz; | |
#endif | |
UNITY_TRANSFER_INSTANCE_ID(patch[0], o); | |
return VertexFunction(o); | |
} | |
#else | |
VertexOutput vert ( VertexInput v ) | |
{ | |
return VertexFunction( v ); | |
} | |
#endif | |
half4 frag(VertexOutput IN ) : SV_TARGET | |
{ | |
UNITY_SETUP_INSTANCE_ID( IN ); | |
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX( IN ); | |
#if defined(ASE_NEEDS_FRAG_WORLD_POSITION) | |
float3 WorldPosition = IN.worldPos; | |
#endif | |
float4 ShadowCoords = float4( 0, 0, 0, 0 ); | |
#if defined(ASE_NEEDS_FRAG_SHADOWCOORDS) | |
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) | |
ShadowCoords = IN.shadowCoord; | |
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) | |
ShadowCoords = TransformWorldToShadowCoord( WorldPosition ); | |
#endif | |
#endif | |
float4 _green_leaves_PNG3615_ST_Instance = UNITY_ACCESS_INSTANCED_PROP(SubsurfaceTest,_green_leaves_PNG3615_ST); | |
float2 uv_green_leaves_PNG3615 = IN.ase_texcoord2.xy * _green_leaves_PNG3615_ST_Instance.xy + _green_leaves_PNG3615_ST_Instance.zw; | |
float Alpha = tex2D( _green_leaves_PNG3615, uv_green_leaves_PNG3615 ).a; | |
float AlphaClipThreshold = 0.5; | |
float AlphaClipThresholdShadow = 0.5; | |
#ifdef _ALPHATEST_ON | |
#ifdef _ALPHATEST_SHADOW_ON | |
clip(Alpha - AlphaClipThresholdShadow); | |
#else | |
clip(Alpha - AlphaClipThreshold); | |
#endif | |
#endif | |
#ifdef LOD_FADE_CROSSFADE | |
LODDitheringTransition( IN.clipPos.xyz, unity_LODFade.x ); | |
#endif | |
return 0; | |
} | |
ENDHLSL | |
} | |
Pass | |
{ | |
Name "DepthOnly" | |
Tags { "LightMode"="DepthOnly" } | |
ZWrite On | |
ColorMask 0 | |
AlphaToMask Off | |
HLSLPROGRAM | |
#pragma multi_compile_instancing | |
#define _ALPHATEST_ON 1 | |
#define ASE_SRP_VERSION 999999 | |
#pragma prefer_hlslcc gles | |
#pragma exclude_renderers d3d11_9x | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" | |
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" | |
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl" | |
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" | |
#pragma multi_compile_instancing | |
struct VertexInput | |
{ | |
float4 vertex : POSITION; | |
float3 ase_normal : NORMAL; | |
float4 ase_texcoord : TEXCOORD0; | |
UNITY_VERTEX_INPUT_INSTANCE_ID | |
}; | |
struct VertexOutput | |
{ | |
float4 clipPos : SV_POSITION; | |
#if defined(ASE_NEEDS_FRAG_WORLD_POSITION) | |
float3 worldPos : TEXCOORD0; | |
#endif | |
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS) | |
float4 shadowCoord : TEXCOORD1; | |
#endif | |
float4 ase_texcoord2 : TEXCOORD2; | |
UNITY_VERTEX_INPUT_INSTANCE_ID | |
UNITY_VERTEX_OUTPUT_STEREO | |
}; | |
CBUFFER_START(UnityPerMaterial) | |
float4 _SpecularColor; | |
float4 _MainColor; | |
float _Shininess; | |
float _subsurface; | |
#ifdef TESSELLATION_ON | |
float _TessPhongStrength; | |
float _TessValue; | |
float _TessMin; | |
float _TessMax; | |
float _TessEdgeLength; | |
float _TessMaxDisp; | |
#endif | |
CBUFFER_END | |
sampler2D _green_leaves_PNG3615; | |
SAMPLER(sampler_green_leaves_PNG3615); | |
UNITY_INSTANCING_BUFFER_START(SubsurfaceTest) | |
UNITY_DEFINE_INSTANCED_PROP(float4, _green_leaves_PNG3615_ST) | |
UNITY_INSTANCING_BUFFER_END(SubsurfaceTest) | |
VertexOutput VertexFunction( VertexInput v ) | |
{ | |
VertexOutput o = (VertexOutput)0; | |
UNITY_SETUP_INSTANCE_ID(v); | |
UNITY_TRANSFER_INSTANCE_ID(v, o); | |
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); | |
o.ase_texcoord2.xy = v.ase_texcoord.xy; | |
//setting value to unused interpolator channels and avoid initialization warnings | |
o.ase_texcoord2.zw = 0; | |
#ifdef ASE_ABSOLUTE_VERTEX_POS | |
float3 defaultVertexValue = v.vertex.xyz; | |
#else | |
float3 defaultVertexValue = float3(0, 0, 0); | |
#endif | |
float3 vertexValue = defaultVertexValue; | |
#ifdef ASE_ABSOLUTE_VERTEX_POS | |
v.vertex.xyz = vertexValue; | |
#else | |
v.vertex.xyz += vertexValue; | |
#endif | |
v.ase_normal = v.ase_normal; | |
float3 positionWS = TransformObjectToWorld( v.vertex.xyz ); | |
#if defined(ASE_NEEDS_FRAG_WORLD_POSITION) | |
o.worldPos = positionWS; | |
#endif | |
o.clipPos = TransformWorldToHClip( positionWS ); | |
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS) | |
VertexPositionInputs vertexInput = (VertexPositionInputs)0; | |
vertexInput.positionWS = positionWS; | |
vertexInput.positionCS = clipPos; | |
o.shadowCoord = GetShadowCoord( vertexInput ); | |
#endif | |
return o; | |
} | |
#if defined(TESSELLATION_ON) | |
struct VertexControl | |
{ | |
float4 vertex : INTERNALTESSPOS; | |
float3 ase_normal : NORMAL; | |
float4 ase_texcoord : TEXCOORD0; | |
UNITY_VERTEX_INPUT_INSTANCE_ID | |
}; | |
struct TessellationFactors | |
{ | |
float edge[3] : SV_TessFactor; | |
float inside : SV_InsideTessFactor; | |
}; | |
VertexControl vert ( VertexInput v ) | |
{ | |
VertexControl o; | |
UNITY_SETUP_INSTANCE_ID(v); | |
UNITY_TRANSFER_INSTANCE_ID(v, o); | |
o.vertex = v.vertex; | |
o.ase_normal = v.ase_normal; | |
o.ase_texcoord = v.ase_texcoord; | |
return o; | |
} | |
TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v) | |
{ | |
TessellationFactors o; | |
float4 tf = 1; | |
float tessValue = _TessValue; float tessMin = _TessMin; float tessMax = _TessMax; | |
float edgeLength = _TessEdgeLength; float tessMaxDisp = _TessMaxDisp; | |
#if defined(ASE_FIXED_TESSELLATION) | |
tf = FixedTess( tessValue ); | |
#elif defined(ASE_DISTANCE_TESSELLATION) | |
tf = DistanceBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), _WorldSpaceCameraPos ); | |
#elif defined(ASE_LENGTH_TESSELLATION) | |
tf = EdgeLengthBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams ); | |
#elif defined(ASE_LENGTH_CULL_TESSELLATION) | |
tf = EdgeLengthBasedTessCull(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams, unity_CameraWorldClipPlanes ); | |
#endif | |
o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w; | |
return o; | |
} | |
[domain("tri")] | |
[partitioning("fractional_odd")] | |
[outputtopology("triangle_cw")] | |
[patchconstantfunc("TessellationFunction")] | |
[outputcontrolpoints(3)] | |
VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID) | |
{ | |
return patch[id]; | |
} | |
[domain("tri")] | |
VertexOutput DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation) | |
{ | |
VertexInput o = (VertexInput) 0; | |
o.vertex = patch[0].vertex * bary.x + patch[1].vertex * bary.y + patch[2].vertex * bary.z; | |
o.ase_normal = patch[0].ase_normal * bary.x + patch[1].ase_normal * bary.y + patch[2].ase_normal * bary.z; | |
o.ase_texcoord = patch[0].ase_texcoord * bary.x + patch[1].ase_texcoord * bary.y + patch[2].ase_texcoord * bary.z; | |
#if defined(ASE_PHONG_TESSELLATION) | |
float3 pp[3]; | |
for (int i = 0; i < 3; ++i) | |
pp[i] = o.vertex.xyz - patch[i].ase_normal * (dot(o.vertex.xyz, patch[i].ase_normal) - dot(patch[i].vertex.xyz, patch[i].ase_normal)); | |
float phongStrength = _TessPhongStrength; | |
o.vertex.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.vertex.xyz; | |
#endif | |
UNITY_TRANSFER_INSTANCE_ID(patch[0], o); | |
return VertexFunction(o); | |
} | |
#else | |
VertexOutput vert ( VertexInput v ) | |
{ | |
return VertexFunction( v ); | |
} | |
#endif | |
half4 frag(VertexOutput IN ) : SV_TARGET | |
{ | |
UNITY_SETUP_INSTANCE_ID(IN); | |
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX( IN ); | |
#if defined(ASE_NEEDS_FRAG_WORLD_POSITION) | |
float3 WorldPosition = IN.worldPos; | |
#endif | |
float4 ShadowCoords = float4( 0, 0, 0, 0 ); | |
#if defined(ASE_NEEDS_FRAG_SHADOWCOORDS) | |
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) | |
ShadowCoords = IN.shadowCoord; | |
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) | |
ShadowCoords = TransformWorldToShadowCoord( WorldPosition ); | |
#endif | |
#endif | |
float4 _green_leaves_PNG3615_ST_Instance = UNITY_ACCESS_INSTANCED_PROP(SubsurfaceTest,_green_leaves_PNG3615_ST); | |
float2 uv_green_leaves_PNG3615 = IN.ase_texcoord2.xy * _green_leaves_PNG3615_ST_Instance.xy + _green_leaves_PNG3615_ST_Instance.zw; | |
float Alpha = tex2D( _green_leaves_PNG3615, uv_green_leaves_PNG3615 ).a; | |
float AlphaClipThreshold = 0.5; | |
#ifdef _ALPHATEST_ON | |
clip(Alpha - AlphaClipThreshold); | |
#endif | |
#ifdef LOD_FADE_CROSSFADE | |
LODDitheringTransition( IN.clipPos.xyz, unity_LODFade.x ); | |
#endif | |
return 0; | |
} | |
ENDHLSL | |
} | |
} | |
CustomEditor "UnityEditor.ShaderGraph.PBRMasterGUI" | |
Fallback "Hidden/InternalErrorShader" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment