Holographe Shader         A hologram effect

Description

As they are many holo... hologram... and holographic shaders, this one is called "holographe".
This shader contains several effects:

  • one color gradient from the center vertical axis of the object to the border. (In my example: dark when pixel is near the center and brighter when away).
  • one transparency gradient from the center vertical axis of the object to the border. (In my example: transparent when pixel is near the center).
  • noise: dark bands, light bands, transparent bands scolling along the object.


I have tried several ways to do it: with a fixed colour, or with a palette file, or with custom parameters...
Finally I think that the pictures files offer more flexibility.

As this is one of my first shader creation, feel free to make it better, or to give remarks in the discussion page.

Holographe.jpg

Usage

  • You need to pass the object radius as a custom parameter to the shader, for every object that will use this material.
  • You need to have 2 TGA files (RGB+A) : one for the color gradient, and one for the noise.
  • The holoColour texture: the picture size is 1 x 256 for instance. The right pixels are the color/transparency at the center of the object, and the rightest pixel at the border of the object.
  • The holoNoise texture: the picture size is 1 x 256. This picture is filled with noise. Black dots will give a dark line, white dots a bright line, and alpha dots a transparent line.

Material

vertex_program shader/holographeVP cg
 {
     source holographe3.cg
     entry_point main_vp
     profiles vs_1_1
 
     default_params
     {
         param_named_auto worldViewProj worldviewproj_matrix
        }
 }

 fragment_program shader/holographeFP cg
 {
     source holographe3.cg
     entry_point main_fp
     profiles ps_2_x
 }

 material shader/hologram
 {
     technique
     {
         pass
         {
            scene_blend alpha_blend
            vertex_program_ref shader/holographeVP
             {
             param_named_auto customParamRadius custom 0
             }
            fragment_program_ref shader/holographeFP
             {
                       param_named_auto Time time
             }
            texture_unit  holoColour
             {
             texture holoColour1D.tga 1d
             }
            texture_unit  holoNoise
             {
             texture holographe1D.tga 1d
             tex_address_mode wrap
             }
         }
     }
 }

Vertex Program

// --------------------------------------------------------------------
 // ''Author : David de Lorenzo''
 // ''Holographe Shader - Vertex Program''
 // -----------------------------------------------------------------
 void main_vp(    in      float4   position  : POSITION,
                  uniform float4x4 worldViewProj,
                  uniform float4   customParamRadius,
                  out     float4   oPosition : POSITION,
                  out     float4   oMisc     : TEXCOORD0
              )
 {
     // ''calculate output position''
     oPosition = mul(worldViewProj, position);
 
     // ''we pass the vertex position to the fragment shader''
     oMisc   = position;
     oMisc.w = customParamRadius.x;
 }

Fragment Program

// -----------------------------------------------------------------
 // ''Author : David de Lorenzo''
 // ''Holographe Shader - Fragment Program''
 // ''Effect #1: Area near the center of the object are more transparent''
 // ''Effect #2: Light and dark bands are moving upwards on the object surface''
 // ''param iPos : the position of the fragment, supplied by the VP''
 // ''param Time  : the time in [0....]''
 // ''param hologNoise  : a RGBA file (1x256 pixels) with little noise''
 // ''param hologColour : a RGBA file (1x256 pixels) with a color and transparency gradient''
 // -----------------------------------------------------------------
 float4 main_fp(
                   in        float4    iPos        : TEXCOORD0,
                   uniform   float     Time,
                   uniform   sampler1D holoNoise,
                   uniform   sampler1D holoColour
                ) :  COLOR0
 {
    float4 oColor;
 
     float objectradius = iPos.w;
 
     // ''Cylinder type hologram''
     // ''Distance from actual Vertex to center''
     float  Vdist =  (iPos.x*iPos.x) + (iPos.z*iPos.z);
     // ''Normalize distance to [0..1]''
     float  ratio  =  Vdist / (objectradius*objectradius);
     oColor   = tex1D(holoColour, ratio);
 
     float  index     = (iPos.y-Time) * 0.05;
     float4 colorBand = tex1D(holoNoise,index);
     // ''We add light bands and dark bands''
     oColor.rgb = oColor.rgb * colorBand.rgb;
     // ''We add bands with transparency''
     oColor.a   = oColor.a * colorBand.a;
 
     return (oColor);
 }

Enjoy!


Alias: Holographe_Shader