Shader "LWPBRCustom" { Properties { [Head(Lightweight Standard shader)] [MainColor] _BaseColor("Color", Color) = (0.5,0.5,0.5,1) [MainTexture]_TextureSample0("Albedo(R), Alpha(A)", 2D) = "white" {}
[Space(20)] [NoScaleOffset][Normal]_TextureSample1("Normal Texture", 2D) = "bump" {}
[Space(20)] [NoScaleOffset][Gamma]_TextureSample2("Metallic(R), AO(G), Smoothness(A)", 2D) = "black" {} _MInten("Metallic Intensity", Range(0,1)) = 1 _SInten("Smoothness Intensity", Range(0,1)) = 1 _AOInten("Ambient Occlusion Intensity", Range(0,1)) = 1 }
SubShader { Tags { "RenderPipeline"="LightweightPipeline" "RenderType"="Transparnent" "Queue"="Geometry" }
Cull Back HLSLINCLUDE #pragma target 3.0 ENDHLSL Pass { Tags { "LightMode"="LightweightForward" }
Name "Base" Blend One Zero ZWrite On ZTest LEqual Offset 0 , 0 ColorMask RGBA HLSLPROGRAM // Required to compile gles 2.0 with standard srp library #pragma prefer_hlslcc gles #pragma exclude_renderers d3d11_9x
// ------------------------------------- // Lightweight Pipeline keywords #pragma multi_compile _ _MAIN_LIGHT_SHADOWS #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS #pragma multi_compile _ _SHADOWS_SOFT #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE // ------------------------------------- // Unity defined keywords #pragma multi_compile _ DIRLIGHTMAP_COMBINED #pragma multi_compile _ LIGHTMAP_ON #pragma multi_compile_fog
//-------------------------------------- // GPU Instancing #pragma multi_compile_instancing
#pragma vertex vert #pragma fragment frag
#define ASE_SRP_VERSION 51300 #define _NORMALMAP #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.lightweight/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.lightweight/ShaderLibrary/ShaderGraphFunctions.hlsl"
struct VertexInput { float4 vertex : POSITION; float3 normal : NORMAL; float4 tangent : TANGENT; float4 texcoord : TEXCOORD0; float4 texcoord1 : TEXCOORD1; UNITY_VERTEX_INPUT_INSTANCE_ID };
CBUFFER_START(UnityPerMaterial)
uniform sampler2D _TextureSample0; uniform float4 _TextureSample0_ST; uniform sampler2D _TextureSample1; uniform sampler2D _TextureSample2; //uniform float4 _TextureSample1_ST;
half _MInten, _SInten, _AOInten;
CBUFFER_END
struct VertexOutput { float4 clipPos : SV_POSITION; float4 lightmapUVOrVertexSH : TEXCOORD0; half4 fogFactorAndVertexLight : TEXCOORD1; //x: fogFactor, yzw: vertex light float4 shadowCoord : TEXCOORD2; float4 tSpace0 : TEXCOORD3; float4 tSpace1 : TEXCOORD4; float4 tSpace2 : TEXCOORD5; float4 texcoord : TEXCOORD6; UNITY_VERTEX_INPUT_INSTANCE_ID UNITY_VERTEX_OUTPUT_STEREO };
VertexOutput vert (VertexInput v ) { VertexOutput o = (VertexOutput)0; UNITY_SETUP_INSTANCE_ID(v); UNITY_TRANSFER_INSTANCE_ID(v, o); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float3 vertexValue = float3( 0, 0, 0 ) ; #ifdef ASE_ABSOLUTE_VERTEX_POS v.vertex.xyz = vertexValue; #else v.vertex.xyz += vertexValue; #endif v.normal = v.normal ;
o.texcoord.xy = v.texcoord.xy;
// Vertex shader outputs defined by graph float3 lwWNormal = TransformObjectToWorldNormal(v.normal); float3 lwWorldPos = TransformObjectToWorld(v.vertex.xyz); float3 lwWTangent = TransformObjectToWorldDir(v.tangent.xyz); float3 lwWBinormal = normalize(cross(lwWNormal, lwWTangent) * v.tangent.w); o.tSpace0 = float4(lwWTangent.x, lwWBinormal.x, lwWNormal.x, lwWorldPos.x); o.tSpace1 = float4(lwWTangent.y, lwWBinormal.y, lwWNormal.y, lwWorldPos.y); o.tSpace2 = float4(lwWTangent.z, lwWBinormal.z, lwWNormal.z, lwWorldPos.z);
VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); // We either sample GI from lightmap or SH. // Lightmap UV and vertex SH coefficients use the same interpolator ("float2 lightmapUV" for lightmap or "half3 vertexSH" for SH) // see DECLARE_LIGHTMAP_OR_SH macro. // The following funcions initialize the correct variable with correct data
OUTPUT_LIGHTMAP_UV(v.texcoord1, unity_LightmapST, o.lightmapUVOrVertexSH.xy); OUTPUT_SH(lwWNormal, o.lightmapUVOrVertexSH.xyz);
half3 vertexLight = VertexLighting(vertexInput.positionWS, lwWNormal); half fogFactor = ComputeFogFactor(vertexInput.positionCS.z); o.fogFactorAndVertexLight = half4(fogFactor, vertexLight); o.clipPos = vertexInput.positionCS;
#ifdef _MAIN_LIGHT_SHADOWS o.shadowCoord = GetShadowCoord(vertexInput); #endif return o; }
half4 frag (VertexOutput IN ) : SV_Target { UNITY_SETUP_INSTANCE_ID(IN);
float3 WorldSpaceNormal = normalize(float3(IN.tSpace0.z,IN.tSpace1.z,IN.tSpace2.z)); float3 WorldSpaceTangent = float3(IN.tSpace0.x,IN.tSpace1.x,IN.tSpace2.x); float3 WorldSpaceBiTangent = float3(IN.tSpace0.y,IN.tSpace1.y,IN.tSpace2.y); float3 WorldSpacePosition = float3(IN.tSpace0.w,IN.tSpace1.w,IN.tSpace2.w); float3 WorldSpaceViewDirection = SafeNormalize( _WorldSpaceCameraPos.xyz - WorldSpacePosition ); float2 uv_TextureSample0 = IN.texcoord.xy * _TextureSample0_ST.xy + _TextureSample0_ST.zw; float4 Masking = tex2D(_TextureSample2, uv_TextureSample0).rgba; float4 c = tex2D(_TextureSample0, uv_TextureSample0).rgba; float3 Albedo = c.rgb; float3 Normal = UnpackNormal(tex2D(_TextureSample1, uv_TextureSample0 )); float3 Emission = 0; float3 Specular = 0; float Metallic = Masking.r * _MInten; float Smoothness = Masking.a * _SInten; float Occlusion = Masking.g * _AOInten; float Alpha = 1; //float AlphaClipThreshold = 0;
InputData inputData; inputData.positionWS = WorldSpacePosition;
#ifdef _NORMALMAP inputData.normalWS = normalize(TransformTangentToWorld(Normal, half3x3(WorldSpaceTangent, WorldSpaceBiTangent, WorldSpaceNormal))); #else #if !SHADER_HINT_NICE_QUALITY inputData.normalWS = WorldSpaceNormal; #else inputData.normalWS = normalize(WorldSpaceNormal); #endif #endif
#if !SHADER_HINT_NICE_QUALITY // viewDirection should be normalized here, but we avoid doing it as it's close enough and we save some ALU. inputData.viewDirectionWS = WorldSpaceViewDirection; #else inputData.viewDirectionWS = normalize(WorldSpaceViewDirection); #endif
inputData.shadowCoord = IN.shadowCoord;
inputData.fogCoord = IN.fogFactorAndVertexLight.x; inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw; inputData.bakedGI = SAMPLE_GI(IN.lightmapUVOrVertexSH.xy, IN.lightmapUVOrVertexSH.xyz, inputData.normalWS);
half4 color = LightweightFragmentPBR( inputData, Albedo, Metallic, Specular, Smoothness, Occlusion, Emission, Alpha);
#ifdef TERRAIN_SPLAT_ADDPASS color.rgb = MixFogColor(color.rgb, half3( 0, 0, 0 ), IN.fogFactorAndVertexLight.x ); #else color.rgb = MixFog(color.rgb, IN.fogFactorAndVertexLight.x); #endif
/* #if _AlphaClip clip(Alpha - AlphaClipThreshold); #endif #if ASE_LW_FINAL_COLOR_ALPHA_MULTIPLY color.rgb *= color.a; #endif */ return color; }
ENDHLSL }
Pass { Name "ShadowCaster" Tags { "LightMode"="ShadowCaster" }
ZWrite On ZTest LEqual
HLSLPROGRAM // Required to compile gles 2.0 with standard srp library #pragma prefer_hlslcc gles #pragma exclude_renderers d3d11_9x
//-------------------------------------- // GPU Instancing #pragma multi_compile_instancing
#pragma vertex ShadowPassVertex #pragma fragment ShadowPassFragment
#define ASE_SRP_VERSION 51300
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Lighting.hlsl" //#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/ShaderGraphFunctions.hlsl" //#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
struct VertexInput { float4 vertex : POSITION; float3 normal : NORMAL; UNITY_VERTEX_INPUT_INSTANCE_ID };
struct VertexOutput { float4 clipPos : SV_POSITION; UNITY_VERTEX_INPUT_INSTANCE_ID };
// x: global clip space bias, y: normal world space bias float3 _LightDirection;
VertexOutput ShadowPassVertex(VertexInput v ) { VertexOutput o; UNITY_SETUP_INSTANCE_ID(v); UNITY_TRANSFER_INSTANCE_ID(v, o);
float3 vertexValue = float3(0,0,0) ; #ifdef ASE_ABSOLUTE_VERTEX_POS v.vertex.xyz = vertexValue; #else v.vertex.xyz += vertexValue; #endif
v.normal = v.normal ;
float3 positionWS = TransformObjectToWorld(v.vertex.xyz); float3 normalWS = TransformObjectToWorldDir(v.normal);
float invNdotL = 1.0 - saturate(dot(_LightDirection, normalWS)); float scale = invNdotL * _ShadowBias.y;
// normal bias is negative since we want to apply an inset normal offset positionWS = _LightDirection * _ShadowBias.xxx + positionWS; positionWS = normalWS * scale.xxx + positionWS; float4 clipPos = TransformWorldToHClip(positionWS);
// _ShadowBias.x sign depens on if platform has reversed z buffer //clipPos.z += _ShadowBias.x;
#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 o.clipPos = clipPos;
return o; }
half4 ShadowPassFragment(VertexOutput IN ) : SV_TARGET { UNITY_SETUP_INSTANCE_ID(IN);
// float Alpha = 1; // float AlphaClipThreshold = AlphaClipThreshold; /* #if _AlphaClip clip(Alpha - AlphaClipThreshold); #endif */ return 0; }
ENDHLSL }
Pass { Name "DepthOnly" Tags { "LightMode"="DepthOnly" }
ZWrite On ColorMask 0
HLSLPROGRAM // Required to compile gles 2.0 with standard srp library #pragma prefer_hlslcc gles #pragma exclude_renderers d3d11_9x
//-------------------------------------- // GPU Instancing #pragma multi_compile_instancing
#pragma vertex vert #pragma fragment frag
#define ASE_SRP_VERSION 51300
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Lighting.hlsl" //#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/ShaderGraphFunctions.hlsl" //#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
struct VertexInput { float4 vertex : POSITION; float3 normal : NORMAL; UNITY_VERTEX_INPUT_INSTANCE_ID };
struct VertexOutput { float4 clipPos : SV_POSITION; UNITY_VERTEX_INPUT_INSTANCE_ID UNITY_VERTEX_OUTPUT_STEREO };
VertexOutput vert(VertexInput v ) { VertexOutput o = (VertexOutput)0; UNITY_SETUP_INSTANCE_ID(v); UNITY_TRANSFER_INSTANCE_ID(v, o); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float3 vertexValue = float3(0,0,0) ; #ifdef ASE_ABSOLUTE_VERTEX_POS v.vertex.xyz = vertexValue; #else v.vertex.xyz += vertexValue; #endif
v.normal = v.normal ;
o.clipPos = TransformObjectToHClip(v.vertex.xyz); return o; }
half4 frag(VertexOutput IN ) : SV_TARGET { UNITY_SETUP_INSTANCE_ID(IN);
// float Alpha = 1; // float AlphaClipThreshold = AlphaClipThreshold; /* #if _AlphaClip clip(Alpha - AlphaClipThreshold); #endif */ return 0; } ENDHLSL }
// This pass it not used during regular rendering, only for lightmap baking. Pass { Name "Meta" Tags { "LightMode"="Meta" }
Cull Off
HLSLPROGRAM // Required to compile gles 2.0 with standard srp library #pragma prefer_hlslcc gles #pragma exclude_renderers d3d11_9x
#pragma vertex vert #pragma fragment frag
#define ASE_SRP_VERSION 51300
uniform float4 _MainTex_ST; #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/MetaInput.hlsl" //#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/ShaderGraphFunctions.hlsl" //#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
//#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A //#pragma shader_feature EDITOR_VISUALIZATION
struct VertexInput { float4 vertex : POSITION; float3 normal : NORMAL; float4 texcoord1 : TEXCOORD1; float4 texcoord2 : TEXCOORD2; UNITY_VERTEX_INPUT_INSTANCE_ID };
struct VertexOutput { float4 clipPos : SV_POSITION; UNITY_VERTEX_INPUT_INSTANCE_ID UNITY_VERTEX_OUTPUT_STEREO };
VertexOutput vert(VertexInput v ) { VertexOutput o = (VertexOutput)0; UNITY_SETUP_INSTANCE_ID(v); UNITY_TRANSFER_INSTANCE_ID(v, o); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float3 vertexValue = float3(0,0,0) ; #ifdef ASE_ABSOLUTE_VERTEX_POS v.vertex.xyz = vertexValue; #else v.vertex.xyz += vertexValue; #endif
v.normal = v.normal ; o.clipPos = MetaVertexPosition(v.vertex, v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST); return o; }
half4 frag(VertexOutput IN ) : SV_TARGET { UNITY_SETUP_INSTANCE_ID(IN); float3 Albedo = float3(0.5, 0.5, 0.5); float3 Emission = 0; float Alpha = 1; float AlphaClipThreshold = 0; /* #if _AlphaClip clip(Alpha - AlphaClipThreshold); #endif */
MetaInput metaInput = (MetaInput)0; metaInput.Albedo = Albedo; metaInput.Emission = Emission; return MetaFragment(metaInput); } ENDHLSL } } //FallBack "Hidden/InternalErrorShader" //CustomEditor "ASEMaterialInspector" }
|