天道酬勤,学无止境

raytracing

Webgl: alternative to writing to gl_FragDepth

In WebGL, is it possible to write to the fragment's depth value or control the fragment's depth value in some other way? As far as I could find, gl_FragDepth is not present in webgl 1.x, but I am wondering if there is any other way (extensions, browser specific support, etc) to do it. What I want to archive is to have a ray traced object play along with other elements drawn using the usual model, view, projection.

2021-06-15 06:18:06    分类:问答    glsl   webgl   raytracing   fragment-shader   depth-buffer

Why does raytracer render spheres as ovals?

I've been hacking up a raytracer for the first time over the past few days. However, there are a few quirks which bother me and I don't really know how to work out. One that has been there since the beginning is the shape of spheres in the scene - when rendered, they actually look like ovals. Of course, there is perspective in the scene, but the final shape still seems odd. I have attached a sample rendering, the problem I have is especially visible on the reflective sphere in the lower left part of the image. I don't really know what could be causing this. It might be the ray-sphere

2021-06-14 07:34:24    分类:问答    c++   geometry   intersection   raytracing

光线追踪中的折射?(Refraction in Raytracing?)

问题 我一直在研究我的光线追踪器。 我添加了反射和多线程支持。 目前我正在努力添加折射,但它只有一半工作。 如您所见,有一个中心球体(没有镜面高光)、一个反射球体(右侧)和一个折射球体(左侧)。 我对反射很满意,它看起来确实很好。 对于折射它有点工作......光线被折射并且球体的所有阴影在球体中都可见(折射率1.4),但有一个外部黑色环。 编辑:显然,当我增加球体的折射率时,黑色环变大,因此球体变小。 相反,当降低折射率时,球体变大,黑环变小……直到将折射率设置为 1,环完全消失。 IOR = 1.9 IOR = 1.1 IOR = 1.00001 有趣的是,当 IOR = 1 时,球体失去透明度并变成白色。 我想我涵盖了全内反射,这不是这里的问题。 现在的代码:我正在使用operator | 对于点积,所以(vec|vec)是点积和operator ~来反转向量。 对象,包括 ligths 和 spheres 都存储在Object **objects; . 光线追踪功能 Colour raytrace(const Ray &r, const int &depth) { //first find the nearest intersection of a ray with an object Colour finalColour = skyBlue *(r

2021-06-12 14:56:57    分类:技术分享    c++   graphics   3d   raytracing

Phong 着色问题(Trouble with Phong Shading)

问题 我正在根据 Phong 模型编写着色器。 我正在尝试实现这个等式: 其中 n 是法线,l 是光的方向,v 是相机的方向,r 是光反射。 这些方程在维基百科文章中有更详细的描述。 截至目前,我仅在定向光源上进行测试,因此没有 r^2 衰减。 环境项是在下面的函数之外添加的,效果很好。 如果点积为负,则函数 maxDot3 返回 0,这通常在 Phong 模型中完成。 这是我实现上述等式的代码: #include "PhongMaterial.h" PhongMaterial::PhongMaterial(const Vec3f &diffuseColor, const Vec3f &specularColor, float exponent,const Vec3f &transparentColor, const Vec3f &reflectiveColor,float indexOfRefraction){ _diffuseColor = diffuseColor; _specularColor = specularColor; _exponent = exponent; _reflectiveColor = reflectiveColor; _transparentColor = transparentColor; } Vec3f PhongMaterial::Shade

2021-06-12 04:15:26    分类:技术分享    c++   graphics   shader   raytracing

如何正确钳制贝克曼分布(How to properly clamp beckmann distribution)

问题 我正在尝试实现 Microfacet BRDF 着色模型(类似于 Cook-Torrance 模型),但我在本文中定义的贝克曼分布方面遇到了一些问题:https://www.cs.cornell.edu/~srm/publications /EGSR07-btdf.pdf 其中 M 是微面法线,N 是宏观面法线,ab 是 [0, 1] 之间的“硬度”参数。 我的问题是这种分布通常会返回非常大的值,尤其是当 ab 非常小时。 例如,贝克曼分布用于计算根据以下方程生成微面法线 M 的概率: 概率必须在范围 [0,1] 之间,那么如果贝克曼分布给我的值大小为 1000000000+,那么如何使用上面的函数获得该范围内的值? 那么有没有合适的方法来限制分布? 还是我误解了它或概率函数? 如果值超过 1,我曾尝试将其简单地钳位为 1,但这并没有真正给我想要的结果。 回答1 我和你有同样的问题。 如果你读 http://blog.selfshadow.com/publications/s2012-shading-course/hoffman/s2012_pbs_physics_math_notes.pdf 和 http://blog.selfshadow.com/publications/s2012-shading-course/hoffman/s2012_pbs_physics

2021-06-11 20:36:52    分类:技术分享    graphics   shader   probability   raytracing   clamp

DirectX 11 compute shader for ray/mesh intersect

I recently converted a DirectX 9 application that was using D3DXIntersect to find ray/mesh intersections to DirectX 11. Since D3DXIntersect is not available in DX11, I wrote my own code to find the intersection, which just loops over all the triangles in the mesh and tests them, keeping track of the closest hit to the origin. This is done on the CPU side and works fine for picking via the GUI, but I have another part of the application that creates a new mesh from an existing one based on several different viewpoints, and I need to check line of sight for every triangle in the mesh many times

2021-06-11 20:01:38    分类:问答    directx-11   raytracing   compute-shader

Detect&find intersection ray vs. cubic bezier triangle

While writing a model editor, besides enabling raytracing I can think about couple of operations where I'd like to find an very good approximation about the intersection point between a ray and a triangular bezier patch. How to do this? I know couple of ways but likely there's better ones. Exact use-cases: I might want to use one bezier triangle patch as a reference surface for drawing detailed shapes with mouse. I might too want to pinpoint a splitting-point from such patch. If there's C source code for it, I might like to see that too. Perhaps even use it instead of rolling my own code.

2021-06-11 03:59:49    分类:问答    math   physics   bezier   raytracing

Computer Graphics: Raytracing and Programming 3D Renders

I've noticed that a number of top universities are offering courses where students are taught subjects relating to Computer Graphics for their CS majors. Sadly this is something not offered by my university and something I would really like to get into sometime in the next couple of years. A couple of the projects I've found from some universities are great, although I'm mostly interested in two things: Raytracing: I want to write a Raytracer within the next two years. What do I need to know? I'm not a fantastic programmer yet (Java, C and Prolog are my main languages as of today) but I'm

2021-06-05 15:46:31    分类:问答    programming-languages   3d   raytracing   graphics

Ray Cylinder intersection

I am developing a Ray Tracing system and it is working, now I am trying to support more primitives (for now it supports: spheres, boxes, planes and triangles), and I am having problems with cylinders. I know to intersect ray with cylinder I need to do two check, the first is with the body (with that I get an Infinite Cylinder), for this I assume circle in two dimensions, in the plane xz (x² + z² = r, where r is the radius) then I need check that Y coordinate is between 0 and height and finally I need to check if the intersection is in the caps (x²+z²<=r, where r is the radius). My code is the

2021-06-03 21:59:59    分类:问答    c++   graphics   raytracing

Textured spheres without strong distortion

I've seen well-textured balls, planets, and other spherical objects in couple of games, last time in UFO: aftermath. If you just splatter a texture into latitude/longditude as u and w -coordinates you'll get lots of ugly texture distortion to poles. I can think myself an one way to implement a spherical map with minimum distortion. By mapping in triangles instead of squares. But I don't know any algorithms. How to produce vertices and texture coordinates for such spheres? Also, I don't see a way to generate a complete spherical map from a simple flat square map. Is there some intuitive way on

2021-06-02 21:27:35    分类:问答    graphics   textures   raytracing