Shader Model 2 Glass Shader        

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.

It should work with gpu's that support shader model 2 and above. A live ogre scene is posted to: http://www.ifam.net/openspace/glassdemo/web/index.html. You need win os and the scol voyager plugin (from openspace.com) 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
Todo: add more screen shots maybe early tomorrow morning and move this page to the Shaders section, something I have not figured out.


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. Perhaps I should become a shader programmer if I ever have time. Advantages: one pass, perhaps it saves CPU resources? Disadvantages: don't try to apply this material to an entity that has hardware skinning shaders used on it as well. Many wacky things can happen. 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

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

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 Shader