Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 2nd, 2012  |  syntax: C  |  size: 2.13 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. struct LightStruct
  2.         {
  3.                 float enable;
  4.                 float intensity;
  5.                 float radius;
  6.                 vec2 position;
  7.                 vec2 direction;
  8.                 vec4 color;
  9.                 float type;
  10.         };
  11.        
  12.         uniform LightStruct lightInfos[32];
  13.         uniform vec2 screen_size;
  14.        
  15.         vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
  16.         {
  17.                 vec4 pic_color = texture2D( texture, texture_coords );
  18.                 vec4 light_color = vec4(0.0);
  19.                 vec4 light_color_inter = vec4(0.0);
  20.                 vec2 light_pos;
  21.                 vec2 light_vec;
  22.                 float light_value;
  23.                 float light_angle;
  24.                 float light_vec_cos;
  25.                 float light_spot;
  26.                 vec2 light_dir;
  27.                 float PI = 3.14159265358979323846264;
  28.                
  29.                 for ( int i = 0; i < lightInfos.length; i++ )
  30.                 {
  31.                        
  32.                         if ( lightInfos[i].enable == 1 )
  33.                         {
  34.                                 if ( lightInfos[i].type == 0 )
  35.                                 {
  36.                                         light_pos = lightInfos[i].position;
  37.                                         light_dir = lightInfos[i].direction;
  38.                                         light_vec = vec2( pixel_coords.x / screen_size.x, ( screen_size.y - pixel_coords.y ) / screen_size.y ) - light_pos;
  39.                                         light_vec.x = light_vec.x * ( screen_size.x / screen_size.y );
  40.                                         light_value = lightInfos[i].intensity * ( 1.0 - ( length( light_vec ) / ( lightInfos[i].radius * 2 ) ) );
  41.                                         light_color_inter =  light_color + vec4( light_value, light_value, light_value, 1.0 ) + clamp(light_value, 0.0, 1.0);
  42.                                         light_angle = PI / 3;
  43.                                         light_vec_cos = dot( normalize( light_vec ), normalize( light_dir ) );
  44.                                         light_spot = ( clamp( light_vec_cos, cos( light_angle ), 1.0 ) - cos( light_angle ) ) * ( cos( light_angle ) * 2.0 );
  45.                                         light_color_inter.rgb *= clamp( light_spot, 0.0, 1.0 );
  46.                                 }
  47.                                 else if ( lightInfos[i].type == 1 )
  48.                                 {
  49.                                         light_pos = lightInfos[i].position;
  50.                                         light_vec = vec2( pixel_coords.x / screen_size.x, ( screen_size.y - pixel_coords.y ) / screen_size.y ) - light_pos;
  51.                                         light_vec.x = light_vec.x * ( screen_size.x / screen_size.y );
  52.                                         light_value = lightInfos[i].intensity * ( 1.0 - ( length( light_vec ) / lightInfos[i].radius ) );
  53.                                         light_color_inter = light_color + vec4( light_value, light_value, light_value, 1.0 ) + clamp(light_value, 0.0, 1.0);
  54.                                 }
  55.                                 light_color += light_color_inter;
  56.                         }
  57.                 }
  58.                 return pic_color * light_color;
  59.         }