Page 1 of 1

Simple refraction shader

Posted: Sun Feb 06, 2005 7:47 am
by former MessiaH
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?

Posted: Thu Feb 10, 2005 9:02 am
by former MessiaH
Is that SO difficult that no one knows how to it?

Posted: Thu Feb 10, 2005 9:55 am
by Guest
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

Posted: Thu Feb 10, 2005 10:05 am
by bal
Niko's currently busy with per-pixel lighting for 0.8.

Posted: Sat Feb 12, 2005 8:59 am
by Guest
Probably there might be some samples of low-level refraction shaders in DX Sdk...

Posted: Tue Feb 15, 2005 12:21 pm
by Guest
I think we should all wait for HLSL implemention,and after that creating refraction shaders would be pretty easy.

Posted: Tue Feb 15, 2005 2:57 pm
by Guest
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.

Posted: Sat Feb 19, 2005 3:11 pm
by former MessiaH
Having HLSL now,aren't there sone ideas of creating this effect?

Posted: Tue Feb 22, 2005 2:43 pm
by Plato
same problem...

i've downloaded dx sdk and going to read it through... there's a chance that i can figure out how hlsl works...

and by the way - there're lot of examples in sdk...

messiah, r u russian by the way?

Posted: Tue Feb 22, 2005 3:47 pm
by former MessiaH
2 Plato
How have you guessed?Has my english failed me or something else?

Posted: Thu Feb 24, 2005 9:56 am
by Plato
Мессия...

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...

Posted: Sat Feb 26, 2005 11:46 am
by former MessiaH
HMM...
Extremely interesting programme by the way,and the only significant misfeature is installer's big size-certainly for my damn dial-up(60 MB).
2Plato
Now I'm doing demo version of HellFighter(DooM3 style) game,based on my code from FatalStrike+Newton physics+per-pixel lighting.

Posted: Tue Mar 01, 2005 8:27 am
by Plato
Мессия,

Are you staying in Moscow? I can send it to you with courier... It's no problem to me...

Posted: Tue Mar 01, 2005 11:15 am
by former MessiaH
2 Plato
UnFortunatelly no.I'm in Ufa,and that's fairly far away from Moscow,you know. :cry: