- Home /
Light Refraction, Glass, and Marbles
I am building a project that needs marbles, the kind children play with. Colorful round pretty marbles that are not rendering the way i want them to. The marbles aren't important. It's the glass that concerns me. If you look at the glass shader in blender it has an IOR (Index of Refraction) value that essentially determines how distorted things are when you look at them through the glass. Anyone who knows blender well should know what I'm talking about. I would like to reproduce this effect using the shaders in unity, the problem is I'm not sure how to go about it. I poked around the internet and there are things about writing your own shaders and there is shader code that i don't quite understand. From what i do understand this is something you need unity pro for? To be honest i don't really understand.
What would be absolutely wonderful is if somebody could point me in the right direction here. Do i need to write my own shader because I'm willing to learn how, assuming there's something i can learn from. Is light refraction something i can do with the shaders I have in the free version of unity or do I need unity pro? If so is there a way around this? All I want is glass the refracts light. I'm open to suggestions. any help is appreciated
Answer by Eno-Khaon · Jun 30, 2016 at 05:25 AM
Is this something more along the lines of what you're looking for?
https://en.wikibooks.org/wiki/Cg_Programming/Unity/Curved_Glass
That shader should be able to be used as-is, so you should be able to create a material and apply that shader. Then, ideally, it should do what you're hoping for.
This shader is awesome! It is very close to what I want if I can figure out how to generate a cubemap for it. The thing now is though, can i get it to "see" things that are inside the glass. (as in inside the mesh) it's sort of essential to making what i want to happen happen. If i can get it to do that it'll be perfect.
You see the whole point of this is recreating a marble I made in blender in unity. In blender it looks like this
Yeah it's a little rough and that isn't the best render, but it stilll looks better than it does in unity because in Unity it looks like a ball with an orange wafer in it... Let's be honest that's because it IS a ball with an orange wafer in it the difference being that in blender it's a refractive glass ball that warps light with a wafer in it, and in unity it's a plain transparent ball that doesn't warp light with an orange wafer in it.
I suppose what i'm asking for is a shader that warps light so that whatever is inside looks warped. I wouldn't $$anonymous$$d it having a reflection but maybe not one quite as pro$$anonymous$$ent as your curved glass shader. (you can see in the picture that it reflects the softlight too heavily which sort of makes it look dull, my mistake)
And the reason for that is that Unity -being a game engine- is doing simplified lighting calculations in realtime, while Blender -being a 3D rendering program- can take as much sweet time as it wants... :)
To be precise, Blender uses raytraced transparency in its renderer.
Answer by tanoshimi · Jun 27, 2016 at 03:20 PM
No, you don't need Unity Pro (since Unity 5.x, there are no differences between the engine features in Pro and Personal).
Yes you need a shader that accounts for refraction.
Fortunately, Unity comes with one. Assets -> Import Package -> Effects -> Glass Refraction and try the material there.
The glass in the glass refraction package doesn't quite look the way that I want it to. I'm going for more of a warping effect like this: https://www.shadertoy.com/view/XsSGDh
I know I can write my own shaders (I even watched an hour long unite talk about it) but I have no idea how to make this work.
The link you provided is indeed very pretty, but for a reason. It's raytraced. And I wouldn't rely on raytracing in this case. Plus, knowing how to write shaders is very far from knowing the complex mathematics of light propagation.
I'd reconsider looking at the Glass Refraction that Unity provides, I'm afraid.
Your answer
Follow this Question
Related Questions
Refractive glass shader 1 Answer
Need help rendering beer glass in unity... 0 Answers
Refraction Shader Problem 1 Answer
Distort shader not showing sprites 2 Answers
Creating realistic lantern (glass) 0 Answers