Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about shader material #1572

Closed
n4m3l3ss-b0t opened this issue Mar 23, 2012 · 4 comments
Closed

Question about shader material #1572

n4m3l3ss-b0t opened this issue Mar 23, 2012 · 4 comments
Labels

Comments

@n4m3l3ss-b0t
Copy link

Good day,

I'm working on a raytracer to try to add photorealism to the scenes. At first, I tried using THREE.Ray to shoot the rays through each pixel and get the interceptions with the available methods, and it worked really well, but sadly it is very slow to shoot a ray through every pixel (it really takes like 4-5 min to shoot a ray through every pixel even on lower resolution like 400x400).

So I had another idea, that is, to use shaders to shoot the rays and calculate every color change on the scenario. But since ray-tracing is a global ilumination method, then I'd need to have a global shader for the whole scene.

So...my question is, is there a way to use a global shader for every object in the scene? From the examples I've been watching, all of them need to have a THREE.shaderMaterial associated with an object, so the shaders can be applied to that object alone, but in this case I'll need to do it globally.

Not sure if I explained it very well, but I'd love an opinion on this. Thanks in advance.

@chandlerprall
Copy link
Contributor

If I understand correctly you want to override every object's material with a global one, right? You can set scene.overrideMaterial = custom_material to do that.

@n4m3l3ss-b0t
Copy link
Author

That instruction is helpful, but... does that mean I can write a global shader for that custom_material, and access the uv's, normals, vertex,... of every object, on the shader code?

Because ray-tracing involves constant update on the colors of each object on the scene, I'll need all their properties.

Let me put it another way, basically, the algorithm I'm thinking is:

  1. Load objects to the scene, and set up lights, define camera.
  2. Start shooting rays through each pixel in the camera, look for intersections.
  3. If there's an intersection with an object, calculate refraction based on the normal, and type of material.
  4. Follow the new refracted ray, if it hits another object, get the point that was hit, and change the color, based on the previous parameters.
  5. Repeat step 3 a certain number of times.

So, the problem is on step 4, how would I update the shaderMaterial that way, or how would I change that specific object on global shader?

@WestLangley
Copy link
Collaborator

Perhaps #1531 will help you.

@n4m3l3ss-b0t
Copy link
Author

It indeed helps, I'll continue on that one. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants