half4 ComputeLightingBase(half3 N, half3 L, half3 V, float spec) { half4 result = 0; half NdotL = dot(N, L); half NdotL_sat = saturate(NdotL); // nieujemne result.xyz += NdotL_sat; if (NdotL > 0) { float3 H = normalize(V+L); float NdotH = dot(N, H); if(NdotH > 0) { #if 1 spec = pow(2, 1+spec * 10); result.w = pow(NdotH, spec); result.w *= (spec+8) / 8; #else spec = pow(2, spec * 10); float qqq = 1/(NdotH*NdotH)-1; result.w = exp(-qqq*spec); result.w *= spec / 4 + 1; #endif } } return result; } half4 ComputeLighting(half3 N, half3 L, half3 V, half spec) { if(spec < .25) { half4 result = 0; half NdotL = dot(N, L); if(NdotL < 0) { half strength = 1 - spec / .25; NdotL = NdotL * -strength; } result.xyz = NdotL; result.w = 0; return result; } else { return ComputeLightingBase(N, L, V, (spec - .25) / .75); } } // zanik swiatla po odleglosci half ComputeRangeAtt(float3 vLightWS, float fLightRange_rcp) { half3 dist = vLightWS * fLightRange_rcp; return saturate(1 - dot(dist, dist)); //return smoothstep(0, 1, 1-saturate(length(vLightWS) / fLightRange)); } // zanik swiatla stozkowego half ComputeSpotAtt(float3 vLight, float3 vLightDir, float4 AttenuationParams) { float angle = dot(vLight, -vLightDir.xyz); //return saturate((angle - AttenuationParams.y) / (AttenuationParams.x - AttenuationParams.y)); return saturate(angle * AttenuationParams.w + AttenuationParams.z); }