#ifndef __LIGHTINGTEMPLATE_H__ #define __LIGHTINGTEMPLATE_H__ #include "UnityCG.cginc" #include "UnityStandardBRDF.cginc" #include "UnityStandardUtils.cginc" #include "UnityPBSLighting.cginc" uniform uint g_nNumDirLights; //--------------------------------------------------------------------------------------------------------------------------------------------------------- // TODO: clean up.. -va #define MAX_SHADOW_LIGHTS 10 #define MAX_SHADOWMAP_PER_LIGHT 6 #define MAX_DIRECTIONAL_SPLIT 4 #define CUBEMAPFACE_POSITIVE_X 0 #define CUBEMAPFACE_NEGATIVE_X 1 #define CUBEMAPFACE_POSITIVE_Y 2 #define CUBEMAPFACE_NEGATIVE_Y 3 #define CUBEMAPFACE_POSITIVE_Z 4 #define CUBEMAPFACE_NEGATIVE_Z 5 #if defined(SHADER_API_D3D11) # include "ShaderLibrary/API/D3D11.hlsl" #elif defined(SHADER_API_PSSL) # include "ShaderLibrary/API/PSSL.hlsl" #elif defined(SHADER_API_XBOXONE) # include "ShaderLibrary/API/D3D11.hlsl" # include "ShaderLibrary/API/D3D11_1.hlsl" #elif defined(SHADER_API_METAL) # include "ShaderLibrary/API/Metal.hlsl" #else # error unsupported shader api #endif #include "ShaderLibrary/API/Validate.hlsl" #include "Shadow.hlsl" CBUFFER_START(ShadowLightData) float4 g_vShadow3x3PCFTerms0; float4 g_vShadow3x3PCFTerms1; float4 g_vShadow3x3PCFTerms2; float4 g_vShadow3x3PCFTerms3; float4 g_vDirShadowSplitSpheres[MAX_DIRECTIONAL_SPLIT]; float4x4 g_matWorldToShadow[MAX_SHADOW_LIGHTS * MAX_SHADOWMAP_PER_LIGHT]; CBUFFER_END //--------------------------------------------------------------------------------------------------------------------------------------------------------- //UNITY_DECLARE_TEX2D(_LightTextureB0); sampler2D _LightTextureB0; UNITY_DECLARE_TEX2DARRAY(_spotCookieTextures); UNITY_DECLARE_ABSTRACT_CUBE_ARRAY(_pointCookieTextures); StructuredBuffer g_dirLightData; float3 ExecuteLightList(uint start, uint numLights, float3 vP, float3 vPw, float3 Vworld) { UnityIndirect ind; UNITY_INITIALIZE_OUTPUT(UnityIndirect, ind); ind.diffuse = 0; ind.specular = 0; ShadowContext shadowContext = InitShadowContext(); float3 ints = 0; for (int i = 0; i < g_nNumDirLights; i++) { DirectionalLight lightData = g_dirLightData[i]; float atten = 1; UnityLight light; light.dir.xyz = mul((float3x3) g_mViewToWorld, -lightData.lightAxisZ).xyz; int shadowIdx = asint(lightData.shadowLightIndex); [branch] if (shadowIdx >= 0) { float shadow = GetDirectionalShadowAttenuation(shadowContext, vPw, 0.0.xxx, shadowIdx, normalize(light.dir.xyz)); atten *= shadow; } light.color.xyz = lightData.color.xyz * atten; ints += EvalMaterial(light, ind); } uint l=0; // don't need the outer loop since the lights are sorted by volume type //while(l0) { uint uIndex = l0.0); // finally apply this to the dist att. UnityLight light; light.dir.xyz = mul((float3x3) g_mViewToWorld, vL).xyz; //unity_CameraToWorld int shadowIdx = asint(lgtDat.shadowLightIndex); [branch] if (shadowIdx >= 0) { float shadow = GetPunctualShadowAttenuation(shadowContext, vPw, 0.0.xxx, shadowIdx, float4(normalize(light.dir.xyz), dist)); atten *= shadow; } light.color.xyz = lgtDat.color.xyz*atten*angularAtt.xyz; ints += EvalMaterial(light, ind); ++l; uIndex = l= 0) { float shadow = GetPunctualShadowAttenuation(shadowContext, vPw, 0.0.xxx, shadowIdx, float4(vLw, dist)); atten *= shadow; } UnityLight light; light.color.xyz = lgtDat.color.xyz*atten*cookieColor.xyz; light.dir.xyz = vLw; ints += EvalMaterial(light, ind); ++l; uIndex = l