Skip to main content
Shader Model 2 Glass        

Shader Model 2 Glass Shader

Description


This shader is based on one that I found at http://ogre3d.org/forums/viewtopic.php?f=2&t=48790. It is a glass shader that can contain entities that use the wiki Diffuse/Normal/Specular hardware skinning shader posted to http://www.ogre3d.org/tikiwiki/Normal+Mapping+with+Hardware+Skinning+and+Specular&structure=Cookbook, as is shown in the screenshot below. As you can see the bubble is not reflecting the room...I think the cheapest way to get a good effect would be to create a cubemap using a model of the room in a 3d app (I use bryce), and then turn it into a .dds file to apply to the bubble. Of course there will be some material swapping methods that one would have to use if the bubble is moving from one room/environment to another.

It should work with gpu's that support shader model 2 and above. A live Openspace scene (that uses Ogre for 3d, Newton for physics, OpenAL for sound) is posted to: http://www.ifam.net/openspace/glassdemo/web/index.html. You need win os or linux running wine and the scol voyager plugin (from http://scolring.org/index.php/logiciels ) to view the scene. If the plugin is not installed on your system you will be prompted for an install. Openspace like Ogre is opensource.



Image
\

Usage


just add the material model_2_glassshader to your object. It is a bit unpredictable with materials that are contained within it. Entities with multiple materials tend not to display some submeshes. Why? I don't know. If you know, let me know. Advantages: one pass, perhaps it saves CPU resources? Disadvantages: don't try to apply this material to an entity that has multiple materials that use the hardware skinning shader...either the hardware skinning shader will appear and not the glass, or vice versa.

Todo or more like a plea: if someone can get this material to incorporate hardware skinning, go for it! Then it could be used for spacesuit visors, robot turrets, monster eyeball glasses, etc.

Material file

Copy to clipboard
vertex_program test5_vs cg { source forumglass.cg entry_point main_vs profiles vs_1_1 arbvp1 } fragment_program test5_ps cg { source forumglass.cg entry_point main_ps profiles ps_2_0 arbfp1 } material model_2_glassshader { technique { pass { scene_blend alpha_blend depth_write on //alpha_rejection greater 128 vertex_program_ref test5_vs { param_named_auto world world_matrix param_named_auto viewProj viewproj_matrix param_named_auto eyePositionWorld camera_position } fragment_program_ref test5_ps { } texture_unit { cubic_texture Mars.dds combinedUVW alpha_op_ex source1 src_manual src_current 0.01 colour_op modulate tex_address_mode clamp } } } }

forumglass.cg

Copy to clipboard
void main_vs( float4 inPosition: POSITION, float3 inNormal: NORMAL, out float4 outPosition: POSITION, out float3 outNormal: TEXCOORD0, out float3 outViewVec: TEXCOORD1, uniform float4x4 world, uniform float4x4 viewProj, uniform float3 eyePositionWorld ){ float4 worldPosition = mul(world,inPosition); outPosition = mul(viewProj, worldPosition); outNormal = normalize(mul(world,float4(inNormal,0)).xyz); outViewVec = normalize(eyePositionWorld - worldPosition); } void main_ps( float3 inNormal: TEXCOORD0, float3 inViewVec: TEXCOORD1, out float4 outColor : COLOR, uniform samplerCUBE ReflectTex ){ float v = dot(inViewVec, inNormal); float3 reflectionVec = reflect(-inViewVec, inNormal); float3 reflection = texCUBE(ReflectTex, reflectionVec*2); outColor = float4(reflection, 1.2 - v); }


To make the material transparent, play with the float number in the last line of the .cg file, i.e. .9-v, or .5-v, etc. I'm sure you can get other cool effects by playing around with other parameters.


Alias: Shader Model 2 Glass
Alias: Shader Model 2 Glass Shader