Simple refraction shader
Simple refraction shader
I want to make some simple refractions(glass effect),and shaders are the only way to dothis.
But unfortunatelly I have no experience of writing shaders.
Does someone have some simple pixel shader and code to make it work?
But unfortunatelly I have no experience of writing shaders.
Does someone have some simple pixel shader and code to make it work?
I can't help you with the shader itself. No experience with it. Although it might be somewhat similar to bumpmapping.
You'd want to use the angle between the viewer and the glass pane, combined with the vector from the bumpmap to warp the underlying pixels.
But in order for this to work properly I'm pretty sure that all transparent surfaces need to be rendered back to front - and I'm not sure Irrlicht does that for you.
Anyway, there are better forums for asking shader questions, methinks.
You could try the opengl forums for pointers: http://www.opengl.org/discussion_boards ... forum;f=11
You'd want to use the angle between the viewer and the glass pane, combined with the vector from the bumpmap to warp the underlying pixels.
But in order for this to work properly I'm pretty sure that all transparent surfaces need to be rendered back to front - and I'm not sure Irrlicht does that for you.
Anyway, there are better forums for asking shader questions, methinks.
You could try the opengl forums for pointers: http://www.opengl.org/discussion_boards ... forum;f=11
Heh!
If you understand the math, it's hardly any more difficult to code this in a low-level shading language than in a high-level one.
Here's what I think the shader would roughly need to do:
1. get the normal between the displayed surface and the view direction
2. manipulate this with a bumpmap lookup
3. combine them in a meaningful way
4. use the result to lookup pixels from the frame buffer and mix them based on the angle to the viewer - this would have to result in only subtle shifts. Maybe this would require blending multiple original pixels
5. blend with more or less of the glass color - minimal glass when looking straight at it, maximum glass when looking almost at the side.
I'd say 1-3 are basically the same as with bumpmapping. And per vertex lighting should theoretically still work.
I don't know whether 4 is at all possible.
Using just a glass color (you should be able to use the interpolated vertex color for this - i.e. you don't need to supply it as a parameter) you only need a bumpmap, no base texture.
However I think the main problem with it is the limited resolution of the frame buffer. The shifts would probably be tiny but would be rounded to whole pixels. It may well be Ugly.
If you understand the math, it's hardly any more difficult to code this in a low-level shading language than in a high-level one.
Here's what I think the shader would roughly need to do:
1. get the normal between the displayed surface and the view direction
2. manipulate this with a bumpmap lookup
3. combine them in a meaningful way
4. use the result to lookup pixels from the frame buffer and mix them based on the angle to the viewer - this would have to result in only subtle shifts. Maybe this would require blending multiple original pixels
5. blend with more or less of the glass color - minimal glass when looking straight at it, maximum glass when looking almost at the side.
I'd say 1-3 are basically the same as with bumpmapping. And per vertex lighting should theoretically still work.
I don't know whether 4 is at all possible.
Using just a glass color (you should be able to use the interpolated vertex color for this - i.e. you don't need to supply it as a parameter) you only need a bumpmap, no base texture.
However I think the main problem with it is the limited resolution of the frame buffer. The shifts would probably be tiny but would be rounded to whole pixels. It may well be Ugly.
Мессия...
Nop... I have seen you on irrlicht.nm.ru...
Well I have found the solution to make shaders... Solution called FX Composer and you can find it on developer.nvidia.com
P.S. What you do by the way? I have some work done with Irrlicht too... Mightly we could do something together?
My uin 91813132... Wellcome... Im russian too...
Nop... I have seen you on irrlicht.nm.ru...
Well I have found the solution to make shaders... Solution called FX Composer and you can find it on developer.nvidia.com
P.S. What you do by the way? I have some work done with Irrlicht too... Mightly we could do something together?
My uin 91813132... Wellcome... Im russian too...