3 ms·
Simple OpenGL question: Can the refractions/caustics be computed entirely in the shaders? Or do you have to do some of the processing in the CPU* and pass the r
by jarrett 13y ago
Simple OpenGL question: Can the refractions/caustics be computed entirely in the shaders? Or do you have to do some of the processing in the CPU* and pass the results back to the shaders? All the shaders I've seen are "local," in the sense that they only have access to the interpolated vertex data for their polygon, plus whatever uniforms have been set. It seems to me that things like caustics would require non-local information. Is that non-local information passed via a uniform? If so, I wonder what the data format of that uniform is.
* I know that shaders aren't guaranteed to execute on the GPU, depending on the OpenGL implementation. But for simplicity let's just assume they do.
- ajross 13y agoThe last caustics implementation I looked at (not this one) did the refraction stuff per-pixel in shaders based on a CPU-computed mesh deformation. The more general answer to your question is that in fragment shaders, you can get "non-locality" via texture lookups inside the shader code.
- jarrett 13y ago> you can get "non-locality" via texture lookups inside the shader code. So you define a way to encode arbitrary non-local data as texture data, correct? That is, you're hacking textures as a store for arbitrary data instead of the image data that textures were originally designed to store?
- ramidarigaz 13y agoYep, exactly. There are a number of techniques that take advantage of this. Most notable are bump mapping and normal mapping.
- constexpr 13y agoAuthor here. The caustics in this demo are computed entirely on the GPU and are approximated with a mesh. The shader for the caustics needs the ratio of the projected area to the original area for each triangle to compute the brightness. You're right that a vertex shader can't access whole triangles (you usually use a geometry shader for that, which WebGL doesn't have) but you can still get the ratio of the triangle areas in this case by using the screen-space derivative functions dFdx() and dFdy() in the fragment shader. Reflections and refractions can also be done in entirely in the fragment shader for simple scenes like this one with standard raytracing intersection tests.
- heeen 13y agoin this case, with only 5 planes and one sphere, you can pass the whole scene into the shader as uniforms. If you have arbitrary scenes, you can hack around this by estimating the water surface area where each triangle would be visible and then generate a water surface quadrilateral for each submerged triangle to raycast it. http://www.youtube.com/watch?v=oWrUvJYzRlQ http://www.youtube.com/watch?v=oWrUvJYzRlQ
- deleted 13y ago[deleted]