- "m_FunctionBody": "Diffuse = MainDiffuse;\r\nSpecular = MainSpecular;\r\nColor = MainColor * (MainDiffuse + MainSpecular);\r\n\r\n#ifndef SHADERGRAPH_PREVIEW\r\n \r\n uint pixelLightCount = GetAdditionalLightsCount();\r\n half Roughness = pow(1 - Smoothness, 2);\r\n half Roughness2 = Roughness * Roughness;\r\n\thalf Roughness2Minus1 = Roughness2 - 1;\r\n\thalf normalizationTerm = (Roughness * half(4.0) + half(2.0));\r\n\r\n#if USE_CLUSTER_LIGHT_LOOP\r\n // for Foward+ LIGHT_LOOP_BEGIN macro uses inputData.normalizedScreenSpaceUV and inputData.positionWS\r\n InputData inputData = (InputData)0;\r\r\n inputData.normalizedScreenSpaceUV = ScreenPosition;\r\n inputData.positionWS = WorldPosition;\r\n#endif\r\n\r\n LIGHT_LOOP_BEGIN(pixelLightCount)\r\n\t\t// Convert the pixel light index to the light data index\r\n\t\t#if !USE_CLUSTER_LIGHT_LOOP\r\n\t\t\tlightIndex = GetPerObjectLightIndex(lightIndex);\r\n\t\t#endif\r\n\t\t// Call the URP additional light algorithm. This will not calculate shadows, since we don't pass a shadow mask value\r\n\t\tLight light = GetAdditionalPerObjectLight(lightIndex, WorldPosition);\r\n\t\t// Manually set the shadow attenuation by calculating realtime shadows\r\n\t\tlight.shadowAttenuation = AdditionalLightRealtimeShadow(lightIndex, WorldPosition, light.direction);\r\n #if defined(_LIGHT_COOKIES)\r\n float3 cookieColor = SampleAdditionalLightCookie(lightIndex, WorldPosition);\r\n light.color *= cookieColor;\r\n #endif\r\n float NdotL = saturate(dot(WorldNormal, light.direction));\r\n float atten = light.distanceAttenuation * light.shadowAttenuation;\r\n float thisDiffuse = NdotL * atten;\r\n //DirectBRDFSpecular\r\n\r\n float3 lightDirectionWSFloat3 = float3(light.direction);\r\n float3 halfDir = SafeNormalize(lightDirectionWSFloat3 + float3(WorldView));\r\n float NoH = saturate(dot(float3(WorldNormal), halfDir));\r\n half LoH = half(saturate(dot(lightDirectionWSFloat3, halfDir)));\r\n float d = NoH * NoH * Roughness2Minus1 + 1.00001f;\r\n half LoH2 = LoH * LoH;\r\n half spec = Roughness2 / ((d * d) * max(0.1h, LoH2) * normalizationTerm);\r\n #if REAL_IS_HALF\r\n spec = spec - HALF_MIN;\r\n spec = clamp(spec, 0.0, 1000.0);\r\n #endif\t\t\r\n float3 thisSpecular = spec * Reflectance * NdotL * atten;\r\n\r\n Diffuse += thisDiffuse;\r\n Specular += thisSpecular;\r\n\r\n Color += light.color * (thisDiffuse + thisSpecular);\r\n LIGHT_LOOP_END\r\n float total = Diffuse + dot(Specular, float3(0.333, 0.333, 0.333));\r\n Color = total <= 0 ? MainColor : Color / total;\r\n#endif"
0 commit comments