Comments (2)
Hello @VinAr22
Thank you! Yes it should be possible to use an html canvas element as a texture. Each demo (the .html file) has a fragment shader (.glsl) associated with it of the same name (the heart of the path-traced rendering) and an associated JavaScript file of the same name that loads in any images that are necessary and creates the uniforms (links to the associated fragment shader).
If you look at BilliardTable.js for instance, you can see how the textures (such as cloth and wood) are first loaded using the three.js library and then handed over to the shader via texture uniforms. Once the fragment shader knows about them, it can use the uniform for each texture inside the pathtracing loop and make that the default diffuse color lookup for that surface or object. In order to use the textures in rendering, you must provide uv coordinates when you call the texture(uniform, uv) function inside glsl - the uv's in ray tracing are traditionally corresponding to where the ray strikes the 2d surface, XY or XZ plane. A good surface to get started with is a rectangle or plane because the uv texture lookup can be easily found or manually given. Again you can see how I handled different uv's in the BilliardTable_Fragment.glsl file (where the function texture() is called). The pow(,2.2) stuff is just gamma correction, but may or may not be necessary in your canvas case. UV's for texture lookups are tricky - I have only really mastered how to use them on planes, rectangles, and spheres. To see a textured sphere and how to get the uv's, refer to my Compleat Angler classic demo.
Getting back to using a canvas instead of a .png or .jpg, I would assume that if you can just load it in with the three.js library, you would then just pass it to the fragment shader via the uniform in the same exact way that you would a .jpg image - they're all just 2d image data. In other words, the path tracing fragment shader doesn't care how you obtained the image, it just needs access to it via a texture uniform.
Here's a link and its source code for an example of how three.js loads in and uses a canvas element as a surface texture. Once you have the material.map populated, just pass it to the fragment shader through a dedicated uniform and it should work.
Let me know if you run into any problems, I will try to help as much as I can. Best of luck!
-Erich
from three.js-pathtracing-renderer.
Hi @erichlof! Thanks a lot for your reply, I have lost access to my account and have not seen your wonderful explanation yet. Thank you for your work
from three.js-pathtracing-renderer.
Related Issues (20)
- muti material not supported
- WebGPU port HOT 3
- More abstractions HOT 9
- Using more information from earlier samples HOT 3
- More samples per frame option HOT 63
- More compatibility with three js APIs HOT 2
- Stop a caustic ray if it crosses a surface HOT 3
- Just wondering how you handled something HOT 14
- Blue noise HOT 8
- GLTF viewer textures HOT 3
- sampler2D array HOT 14
- How to use this pathtracer in Freeciv 3D version? HOT 2
- [question] how to debug glsl in chrome? HOT 2
- GLTF_Model_Viewer didn't get the right result? HOT 6
- How to incorporate it into project? HOT 9
- statistical tool: bootstrapping
- Shadow Catcher HOT 1
- Support for a THREE.ParametricGeometry HOT 1
- GLTF_Viewer is not able to load textures HOT 1
- image stretched for BHV point light source HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from three.js-pathtracing-renderer.