Simple refraction shader

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
former MessiaH

Simple refraction shader

Post 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?
former MessiaH

Post by former MessiaH »

Is that SO difficult that no one knows how to it?
Guest

Post 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
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Niko's currently busy with per-pixel lighting for 0.8.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Guest

Post by Guest »

Probably there might be some samples of low-level refraction shaders in DX Sdk...
Guest

Post by Guest »

I think we should all wait for HLSL implemention,and after that creating refraction shaders would be pretty easy.
Guest

Post 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.
former MessiaH

Post by former MessiaH »

Having HLSL now,aren't there sone ideas of creating this effect?
Plato

Post 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?
former MessiaH

Post by former MessiaH »

2 Plato
How have you guessed?Has my english failed me or something else?
Plato

Post 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...
former MessiaH

Post 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.
Plato
Posts: 7
Joined: Thu Feb 24, 2005 10:29 am
Location: Russia, Moscow

Post by Plato »

Мессия,

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

Post by former MessiaH »

2 Plato
UnFortunatelly no.I'm in Ufa,and that's fairly far away from Moscow,you know. :cry:
Post Reply