projet-rendu/PainterShader.java

28 lines
662 B
Java
Raw Normal View History

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