Hi,
I want to create a general refraction shader based on physical laws like Snell's one. I alredy tried to transform his term n1 * sin(a) = n2 * sin(b) while n1 equals the IOR of the surrounding substance and n2 the IOR of the actual Object, a being the input degrees of the light and b the output degrees.
(Source of my thoughts :
http://en.wikipedia.org/wiki/Snell%27s_law)
So I came up with sin(b) = n1 * sin (a) / n2 - nothing special.
My problem is having just b on the left part. for that I should have
b = arcsin[n1 * sin(a) / n2]. But UDK does not have an arcsine node inside the material editor and I cannot find the correct mathematic therm (or some which is able to be put inside the material editor) of arcsine anywhere on the web.
This step is not completly necessary because of just having b= n1 * a / n2 creats very near results to the ones with the sinenodes in a calculator.
But still it is not working correctly, because of distorting to less and taking to less weight at the actual form of the object.
In this case I am using glass as an example but my goal is creating a shader which is usable for most or better all materials I would like to produce (Like the physical Laws are mostly guilty for all substances).
So how can I make this working physicly correct?
My distortion-shader at the moment:
Current result while using with IOR of Glass (1.52):
Results I would like to achieve:
http://3.bp.blogspot.com/_pjMcWzh34dg/Sfo2kfbVUTI/AAAAAAAAAAU/BzeYJ-MHhiI/s1600-h/GraphicDemo_3.JPG
Also does anyone have a great source for palmfrond textures? Everyone I find is either looking terrible or even able for being in use for a good texture. :poly124:
Replies
If you really need this, you could always use a custom code node like this...
Thank you, I did not know this was possible through the custom node.
Ace-Angel:
Everything I read until now told me to use custom nodes as less as possible, because of them being so hard to compute compared to the standard nodes. So i would rather translate it to the usual nodes. Or is there already an implemented function for the refraction?
Sorry for such questions I have never done something with custom nodes and have still few experience with UDK and generall 3d engines.
Also I noticed another issue:
Depending on the direction of view the distortion is changing between refracting up and down.
View in X-direction:
View in opposite X-direction:
I also notices that this happened before - it only changes the axis of this event from y to x through the asin. Is it possible that the reflection vector, through which i wanted to get the angel of view to the object , is causing this?
Edit: sorry for the bugs with the images. I am also new to this forum and I cannot get the preview working properly.
Edit2: got it !
However, now that I look at it, it seems like you don't need Environment Refraction, since the Refraction I'm talking about turns cubemaps and such upside down, so just forget about it.
Your Refraction is the one where it bends what the user sees through it, right?
In that case, I don't know if it's possible to use Snell's Law in UDK, since UDK doesn't seem to recognize the environment as a 3D Space when using said Law, it well always end up bending one side differently to the other, without respecting the Normals.
Also, I think if you look 'up' with the Law, it will actually create an circle/black hole kind of issue.
The cheapest solution is to either use a Fresnel, or a Reflection Vector OR, use a Spherical Mapping with a round Normal Map to 'fake' the bend, these will give you the most 'stable' results.
If anyone wants to correct me, please do, it's been a couple of months since I last tried to get Snell's refraction working, and it didn't work too well.
Also thanks for the helpful link .
But why then is UDK calculating the distortion differently when using this material with a cube and a glass?
As you can see the distortion has no bending when used with a cube. only with round objects like spheres or my example-glass. So this should not be caused by the normals.
Also, do you mind posting up an image of your Snell shader setup, because in my case, almost always one side of the cube looked like a black-hole.
My settings for the material:
Translucent
Phong
TwoSided: true
The current shader (The one from the start of the threat but with the asin added):
Results with an noise-normal map applied:
As you can see it does not change anything serious in comparison to the earlier
screenshots. A constant-3-vector changes nothing.
If I use a fresnel instead of the reflection-vector it reduces the distortion to a minimum. Even with a normal applied to the slot of the fresnel does not change anything noticable. But it cleares the issue with the changing distortion depending on the view direction. Only the edges off the horizon are a little bit bent (changing the values of the fresnel also has no nice effects):
Also would you also like to post up your old snell shader? Maybe we get something decent if we combine both somehow togther.
As you can see, it doesn't make a huge amount of difference from a Fresnel to this, it could be because I have a mistake in my setup maybe.
Here what happens when I try instead to sample the scene using SceneTexture with this setup (since UDK can only sample the scene in 2D, you get this):
If anyone has advice, please do tell, I have no idea how this kind of refraction is supposed to look correctly.
The effect simliar to the fresnel is caused by the dot-product of the camera vector and the 3-constant-vector.
Example:
(http://udn.epicgames.com/Three/rsrc/Three/MaterialsCompendium/DotProductExample.jpg)
Sorry, I am not able to take my own screenshots, because of my computer not working anymore and my replacement cannot handle udk.
If you can specify what it is you're refracting, how it will be seen in the engine, and so on, perhaps a solution can be found that fits.
If you want any normals, just do this. For reflections you'll probably want view space(screen space) normals.
If you want normal maps in there, use a normal map, instead of that constant3(0,0,1)
You might be able to fudge some extra "realism" by altering it by destdepth for variable convergeance, but I imagine that would cause more problems than anything else with doubling of objects in the scene and such.
Experiment! Enjoy.
Example: http://www.animations.physics.unsw.edu.au/jw/light/Snells_law_and_refraction.htm
There are way too many things to consider, and since UDK doesn't even allow the scene-normal buffer to be exposed easily or at all in some cases, or it only sees the environment behind the objects as a 2D scene, you might as well do things manually.
Besides, no one is going to care about your glass shader if it doesn't cast the typical 'rainbow' caustics, which no real-time engine does, last I checked. So you enter an uncanny valley issues where your material looks realistic, but the subtleties which bring it to life like those mentioned are non-existent, and you end up having this weird 'dead' material.
(Transform : Tangent -> View)
1: With this shader I reached a scene-texture, which rotated itself with the object. This means if a object is rotated about 180 degrees it gives some effects similiar to a reflection:
2:
Not surprisingly this setup produces huge artefacts:
Inside the custom node is this code:
return normalize( cross(ddy(inWorldPosition.xyz), ddx(inWorldPosition.xyz)) );
(Source: http://www.volumesoffun.com/polyvox/documentation/dokuwiki/computing_normals_in_a_pixel_shader)