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

Recommended Posts

Anyone has any documentation on how to achieve a glass like effect with shaders? thx alot

Share on other sites
Basically you need to do a lookup in an environment cube map, using the refracted eye vector.

I'm pretty certain you can find several examples of glass shaders lying around. To begin with I guess you'll need to understand Snell's law and, perhaps also, the Fresnel equations. Here are some articles that helped me while implementing it, anyway:

Snell's law
Fresnel equations

Well, that's the physics part of it, anyway.

Share on other sites
Quote:
 Original post by James TrotterI'm pretty certain you can find several examples of glass shaders lying around. To begin with I guess you'll need to understand Snell's law and, perhaps also, the Fresnel equations. Here are some articles that helped me while implementing it, anyway:Snell's lawFresnel equationsWell, that's the physics part of it, anyway.

It's almost impossible to get glass to look right without the fresnel equations. Effects that we're used to seeing when we look out the window just don't happen when you model glass with constant transparency.

Share on other sites
Well it depends on the type of glass you want. For basic glassy look here is a Cg shader I have that does the trick:

// fresnel approximationfloat my_fresnel( float3 I, float3 N, float power, float scale, float bias ){	return bias + ( pow( min( 0.0, 1.0 - dot( I, N ) ), power ) * scale );}float4 glass_object_main( uniform float3 incident : TEXCOORD0,						  uniform float3 normal   : TEXCOORD1,						  						  uniform float indRefract,	// Index of refraction									  uniform samplerCUBE envMap : TEXUNIT0					    					    ) : COLOR{	float3 I = normalize( incident );							float3 N = normalize( normal   );		float3 R = reflect( I, N );	float3 T = refract( I, N, indRefract );		float fresnel = my_fresnel( -I, N, 5.0, 0.98, 0.02 );		// reflection in env map	float3 _reflect = texCUBE( envMap, R ).rgb;		// refraction in env map	float3 _refract = texCUBE( envMap, T ).rgb;		float3 final = lerp( _refract, _reflect, fresnel );		return float4( final, 1.0 ); }

If you want a frosted glass look you can get a nice effect of this by using splines. ATI's Ashli viewer has shaders (in GLSL, GLSL, and RenderMan) that does this. It's quite cool.

-SirKnight

Share on other sites
thanks a lot for your help guys!

1. 1
Rutin
19
2. 2
3. 3
JoeJ
16
4. 4
5. 5

• 26
• 20
• 13
• 13
• 17
• Forum Statistics

• Total Topics
631700
• Total Posts
3001782
×