
import defaultRenderPass from '../defaultRenderPass.js';
import sampler2D from '../sampler2D.js';
import shader from '../shader.js';

class shadow extends defaultRenderPass {

	prepare() {

		var randomTexure = kepler.resources.getTexture("rotrandom.png");
		var randomSampler = new sampler2D();
		randomSampler.addTexture(randomTexure);
		
		var depthPasses = this.viewport.system.depthPasses;
		var depthpass = depthPasses[0];

		this.shader = new shader();
		this.shader.createFromFile("shaders/shadow.shader");
		this.shader.setUniform("bias", 0.36   );
		this.shader.setUniform("minVariance", 0.0001 );
		
		this.shader.setUniform("shadowNoiseSampler", randomSampler );
		this.shader.setUniform("lightPosition", depthpass.lightPosition  );
		this.shader.setUniform("shadowDepthSampler", depthpass.framebuffer.getSampler() );
		this.shader.setUniform("lightViewProjection", depthpass.viewProjection );

	}
	
}

export {shadow as default};