Skip to content

Commit

Permalink
Improve color rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
ricktu288 committed Aug 30, 2022
1 parent c81af49 commit c115d47
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions simulator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4357,7 +4357,12 @@ var canvasPainter = {
if (graphs.intersection_is_on_ray(observed_intersection, graphs.ray(observed_point, waitingRays[j].p1)) && graphs.length_squared(observed_point, waitingRays[j].p1) > 1e-5)
{

ctx.globalAlpha = alpha0 * ((waitingRays[j].brightness_s + waitingRays[j].brightness_p) + (last_ray.brightness_s + last_ray.brightness_p)) * 0.5;

if (colorMode) {
var color = wavelengthToColor(waitingRays[j].wavelength, (waitingRays[j].brightness_s + waitingRays[j].brightness_p) * 0.5);
} else {
ctx.globalAlpha = alpha0 * ((waitingRays[j].brightness_s + waitingRays[j].brightness_p) + (last_ray.brightness_s + last_ray.brightness_p)) * 0.5;
}
if (s_point)
{
rpd = (observed_intersection.x - waitingRays[j].p1.x) * (s_point.x - waitingRays[j].p1.x) + (observed_intersection.y - waitingRays[j].p1.y) * (s_point.y - waitingRays[j].p1.y);
Expand Down Expand Up @@ -4444,7 +4449,11 @@ var canvasPainter = {
observed_intersection = graphs.intersection_2line(waitingRays[j], last_ray);
if (last_intersection && graphs.length_squared(last_intersection, observed_intersection) < 25)
{
ctx.globalAlpha = alpha0 * ((waitingRays[j].brightness_s + waitingRays[j].brightness_p) + (last_ray.brightness_s + last_ray.brightness_p)) * 0.5;
if (colorMode) {
var color = wavelengthToColor(waitingRays[j].wavelength, (waitingRays[j].brightness_s + waitingRays[j].brightness_p) * 0.5);
} else {
ctx.globalAlpha = alpha0 * ((waitingRays[j].brightness_s + waitingRays[j].brightness_p) + (last_ray.brightness_s + last_ray.brightness_p)) * 0.5;
}

if (s_point)
{
Expand Down Expand Up @@ -4526,7 +4535,7 @@ var canvasPainter = {
}

}
if (colorMode) {
if (colorMode && ctx.constructor != C2S) {
//var gammaCorrection = 0.2;
var imageData = ctx.getImageData(0.0, 0.0, canvas.width, canvas.height);
var data = imageData.data;
Expand Down Expand Up @@ -6227,9 +6236,11 @@ var canvasPainter = {
G *= alpha * brightness;
B *= alpha * brightness;

R = 1 - Math.exp(-R);
G = 1 - Math.exp(-G);
B = 1 - Math.exp(-B);
if (ctx.constructor != C2S) {
R = 1 - Math.exp(-R);
G = 1 - Math.exp(-G);
B = 1 - Math.exp(-B);
}

return "rgb(" + (R * 100) + "%," + (G * 100) + "%," + (B * 100) + "%)";

Expand Down

0 comments on commit c115d47

Please sign in to comment.