feat: meilleurs affichage

This commit is contained in:
Laureηt 2022-04-19 11:19:30 +02:00
parent f5ac6b8172
commit df59522366
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
2 changed files with 68 additions and 23 deletions

View file

@ -58,6 +58,27 @@ public class Rasterizer {
f.setPosition(f.getY(), f.getX());
}
public void rasterizeVertice(Fragment v1, Fragment v2) {
/* Coordinates of V1 and V2 */
int x1 = v1.getX();
int y1 = v1.getY();
int x2 = v2.getX();
int y2 = v2.getY();
/* For now : just display the vertices */
Fragment f = new Fragment(0, 0);
int size = 2;
for (int i = 0; i < v1.getNumAttributes(); i++) {
f.setAttribute(i, v1.getAttribute(i));
}
for (int i = -size; i <= size; i++) {
for (int j = -size; j <= size; j++) {
f.setPosition(x1 + i, y1 + j);
shader.shade(f);
}
}
}
/**
* Rasterizes the edge between the projected vectors v1 and v2.
* Generates Fragment's and calls the Shader::shade() metho on each of them.
@ -70,19 +91,6 @@ public class Rasterizer {
int x2 = v2.getX();
int y2 = v2.getY();
// /* For now : just display the vertices */
// Fragment f = new Fragment(0, 0);
// int size = 2;
// for (int i = 0; i < v1.getNumAttributes(); i++) {
// f.setAttribute(i, v1.getAttribute(i));
// }
// for (int i = -size; i <= size; i++) {
// for (int j = -size; j <= size; j++) {
// f.setPosition(x1 + i, y1 + j);
// shader.shade(f);
// }
// }
// tracé d'un segment avec l'algo de Bresenham
Fragment fragment = new Fragment(0, 0); // , numAttributes);

View file

@ -23,10 +23,9 @@ public class Renderer {
mesh = new Mesh(scene.getMeshFileName());
screen = new GraphicsWrapper(scene.getScreenW(), scene.getScreenH());
screen.clearBuffer();
// shader = new SimpleShader(screen);
shader = new PainterShader(screen);
rasterizer = new PerspectiveCorrectRasterizer(shader);
// rasterizer = new Rasterizer(shader);
shader = new SimpleShader(screen);
// rasterizer = new PerspectiveCorrectRasterizer(shader);
rasterizer = new Rasterizer(shader);
xform = new Transformation();
xform.setLookAt(scene.getCameraPosition(), scene.getCameraLookAt(), scene.getCameraUp());
@ -89,6 +88,20 @@ public class Renderer {
return fragments;
}
static void renderVertices() {
Fragment[] fragment = projectVertices();
int[] faces = mesh.getFaces();
for (int i = 0; i < 3 * mesh.getNumFaces(); i += 3) {
for (int j = 0; j < 3; j++) {
Fragment v1 = fragment[faces[i + j]];
Fragment v2 = fragment[faces[i + ((j + 1) % 3)]];
rasterizer.rasterizeVertice(v1, v2);
screen.repaint(); // on refresh l'écran
}
}
}
static void renderWireframe() {
Fragment[] fragment = projectVertices();
int[] faces = mesh.getFaces();
@ -142,16 +155,28 @@ public class Renderer {
}
}
/* vertice rendering */
renderVertices();
wait(1);
/* wireframe rendering */
renderWireframe();
// screen.swapBuffers();
wait(1);
/* solid rendering, no lighting */
shader = new SimpleShader(screen);
rasterizer = new Rasterizer(shader);
screen.clearBuffer();
shader.reset();
renderSolid();
wait(1);
/* solid rendering, no lighting */
shader = new PainterShader(screen);
rasterizer = new Rasterizer(shader);
screen.clearBuffer();
shader.reset();
renderSolid();
screen.swapBuffers();
wait(1);
/* solid rendering, with lighting */
@ -159,20 +184,32 @@ public class Renderer {
shader.reset();
setLightingEnabled(true);
renderSolid();
screen.swapBuffers();
wait(1);
/* solid rendering, with texture */
screen.clearBuffer();
/* création du texture shader */
TextureShader texShader = new TextureShader(screen);
texShader.setTexture("data/brick.jpg");
shader = texShader;
/* solid rendering, with texture */
rasterizer = new Rasterizer(shader);
screen.clearBuffer();
shader.reset();
rasterizer.setShader(texShader);
setLightingEnabled(true);
renderSolid();
screen.swapBuffers();
wait(1);
/* solid rendering, with texture */
rasterizer = new PerspectiveCorrectRasterizer(shader);
screen.clearBuffer();
shader.reset();
rasterizer.setShader(texShader);
setLightingEnabled(true);
renderSolid();
wait(1);
// on attend un peu avant de fermer la fenêtre
wait(60);
screen.destroy();
System.exit(0);