#ifndef OPAQUECUSTOMLIGHTMAPOBJECT_BASE #define OPAQUECUSTOMLIGHTMAPOBJECT_BASE #include "./Lighting_Base.hlsl" TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex); TEXTURE2D(_EmisMap); SAMPLER(sampler_EmisMap); TEXTURE2D(_CustomLightmap); SAMPLER(sampler_CustomLightmap); TEXTURE2D(_CustomShadowMask); SAMPLER(sampler_CustomShadowMask); CBUFFER_START(UnityPerMaterial) float4 _MainTex_ST; float4 _EmisMap_ST; half _EmissionMapScale; half4 _SpecularColor; half _SpecularFactor; half _Smoothness; half _LightMapIntensity; float _TillingX; float _TillingY; float _OffsetX; float _OFfsetY; CBUFFER_END struct a2v { half4 vertex : POSITION; half4 normal : NORMAL; half4 tangent: TANGENT; half2 texcoord : TEXCOORD0; float4 lightmapUV : TEXCOORD1; UNITY_VERTEX_INPUT_INSTANCE_ID }; struct v2f { float4 pos : SV_POSITION; half4 uvTex0 : TEXCOORD0; half3 worldPos : TEXCOORD1; half4 worldTangentDir : TEXCOORD2; half4 worldBitangentDir : TEXCOORD3; half4 worldNormalDir : TEXCOORD4; half3 worldViewDir : TEXCOORD5; float4 shadowCoord : TEXCOORD6; #if defined(_SG_EXPFOG) half4 _fogCoord : TEXCOORD7; #endif float4 lightmapUV : TEXCOORD8; UNITY_VERTEX_INPUT_INSTANCE_ID UNITY_VERTEX_OUTPUT_STEREO }; v2f VertexCommon(a2v v) { v2f o = (v2f)0; UNITY_SETUP_INSTANCE_ID(v); UNITY_TRANSFER_INSTANCE_ID(v, o); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); VertexNormalInputs normalInput = GetVertexNormalInputs(v.normal, v.tangent); o.pos = vertexInput.positionCS; o.uvTex0.xy = TRANSFORM_TEX(v.texcoord, _MainTex); half3 worldPos = vertexInput.positionWS; half3 worldNormal = normalInput.normalWS; half3 worldViewDir = GetCameraPositionWS() - worldPos; o.worldViewDir = worldViewDir; o.worldTangentDir = float4(normalInput.tangentWS, worldViewDir.x); o.worldBitangentDir = float4(normalInput.bitangentWS, worldViewDir.y); o.worldNormalDir = float4(normalInput.normalWS, worldViewDir.z); o.worldPos.xyz = worldPos; return o; } // vertex shader inline v2f VertexForwardBase (a2v v) { v2f o = VertexCommon(v); o.lightmapUV.xy = v.lightmapUV.xy * float2(_TillingX, _TillingY) + float2(_OffsetX, _OFfsetY); #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) o.shadowCoord = GetShadowCoord(vertexInput); #endif #if defined(_SG_EXPFOG) CUSTOM_TRANSFER_FOG(o, v.vertex); #endif return o; } half4 FragForwardBase(v2f i) : SV_Target { UNITY_SETUP_INSTANCE_ID(i); UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); float3 worldPos = i.worldPos; half3 worldNormal = normalize(mul(half3(0, 0, 1), half3x3(i.worldTangentDir.xyz, i.worldBitangentDir.xyz, i.worldNormalDir.xyz))); half3 worldViewDir = normalize(half3(i.worldTangentDir.w, i.worldBitangentDir.w, i.worldNormalDir.w)); half4 mainColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uvTex0); half4 emissionCol = SAMPLE_TEXTURE2D(_EmisMap, sampler_EmisMap, i.uvTex0) * _EmissionMapScale; half smoothness = _Smoothness; half3 specularColor = mainColor.a * _SpecularFactor * _SpecularColor; half4 shLight = SAMPLE_TEXTURE2D(_CustomLightmap, sampler_CustomLightmap, i.lightmapUV); float atten = 1; half bakedAtten = SAMPLE_TEXTURE2D(_CustomShadowMask, sampler_CustomShadowMask, i.lightmapUV); atten = min(atten, bakedAtten); half3 finalColor = BlinnPhoneLightingFwdBase(mainColor, worldPos, worldNormal, worldViewDir, shLight.rgb, atten, specularColor, smoothness); finalColor = ApplyDark(finalColor); #if defined(_SG_EXPFOG) CUSTOM_APPLY_FOG(i, finalColor, distance(_WorldSpaceCameraPos, worldPos)); #endif finalColor += emissionCol.rgb; return half4(finalColor,1); } #endif