Jump to content
  • Advertisement
Sign in to follow this  
Aeluned

Refraction

This topic is 4793 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a background image taking up the whole viewport and I want to render a 3D object atop it that performs refraction. I don't care about chromatic abberation, I just want to warp the background image. I've seen this done places, but can't find a moronically simple demo in C++. I think I need cube maps for this? I'm trying to achieve something like this: clicky see how the background is warped through the metaballs? can anyone point me to a link or something?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
i beleive your looking for fragment shaders (aka pixel shaders)

Share this post


Link to post
Share on other sites
Yes,I realize there's probably a fragment shader going on...and I know how to use those. Could you be more specific?

I'm going thru the demo that generated the pic I posted, but it's sorta involved, and the shader is written in ASM type language - unfortunately, I'm only familiar with high level shader languages.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
i beleive your looking for fragment shaders (aka pixel shaders)


I believe the anonymous poster is right. Actually, the demo that generated the picture you linked to gives a good example. I doubt it will get any simpler than that demo. You'll need a good graphics card though.

Tom

edit: sorry, you posted while I was writing...

Share this post


Link to post
Share on other sites
Yeah, I'm deep in the code now with a 6800.
I guess I'll have to figure it out from this...thanks.

Share this post


Link to post
Share on other sites
It's actually a pretty simple concept. You store the background image in a cubemap, then instead of using the eye vector to look up the cubemap, you perturb the eye vector based on the normal of the surface, the index of refraction, and snell's law, then use the new vector as the lookup into the cube map. If you want to extend this, you can also add fresnel effects.

Share this post


Link to post
Share on other sites
My biggest problem is getting the cube map working.
(Sorry, I don't know the source tag).

GreecePosX = g_pTextureMgr->LoadImageRec("C:\\Images\\GreeceCubeMap\\GreecePX.png");
GreeceNegX = g_pTextureMgr->LoadImageRec("C:\\Images\\GreeceCubeMap\\GreeceNX.png");
GreecePosY = g_pTextureMgr->LoadImageRec("C:\\Images\\GreeceCubeMap\\GreecePY.png");
GreeceNegY = g_pTextureMgr->LoadImageRec("C:\\Images\\GreeceCubeMap\\GreeceNY.png");
GreecePosZ = g_pTextureMgr->LoadImageRec("C:\\Images\\GreeceCubeMap\\GreecePZ.png");
GreeceNegZ = g_pTextureMgr->LoadImageRec("C:\\Images\\GreeceCubeMap\\GreeceNZ.png");

glGenTextures(1,&M_iTexName);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, M_iTexName);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
0, 4, GreecePosX->sizeX, GreecePosX->sizeY, 0,
GL_RGBA, GL_UNSIGNED_BYTE, GreecePosX->data);

GLint err = 0;
err = glGetError();

glTexImage2D( GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
0, 4, GreeceNegX->sizeX, GreeceNegX->sizeY, 0,
GL_RGBA, GL_UNSIGNED_BYTE, GreeceNegX->data);

err = glGetError();
glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
0, 4, GreecePosY->sizeY, GreecePosY->sizeY, 0,
GL_RGBA, GL_UNSIGNED_BYTE, GreecePosY->data);

err = glGetError();
glTexImage2D( GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
0, 4, GreeceNegY->sizeX, GreeceNegY->sizeY, 0,
GL_RGBA, GL_UNSIGNED_BYTE, GreeceNegY->data);

glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
0, 4, GreecePosZ->sizeX, GreecePosZ->sizeY, 0,
GL_RGBA, GL_UNSIGNED_BYTE, GreecePosZ->data);

glTexImage2D( GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
0, 4, GreeceNegZ->sizeX, GreeceNegZ->sizeY, 0,
GL_RGBA, GL_UNSIGNED_BYTE, GreeceNegZ->data);

glDisable(GL_TEXTURE_CUBE_MAP_ARB);


.....

then later, before I render I call

glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, M_iTexName);
glEnable(GL_TEXTURE_CUBE_MAP_ARB);

there are no errors on the texture upload and the data seems to be fine.

however, when I sample the texture in the fragment shader I get black.
So, somehow the the texture isn't making it to the board?

If i don't use a shader and just enable(GL_TEXTURE_CUBE_MAP_ARB), I get the object untextured.

...I can't believe I can't use a cube map.

any ideas?

Added source and code tags, please check the Forum FAQ for the tags in use on this board

[Edited by - _the_phantom_ on June 29, 2005 6:51:36 PM]

Share this post


Link to post
Share on other sites
nvm, I didn't declare the uniform cubeSampler in the vertex program (only in the fragment program) so I suppose the compiler threw it away.


It sorta works now.

Share this post


Link to post
Share on other sites
That actually brings up an interesting question. I know with, say, water in half life 2 and such, their refraction doesnt bother with a cubemap, i remember seeing something describing it something like this:

1. Render underwater with the water plane as a clip plane
2. render normals (or some kind of perturbation values) into a texture for the water
3. render this somehow perturbing texture coordinates with the perturbation values

how do they deal with the perturbation values?

thanks
cheers
-Dan

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!