相关疑难解决方法(0)

如何正确处理光线追踪中的折射

我目前正在研究光线跟踪器,只是为了好玩而且我在折射处理方面遇到了麻烦.

整个光线跟踪器的代码源可以在Github上找到.

这是渲染的图像:

折射bug

右侧球体的折射率为1.5(玻璃).

在折射的基础上,我想处理一个"透明度"系数,其定义如下:

  • 0 - >对象是100%不透明的
  • 1 - >对象是100%透明(没有原始对象颜色的痕迹)

该球体的透明度为1.

这是处理折射部分的代码.它可以在github上找到.

Color handleTransparency(const Scene& scene,
                         const Ray& ray,
                         const IntersectionData& data,
                         uint8 depth)
{
  Ray refracted(RayType::Transparency, data.point, ray.getDirection());
  Float_t eta = data.material->getRefraction();

  if (eta != 1 && eta > Globals::Epsilon)
    refracted.setDirection(Tools::Refract(ray.getDirection(), data.normal, eta));
  refracted.setOrigin(data.point + Globals::Epsilon * refracted.getDirection());
  return inter(scene, refracted, depth + 1);
}

// http://graphics.stanford.edu/courses/cs148-10-summer/docs/2006--degreve--reflection_refraction.pdf
Float_t getFresnelReflectance(const IntersectionData& data, const Ray& ray)
{
  Float_t n = data.material->getRefraction();
  Float_t cosI = -Tools::DotProduct(ray.getDirection(), data.normal); …
Run Code Online (Sandbox Code Playgroud)

c++ raytracing

22
推荐指数
2
解决办法
2869
查看次数

glsl折射被颠倒映射

我正在glsl中实现折射.我正在使用frag着色器中提供的折射功能来获得所需的效果.但是我得到的折射,它的颠倒.我认为这是错误的......任何想法为什么会如此?

这是我在顶点着色器中所做的:

vec3 worldView = normalize(vec3(WorldCameraPosition-worldPos));
refractor = refract(-worldView, worldNorm, Eta); // eta = 0.66;
Run Code Online (Sandbox Code Playgroud)

然后我做的碎片着色器:

vec4 refractColor = textureCube(cubeMap, refractor); 
Run Code Online (Sandbox Code Playgroud)

http://www.cse.ohio-state.edu/~duttas/Images_5542/Capture.PNG http://www.cse.ohio-state.edu/~duttas/Images_5542/Capture.PNG

opengl shader glsl

7
推荐指数
1
解决办法
3830
查看次数

标签 统计

c++ ×1

glsl ×1

opengl ×1

raytracing ×1

shader ×1