- Home /
How do i use raycast from a screen point to set a pixels color?
So i want to use raycast from each pixel on the screen to set it's color to the color of which the ray hit. So from each pixel it will send out a ray, the ray will then hit an object and return the color of the point that it hit, then set the pixels color to the RGB levels that were returned. The reason i'm doing this is because once i do i want to be able to set the rays physics to ricochet off of certain objects and take the color of the object it hits after that.
This is so that i can create a mirror effect. Similar to the way your eyes work with reflected light and angles to portray what is in an apposing world.
Anyway, i have a hunch that this is sort of how the "Main Camera" in the scene works in the first place, but i'm not sure. And i also don't know how i would go about setting the physics of the rays created to be able to ricochet off of specifically named objects, or objects with a specific material type.
Any information on this would be very much appreciated. And thank you to anyone who can help me.
You are talking about ray tracing. There are people of have done it, but my guess is that it requires Unity Pro and RenderTextures to make it happen. One video:
That looks really nice. Now i have a few questions. As you said, ray tracing is not included in unity free.
How does the main camera work, if not through ray tracing?
What would happen if you tried to use ray tracing? Would you get an error, or would it just not operate?
how do i go about accessing the code for the prefab for the main camera? i would love to dig into it to see how it works.
Ray tracing is not part of Unity, you have to implement it yourself! Unity renders using polygons, there is no need for raytracing, but it's a good idea to do so, just for learning how it works, I have implemented it myself :) You do not need Unity Pro to do raytracing! Render textures have nothing to do with it! You can just do a Texture2D and GUI it onto the screen. Tio: you can't do raytracing in unity in real time. at full resolution, you will get about 1 frame every 5 seconds Hope this helps :) Benproductions1
Hmm. If ray tracing get's you that low frame rate then how do you guys suppose that video did what they did and had normal frame rate? I mean, i thought that was the best way to go about creating this effect, if there's a better way i would love to know it.
They used some very very very complex shaders to achieve what they did. As far as I know it has not been released. If you need it for many objects simultaneously, you frame-rate is going to be low. The reason it's not low in the video is because the game isn't running, so no screen effects and no scripts running. Also they had a very good computer :)