Skip to content

Commit

Permalink
slight changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tuurvig committed May 23, 2024
1 parent 1d6283e commit e86eb01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/renderer/VolumeWorld.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export default class VolumeWorld {
linearGradient.addColorStop(0.25, "rgba(28,169,6,0.8827906162464986)");
linearGradient.addColorStop(0.5, "rgba(28,169,6,1)");
linearGradient.addColorStop(1.0, "rgba(255,0,0,1)");
//linearGradient.addColorStop(0, "rgba(1,1,1,0)");
//linearGradient.addColorStop(0.25, "rgba(0,52,127,0.22)");
//linearGradient.addColorStop(0.4, "rgba(255,0,0,1)");
//linearGradient.addColorStop(1.0, "rgba(255,0,0,1)");

ctx.fillStyle = linearGradient;
ctx.fillRect(0, 0, 500, 1);

Expand Down
20 changes: 10 additions & 10 deletions src/renderer/shaders/raymarcher-illustrative.frag
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ GradientApproximation approximateGradient(vec3 pos, float stepSize, vec3 viewRay
vec3 yStep = vec3(0., stepSize * 0.5, 0.);
vec3 zStep = vec3(0., 0., stepSize * 0.5);

ga.gradient.x = sampleVolume(pos + xStep) - sampleVolume(pos - xStep);
ga.gradient.y = sampleVolume(pos + yStep) - sampleVolume(pos - yStep);
ga.gradient.z = sampleVolume(pos + zStep) - sampleVolume(pos - zStep);
ga.gradient.x = sampleVolume(pos - xStep) - sampleVolume(pos + xStep);
ga.gradient.y = sampleVolume(pos - yStep) - sampleVolume(pos + yStep);
ga.gradient.z = sampleVolume(pos - zStep) - sampleVolume(pos + zStep);

ga.magnitude = length(ga.gradient) + 0.00001;
ga.normal = ga.gradient / ga.magnitude;
Expand All @@ -50,7 +50,7 @@ GradientApproximation approximateGradient(vec3 pos, float stepSize, vec3 viewRay

float shadingIntensity(vec3 normal, vec3 lightDir, vec3 viewDir, float diffuse, float specular, float shininess) {
float diff = clamp(dot(normal, -lightDir), 0.0, 1.0);
vec3 halfVector = normalize(-lightDir - viewDir);
vec3 halfVector = normalize(-lightDir + viewDir);
float spec = pow(max(dot(halfVector, normal), 0.0), shininess);

return diff + spec;
Expand Down Expand Up @@ -120,7 +120,7 @@ float lightingImportanceFunction(float magnitude, vec3 normal, vec3 viewDir, vec
const float p1 = 50.;
const float p2 = 5.;
const float p3 = 30.;
vec3 halfVector = normalize(viewDir - lightDir);
vec3 halfVector = normalize(viewDir + lightDir);
float specular = pow(dot(normal, halfVector), p1);
float diffuse = pow(dot(normal, lightDir), p2);
float gradient = pow(1. - magnitude, p3);
Expand Down Expand Up @@ -172,11 +172,11 @@ vec4 raymarchImportanceAware(vec3 rayDir, vec3 lightDir, vec3 startPos, float st

for(int i = 0; i < stepCount && step <= stopDist; ++i) {
float sampleValue = sampleVolume(pos);
float opacity = getOpacityAt(sampleValue, oStart, oEnd);
vec3 color = getColorAt(sampleValue, gStart, gEnd);
//vec4 transfer = getColorAt(sampleValue);
//float opacity = transfer.a;
//vec3 color = transfer.rgb;
//float opacity = getOpacityAt(sampleValue, oStart, oEnd);
//vec3 color = getColorAt(sampleValue, gStart, gEnd);
vec4 transfer = getColorAt(sampleValue);
float opacity = transfer.a;
vec3 color = transfer.rgb;

GradientApproximation ga = approximateGradient(pos, stepSize, viewRay);
float importance = globalImportanceFunction(1., ga.magnitude, ga.normal, viewRay, lightDir);
Expand Down

0 comments on commit e86eb01

Please sign in to comment.