import { RenderPass } from './renderpass.js';
import { RENDER_PASS_TYPE_SHADOWMAP } from '../values.js';
import { ShaderHelper } from '../material/shader/helper.js';

/**
 * Shadow map render pass
 *
 * @public
 */ class ShadowMapPass extends RenderPass {
    /** @internal */ _currentLight;
    /**
   * Creates an instance of ShadowMapPass
   */ constructor(){
        super(RENDER_PASS_TYPE_SHADOWMAP);
        this._currentLight = null;
    }
    /** The light that will be used to render shadow map */ get light() {
        return this._currentLight;
    }
    set light(light) {
        this._currentLight = light;
    }
    /** @internal */ _getGlobalBindGroupHash(ctx) {
        return `${ctx.shadowMapInfo.get(this.light).shaderHash}`;
    }
    /** @internal */ renderItems(ctx, camera, renderQueue) {
        const items = renderQueue.itemList;
        if (items) {
            ctx.drawEnvLight = false;
            ctx.env = null;
            ctx.flip = this.isAutoFlip(ctx);
            ctx.renderPassHash = this.getGlobalBindGroupHash(ctx, camera);
            const bindGroup = ctx.globalBindGroupAllocator.getGlobalBindGroup(ctx);
            ctx.device.setBindGroup(0, bindGroup);
            ShaderHelper.setLightUniformsShadowMap(bindGroup, ctx, this._currentLight);
            ShaderHelper.setCameraUniforms(bindGroup, ctx, camera, true);
            const reverseWinding = camera.worldMatrixDet < 0;
            for (const lit of items.opaque.lit){
                this.drawItemList(lit, ctx, reverseWinding);
            }
            for (const unlit of items.opaque.unlit){
                this.drawItemList(unlit, ctx, reverseWinding);
            }
            for (const lit of items.transmission.lit){
                this.drawItemList(lit, ctx, reverseWinding);
            }
            for (const unlit of items.transmission.unlit){
                this.drawItemList(unlit, ctx, reverseWinding);
            }
        }
    }
}

export { ShadowMapPass };
//# sourceMappingURL=shadowmap_pass.js.map
