Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Ich denke die verbleibende Branch dürfte wohl meistens ihren Performanceverlust ungefähr aufwiegen.. das dürfte aber stark variieren je nach Grafikkarte und Szene. Es wäre sicher einen Versuch wert die auch mal wegzulassen.Zitat
Here is an optimized version of the previous pixel shader suggested by one of the forum members in this topic This version removes one dynamic branching and seriously improves the code speed (there are about 100 FPS of difference between both pixel shaders!!!):
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
////////////////////////////////////////////////////////////////// //Spotlicht berechnen float4 SpotLightDiffuse(float3 vLightPosition, float3 vSpotDir, float4 LightColor, float fAttenuation0, float fAttenuation1, float fCosHalfPhi, float fCosHalfTheta, float fFalloff, float3 vPosition, float3 vNormal) { float3 vNegLightDir= vLightPosition - vPosition; float3 vNormalizedNegLightDir= normalize(vNegLightDir); float fIntensity= saturate(dot(vNormal, vNormalizedNegLightDir)); float fSpotStencil= pow( (saturate(-dot(vSpotDir, vNormalizedNegLightDir) - fCosHalfPhi)) / (fCosHalfTheta - fCosHalfPhi), fFalloff); float fAttenuation= saturate(1 / (fAttenuation0 + fAttenuation1 * length(vNegLightDir))); return(fSpotStencil * fIntensity * fAttenuation * LightColor); } float4 SpotLightSpecular(float3 vLightPosition, float3 vSpotDir, float4 LightColor, float fAttenuation0, float fAttenuation1, float fCosHalfPhi, float fCosHalfTheta, float fFalloff, float3 vPosition, float3 vNormal, float fPower, float3 vViewDir) { float3 vNegLightDir= vLightPosition - vPosition; float3 vNormalizedNegLightDir= normalize(vNegLightDir); float fIntensity= pow(saturate( dot(reflect(vNormalizedNegLightDir, vNormal), vViewDir) ), fPower); float fSpotStencil= pow( (saturate(-dot(vSpotDir, vNormalizedNegLightDir) - fCosHalfPhi)) / (fCosHalfTheta - fCosHalfPhi), fFalloff); float fAttenuation= saturate(1 / (fAttenuation0 + fAttenuation1 * length(vNegLightDir))); return(fSpotStencil * fIntensity * fAttenuation * LightColor); } |
Werbeanzeige