projet-rendu/PainterShader.java
2022-04-14 22:42:57 +02:00

28 lines
662 B
Java

/**
* Simple shader that just copy the interpolated color to the screen,
* taking the depth of the fragment into acount.
*
* @author: cdehais
*/
public class PainterShader extends Shader {
DepthBuffer depth;
public PainterShader(GraphicsWrapper screen) {
super(screen);
depth = new DepthBuffer(screen.getWidth(), screen.getHeight());
}
public void shade(Fragment fragment) {
if (depth.testFragment(fragment)) {
screen.setPixel(fragment.getX(), fragment.getY(), fragment.getColor());
depth.writeFragment(fragment);
}
}
public void reset() {
depth.clear();
}
}