Untitled
unknown
plain_text
2 years ago
2.2 kB
4
Indexable
glm::vec4 refractColor = glm::vec4(0.f,0.f,0.f,0.f); if(m_config.enableRefraction){ if(currentRecursiveLevelRefr <= 3){ glm::vec3 normal = glm::normalize(normalInWorldSpace); glm::vec3 directionToCamera = glm::normalize(-currRay.d); float ior = material.ior; float dotProduct = glm::dot(normal,directionToCamera); float ior1 = 1.f, ior2 = ior; float ratio = ior1 / ior2; float k = 1.f - ratio * ratio * (1.f - dotProduct * dotProduct); glm::vec3 refractedDirection = glm::vec4(0.f,0.f,0.f,0.f); if(k>=0.f){ refractedDirection = glm::normalize(ratio * directionToCamera - (ratio * dotProduct + sqrtf(k)) * normal); } float epsilon = 0.001f; glm::vec3 refractedStartingPt = positionInWorldSpace + epsilon*refractedDirection; ray transmittedRay = ray{.eye =glm::vec4(refractedStartingPt,1.f), .d=glm::vec4(refractedDirection,0.f)}; int recursiveLevel = currentRecursiveLevelRefr+1; auto [refrPixel, newIntersectPoint] = traceRay(transmittedRay, scene, true, currentRecursiveLevelRefl, recursiveLevel); if(newIntersectPoint.isValid &&(newIntersectPoint.t > 0.01) && (newIntersectPoint.t < std::numeric_limits<float>::infinity())){ refractColor[0] = clamp(0.f,1.f,refrPixel[0]); refractColor[1] = clamp(0.f,1.f,refrPixel[1]); refractColor[2] = clamp(0.f,1.f,refrPixel[2]); refractColor[3] = clamp(0.f,1.f,refrPixel[3]); } } } std::cout<< "r:" << refractColor[0] << "\n" << std::endl; std::cout<< "g:" << refractColor[1] << "\n" << std::endl; std::cout<< "b:" << refractColor[2] << "\n" << std::endl; glm::vec4 pixel = directIllumination + (scene.getGlobalData().ks * material.cReflective * reflColor) + (scene.getGlobalData().kt * material.cTransparent * refractColor); return std::make_tuple(pixel, best_t_value_point); }
Editor is loading...