/*
- * Sixth - System for data storage, computation, exploration and interaction.
- * Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
+ * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 3 of the GNU Lesser General Public License
* or later as published by the Free Software Foundation.
+ *
*/
package eu.svjatoslav.sixth.e3d.renderer.octree.raytracer;
-import eu.svjatoslav.sixth.e3d.gui.View;
+import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
import eu.svjatoslav.sixth.e3d.renderer.octree.OctreeVolume;
import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
private static final int PROGRESS_UPDATE_FREQUENCY_MILLIS = 1000;
private final Camera camera;
private final Texture texture;
- private final View view;
+ private final ViewPanel viewPanel;
private OctreeVolume octreeVolume;
private Vector<LightSource> lights;
private int computedLights;
public RayTracer(final Texture texture, final OctreeVolume octreeVolume,
final Vector<LightSource> lights, final Camera camera,
- final View view) {
+ final ViewPanel viewPanel) {
this.texture = texture;
this.octreeVolume = octreeVolume;
this.lights = lights;
this.camera = camera;
- this.view = view;
+ this.viewPanel = viewPanel;
}
@Override
nextBitmapUpdate = System.currentTimeMillis()
+ PROGRESS_UPDATE_FREQUENCY_MILLIS;
texture.resetResampledBitmapCache();
- view.repaintDuringNextViewUpdate();
+ viewPanel.repaintDuringNextViewUpdate();
}
}
texture.resetResampledBitmapCache();
- view.repaintDuringNextViewUpdate();
- // System.out.println("Raytracing done.");
- // System.out.println("New lights computed:" + computedLights);
+ viewPanel.repaintDuringNextViewUpdate();
}
- public int traceLight(final LightSource l, final int cubeX,
- final int cubeY, final int cubeZ) {
- return 0;
- }
-
- public int traceRay(final Ray r) {
+ private int traceRay(final Ray ray) {
- final int re = octreeVolume.traceCell(0, 0, 0,
- octreeVolume.masterCellSize, 0, r);
+ final int intersectingCell = octreeVolume.traceCell(0, 0, 0,
+ octreeVolume.masterCellSize, 0, ray);
- if (re != -1) {
+ if (intersectingCell != -1) {
// if lightening not computed, compute it
- if (octreeVolume.ce3[re] == -1)
+ if (octreeVolume.ce3[intersectingCell] == -1)
// if cell is larger than 1
- if (r.hitCellSize > 1) {
+ if (ray.hitCellSize > 1) {
// break it up
- octreeVolume.breakSolidCell(re);
- return traceRay(r);
+ octreeVolume.breakSolidCell(intersectingCell);
+ return traceRay(ray);
} else {
computedLights++;
float red = 30, green = 30, blue = 30;
for (final LightSource l : lights) {
- final int xDist = (l.x - r.hitCellX);
- final int yDist = (l.y - r.hitCellY);
- final int zDist = (l.z - r.hitCellZ);
+ final int xDist = (l.x - ray.hitCellX);
+ final int yDist = (l.y - ray.hitCellY);
+ final int zDist = (l.z - ray.hitCellZ);
double newRed = 0, newGreen = 0, newBlue = 0;
double tempRed, tempGreen, tempBlue;
+ (yDist * yDist) + (zDist * zDist));
distance = (distance / 3) + 1;
- final Ray r1 = new Ray(r.hitCellX, r.hitCellY
- - (float) 1.5, r.hitCellZ,
+ final Ray r1 = new Ray(ray.hitCellX, ray.hitCellY
+ - (float) 1.5, ray.hitCellZ,
- (float) l.x - (float) r.hitCellX, l.y
- - (r.hitCellY - (float) 1.5), (float) l.z
- - (float) r.hitCellZ);
+ (float) l.x - (float) ray.hitCellX, l.y
+ - (ray.hitCellY - (float) 1.5), (float) l.z
+ - (float) ray.hitCellZ);
final int rt1 = octreeVolume.traceCell(0, 0, 0,
octreeVolume.masterCellSize, 0, r1);
newBlue = (l.color.b * l.brightness) / distance;
}
- final Ray r2 = new Ray(r.hitCellX - (float) 1.5,
- r.hitCellY, r.hitCellZ,
+ final Ray r2 = new Ray(ray.hitCellX - (float) 1.5,
+ ray.hitCellY, ray.hitCellZ,
- l.x - (r.hitCellX - (float) 1.5), (float) l.y
- - (float) r.hitCellY, (float) l.z
- - (float) r.hitCellZ);
+ l.x - (ray.hitCellX - (float) 1.5), (float) l.y
+ - (float) ray.hitCellY, (float) l.z
+ - (float) ray.hitCellZ);
final int rt2 = octreeVolume.traceCell(0, 0, 0,
octreeVolume.masterCellSize, 0, r2);
newBlue = tempBlue;
}
- final Ray r3 = new Ray(r.hitCellX, r.hitCellY,
- r.hitCellZ - (float) 1.5,
+ final Ray r3 = new Ray(ray.hitCellX, ray.hitCellY,
+ ray.hitCellZ - (float) 1.5,
- (float) l.x - (float) r.hitCellX, (float) l.y
- - (float) r.hitCellY, l.z
- - (r.hitCellZ - (float) 1.5));
+ (float) l.x - (float) ray.hitCellX, (float) l.y
+ - (float) ray.hitCellY, l.z
+ - (ray.hitCellZ - (float) 1.5));
final int rt3 = octreeVolume.traceCell(0, 0, 0,
octreeVolume.masterCellSize, 0, r3);
newBlue = tempBlue;
}
- final Ray r4 = new Ray(r.hitCellX, r.hitCellY
- + (float) 1.5, r.hitCellZ,
+ final Ray r4 = new Ray(ray.hitCellX, ray.hitCellY
+ + (float) 1.5, ray.hitCellZ,
- (float) l.x - (float) r.hitCellX, l.y
- - (r.hitCellY + (float) 1.5), (float) l.z
- - (float) r.hitCellZ);
+ (float) l.x - (float) ray.hitCellX, l.y
+ - (ray.hitCellY + (float) 1.5), (float) l.z
+ - (float) ray.hitCellZ);
final int rt4 = octreeVolume.traceCell(0, 0, 0,
octreeVolume.masterCellSize, 0, r4);
newBlue = tempBlue;
}
- final Ray r5 = new Ray(r.hitCellX + (float) 1.5,
- r.hitCellY, r.hitCellZ,
+ final Ray r5 = new Ray(ray.hitCellX + (float) 1.5,
+ ray.hitCellY, ray.hitCellZ,
- l.x - (r.hitCellX + (float) 1.5), (float) l.y
- - (float) r.hitCellY, (float) l.z
- - (float) r.hitCellZ);
+ l.x - (ray.hitCellX + (float) 1.5), (float) l.y
+ - (float) ray.hitCellY, (float) l.z
+ - (float) ray.hitCellZ);
final int rt5 = octreeVolume.traceCell(0, 0, 0,
octreeVolume.masterCellSize, 0, r5);
newBlue = tempBlue;
}
- final Ray r6 = new Ray(r.hitCellX, r.hitCellY,
- r.hitCellZ + (float) 1.5,
+ final Ray r6 = new Ray(ray.hitCellX, ray.hitCellY,
+ ray.hitCellZ + (float) 1.5,
- (float) l.x - (float) r.hitCellX, (float) l.y
- - (float) r.hitCellY, l.z
- - (r.hitCellZ + (float) 1.5));
+ (float) l.x - (float) ray.hitCellX, (float) l.y
+ - (float) ray.hitCellY, l.z
+ - (ray.hitCellZ + (float) 1.5));
final int rt6 = octreeVolume.traceCell(0, 0, 0,
octreeVolume.masterCellSize, 0, r6);
}
- final int cellColor = octreeVolume.ce2[re];
+ final int cellColor = octreeVolume.ce2[intersectingCell];
red = (red * ((cellColor & 0xFF0000) >> 16)) / 255;
green = (green * ((cellColor & 0xFF00) >> 8)) / 255;
if (blue > 255)
blue = 255;
- octreeVolume.ce3[re] = (((int) red) << 16)
+ octreeVolume.ce3[intersectingCell] = (((int) red) << 16)
+ (((int) green) << 8) + ((int) blue);
}
- if (octreeVolume.ce3[re] == 0)
- return octreeVolume.ce2[re];
- return octreeVolume.ce3[re];
+ if (octreeVolume.ce3[intersectingCell] == 0)
+ return octreeVolume.ce2[intersectingCell];
+ return octreeVolume.ce3[intersectingCell];
}
// return (200 << 16) + (200 << 8) + 255;