spotlight

231 阅读1分钟
#if 1 > 0
    struct SpotLight {
        vec3 position;
        vec3 direction;
        vec3 color;
        float distance;
        float decay;
        float coneCos;
        float penumbraCos;
    };
    uniform SpotLight spotLights[ 1 ];
    void getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {
        vec3 lVector = spotLight.position - geometry.position;
        directLight.direction = normalize( lVector );
        float lightDistance = length( lVector );
        float angleCos = dot( directLight.direction, spotLight.direction );
        if ( angleCos > spotLight.coneCos ) {
            float spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );
            directLight.color = spotLight.color;
            directLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );
            directLight.visible = true;
        }
        else {
            directLight.color = vec3( 0.0 );
            directLight.visible = false;
        }
    
    }
#endif

#if ( 1 > 0 ) && defined( RE_Direct )
        SpotLight spotLight;
        #if defined( USE_SHADOWMAP ) && 0 > 0
            SpotLightShadow spotLightShadow;
        #endif
        
        spotLight = spotLights[ 0 ];
        getSpotDirectLightIrradiance( spotLight, geometry, directLight );
        #if defined( USE_SHADOWMAP ) && ( 0 < 0 )
            spotLightShadow = spotLightShadows[ 0 ];
            directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ 0 ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ 0 ] ) : 1.0;
        #endif
        RE_Direct( directLight, geometry, material, reflectedLight );
    #endif