export const FP_SHADER_CHUNK_DECODE_PARS = `
#ifndef FP_SHADER_CHUNK_DECODE_PARS
    #define FP_SHADER_CHUNK_DECODE_PARS

    // don't rely on three.js light number define to ensure that point light calculations are available
    #if NUM_POINT_LIGHTS < 1
        struct PointLight {
            vec3 position;
            vec3 color;
            float distance;
            float decay;
        };
    #endif
    
    // directLight is an out parameter as having it as a return value caused compiler errors on some devices
    void fp_getPointDirectLightIrradiance( const in PointLight pointLight, out IncidentLight directLight, vec3 viewPosition ) {
    
        // TODO consider moving light position transformation to view-space over to CPU
        vec3 lVector = (viewMatrix*vec4(pointLight.position,1.0)).xyz + viewPosition;
        
        directLight.direction = normalize( lVector );
        
        float lightDistance = length( lVector );
        
        directLight.color = pointLight.color;
        directLight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );
        directLight.visible = ( directLight.color != vec3( 0.0 ) );
    }
    
    float convert_depth_to_linear(in float d){
        float d_n = 2.0*d - 1.0;
    
        float f = fp_f_camera_far;
        float n = fp_f_camera_near;
    
        float fn = f*n;
        
        float z_diff = f - n;
        
        float denominator = (f + n - d_n * z_diff );
    
        float z_view = (2.0*fn) / denominator;
    
        return (z_view - n) / z_diff;
    }
    
    ivec2 address_to_data_texture_coordinates(uint address){
        // Lookup texture has 128 width
        uint lookup_index_x = address % 128u;
        uint lookup_index_y = address >> 7;
        
        return ivec2(int(lookup_index_x),int(lookup_index_y));
    }
#endif
`;
