Fix view ratio, fix lighting for gray sphere
This commit is contained in:
parent
e813d33357
commit
653f0cafcb
2 changed files with 15 additions and 8 deletions
|
@ -106,17 +106,20 @@ std::vector<unsigned char> Ex02::RT::renderGraySphere(
|
|||
std::vector<unsigned char> grayscalePixels;
|
||||
grayscalePixels.resize(outputWidth * outputHeight);
|
||||
glm::vec3 rayPos{0.0f, 0.0f, 0.0f};
|
||||
float lightFalloffStart = 4.5f;
|
||||
float lightFalloffEnd = 7.0f;
|
||||
if(threadCount == 1) {
|
||||
for(unsigned int j = 0; j < outputHeight; ++j) {
|
||||
float offsetY = ((float)j + 0.5f - ((float)outputHeight / 2.0f));
|
||||
for(unsigned int i = 0; i < outputWidth; ++i) {
|
||||
float offsetX = ((float)i + 0.5f - ((float)outputWidth / 2.0f));
|
||||
glm::vec3 rayDir = glm::vec3{
|
||||
offsetX, offsetY, -EX02_RAY_TRACER_DRAW_PLANE};
|
||||
offsetX, offsetY, -(float)outputHeight * EX02_RAY_TRACER_VIEW_RATIO};
|
||||
auto rayResult = Internal::rayToSphere(
|
||||
rayPos, rayDir, spherePos, sphereRadius);
|
||||
if(rayResult) {
|
||||
glm::vec3 toLight = lightPos - *rayResult;
|
||||
glm::vec3 toLightCached = toLight;
|
||||
toLight /= std::sqrt(
|
||||
toLight.x * toLight.x
|
||||
+ toLight.y * toLight.y
|
||||
|
@ -128,13 +131,17 @@ std::vector<unsigned char> Ex02::RT::renderGraySphere(
|
|||
continue;
|
||||
}
|
||||
|
||||
glm::vec3 resultToOrigin = rayPos - *rayResult;
|
||||
float angle = Internal::angleBetweenRays(
|
||||
toLight,
|
||||
resultToOrigin);
|
||||
if(angle <= PI && angle >= 0.0f) {
|
||||
float dist = std::sqrt(
|
||||
toLightCached.x * toLightCached.x
|
||||
+ toLightCached.y * toLightCached.y
|
||||
+ toLightCached.z * toLightCached.z);
|
||||
if(dist < lightFalloffStart) {
|
||||
grayscalePixels.at(i + j * outputWidth) = 255;
|
||||
} else if(dist >= lightFalloffStart && dist <= lightFalloffEnd) {
|
||||
grayscalePixels.at(i + j * outputWidth) =
|
||||
(angle / PI) * 255.0f;
|
||||
(1.0f - (dist - lightFalloffStart)
|
||||
/ (lightFalloffEnd - lightFalloffStart))
|
||||
* 255.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef EX02_RAY_TRACER_HPP
|
||||
#define EX02_RAY_TRACER_HPP
|
||||
|
||||
#define EX02_RAY_TRACER_DRAW_PLANE 500.0f
|
||||
#define EX02_RAY_TRACER_VIEW_RATIO 0.5f
|
||||
#define EX02_RAY_TRACER_DEFAULT_NEAR_PLANE 0.2f
|
||||
#define EX02_RAY_TRACER_DEFAULT_FAR_PLANE 4.0f
|
||||
#define EX02_RAY_TRACER_COLL_INCREMENT 2.0f
|
||||
|
|
Loading…
Reference in a new issue