Answer the question
In order to leave comments, you need to log in
RayTracing - what should be the formula for correct surface shading at different angles?
Good evening. I am making PathTracer and ran into a problem:
to calculate the shadows of direct lighting, I get for each pixel its illumination using the formula:
return emissionColor // RGB(255, 255, 255)
.scale(lightPower - rayLine.getLength() * (lightPower / fadeRadius)) // затухание с увеличением расстояния
.scale(lambertCos); // 0 - 1
0 - Vector.dot( // 0 - специально, что бы было заметно отрицательное число
lightDirection, // вектор из точки, для которой рассчитываем освещенность, к источнику света, <b>нормализованный</b>
intersection.getNormal() - нормаль точки, для которой рассчитываем освещенность
);
surfaceCost = Vector.dot(
lightDirection,
shadowRay.getNormal() // нормаль в точке пересечения луча в точке на источнике света
);
return emissionColor // RGB(255, 255, 255)
.scale(lightPower - rayLine.getLength() * (lightPower / fadeRadius)) // затухание с увеличением расстояния
.scale(lambertCos) // 0 - 1
.scale(surfaceCos); // 0 - 1
surfaseCos = 1 - (surfaseCos * (rayline.getDist() * fadeRadius))
Answer the question
In order to leave comments, you need to log in
Well, I sort of fixed it.
The bottom line turned out to be that my final image is assembled from passes (for each pixel):
surface color, pass - black and white direct lighting mask, direct lighting pass (combined 1st 2 passes), ambient occlusion pass and global illumination pass .
When calculating the global illumination pass, I recursively take the global illumination data for the next iterations.
And then there was a bug: if the point for which the illumination was calculated was a light source, I simply returned the source color (emission color), but I also had to assign the necessary colors to the corresponding pass variables, because the variable data of each pass is used in previous iterations:
this.surfaceColor = intersection.getOwner().getMaterial().getEmission().getEmissionColor();
this.lightSamplingColor = RGBColor.WHITE;
this.ambientOcclusionColor = this.lightSamplingColor;
this.globalIlluminationColor = this.surfaceColor;
return this.surfaceColor;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question