[2370]  1  

 2  [vert.glsl] 

 3  #version 120 

 4  

 5  attribute vec3 in_Vertex; 

 6  attribute vec3 in_Normal; 

 7  attribute vec4 in_Color; 

 8  attribute vec2 in_Index;


 9  attribute vec2 in_Weight; 

 10  

 11  uniform mat4 in_ModelView; 

 12  uniform mat4 in_View; 

 13  uniform mat4 in_Proj; 

 14  uniform mat3 in_NormalMat; 

 15  //10is not a fix idea, should be more. 

 16  uniform mat4 in_BoneList[10]; 

 17  

 18  varying vec4 pass_Vertex; /* View space */ 

 19  varying vec3 pass_TNormal; 

 20  varying vec4 pass_Color; 

 21  

 22  void main(void) 

 23  { 

 24  vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0); 

 25  vec3 tnorm = normalize(in_NormalMat * in_Normal); 

 26  

 27  pass_Vertex = vertex; 

 28  pass_TNormal = tnorm; 

 29  pass_Color = in_Color; 

 30  

 31  gl_Position = in_Proj * vertex; 

 32  } 

 33  

 34  [frag.glsl] 

 35  #version 120 

 36  

 37  #if defined GL_ES 

 38  precision highp float; 

 39  #endif 

 40  

 41  uniform float in_Damage; 

 42  uniform mat4 in_View; 

 43  uniform mat4 in_Inv_View; 

 44  

 45  uniform vec4 u_Lights[8 * 2]; 

 46  

 47  varying vec4 pass_Vertex; /* View space */ 

 48  varying vec3 pass_TNormal; 

 49  varying vec4 pass_Color; 

 50  

 51  #if 0 

 52  //Cube Light 

 53  //Cos(45) = 0.70710678118 

 54  //1.0  Cos(45) = 0.29289321881 

 55  

 56  const float cos_45 = 0.70710678118; 

 57  const float inv_cos_45 = 0.29289321881; 

 58  

 59  vec4 in_Light3_Pos = vec4(10.0, 20.0, 0.0, 1.0); 

 60  vec3 in_Light3_Size_Inner = vec3(12.0, 12.0, 12.0); 

 61  vec3 in_Light3_Size_Outer = vec3(10.0, 10.0, 10.0); 

 62  vec3 in_Light3_diffuse = vec3(0.4, 1.0, 0.4); 

 63  #endif 

 64  

 65  void main(void) 

 66  { 

 67  /* Material properties */ 

 68  vec3 specular_reflect = vec3(0.8, 0.75, 0.4); 

 69  float specular_power = 60.0; 

 70  

 71  /* World properties */ 

 72  vec3 ambient = vec3(0.7, 0.7, 0.7); 

 73  vec3 specular = vec3(0.0, 0.0, 0.0); 

 74  vec3 diffuse = vec3(0.0, 0.0, 0.0); 

 75  

 76  /* Light precalculations */ 

 77  vec3 v = normalize(pass_Vertex.xyz); 

 78  

 79  /* Apply lighting */ 

 80  for (int i = 0; i < 8; i++) 

 81  { 

 82  vec4 pos = u_Lights[i * 2]; 

 83  vec4 color = u_Lights[i * 2 + 1]; 

 84  vec3 s, r; 

 85  

 86  if (pos.w > 0.0) 

 87  { 

 88  /* Point light  no attenuation yet */ 

 89  s = normalize((in_View * pos).xyz  pass_Vertex.xyz); 

 90  r = reflect(s, pass_TNormal); 

 91  } 

 92  else 

 93  { 

 94  /* Directional light */ 

 95  s = normalize(pos.xyz); 

 96  r = reflect(s, pass_TNormal); 

 97  } 

 98  

 99  float sdotn = max(dot(s, pass_TNormal), 0.0); 

 100  diffuse += color.xyz * sdotn; 

 101  if (sdotn > 0.0) 

 102  specular += color.xyz * specular_reflect 

 103  * pow(max(dot(r, v), 0.0), specular_power); 

 104  } 

 105  

 106  #if 0 

 107  //Light calculation for cube light 

 108  //const float cos_45 = 0.70710678118; 

 109  //const float inv_cos_45 = 0.29289321881; 

 110  vec3 local_vertex = (in_Inv_View * pass_Vertex).xyz  (in_Light3_Pos).xyz; 

 111  vec3 proj_vertex = clamp(local_vertex.xyz, in_Light3_Size_Inner, in_Light3_Size_Inner); 

 112  vec3 proj_local_dir = local_vertex  proj_vertex; 

 113  vec3 inner_dir = proj_vertex / in_Light3_Size_Inner; 

 114  inner_dir.x = (inner_dir.x == 1.0)?(1.0):(0.0); 

 115  inner_dir.y = (inner_dir.y == 1.0)?(1.0):(0.0); 

 116  inner_dir.z = (inner_dir.z == 1.0)?(1.0):(0.0); 

 117  

 118  //inside the cube 

 119  if (length(proj_local_dir) == 0.0) 

 120  { 

 121  sdotn = 1.0; 

 122  light_radius_mod = 1.0; 

 123  } 

 124  //spec calculation 

 125  else 

 126  { 

 127  //Distance calculation 

 128  vec3 proj_local_light = proj_local_dir / in_Light3_Size_Outer; 

 129  light_radius_mod = max(0.0, 1.0  length(proj_local_light)); 

 130  //cube orientation 

 131  sdotn = max(0.0, dot(normalize(proj_local_dir), normalize(inner_dir))); 

 132  

 133  

 134  //if (length(inner_dir) > 1.0) 

 135  // sdotn = 0.0; 

 136  //else 

 137  //{ 

 138  // //vec3 proj_local_light = max(vec3(0.0,0.0,0.0), vec3(1.0,1.0,1.0)  abs(proj_local_dir / in_Light3_Size_Outer)); 

 139  //} 

 140  /* 

 141  proj_local_dir = normalize((in_View * vec4(proj_vertex + in_Light3_Pos.xyz,1.0)).xyz  pass_Vertex.xyz); 

 142  sdotn = max(dot(proj_local_dir, pass_TNormal), 0.0); 

 143  r = reflect(proj_local_dir, pass_TNormal); 

 144  if (sdotn > 0.0 && light_radius_mod > 0.0) 

 145  specular += specular_color * min(specular_reflect, light_radius_mod) 

 146  * pow(max(dot(r, v), 0.0), specular_power); 

 147  */ 

 148  } 

 149  //diffuse calculation 

 150  diffuse += in_Light3_diffuse * sdotn; //min(sdotn, light_radius_mod); 

 151  // 

 152  #endif 

 153  

 154  vec3 light = ambient + diffuse + specular; 

 155  

 156  vec4 real_color = mix(pass_Color, vec4(1.2, 1.2, 1.2, 1.0), in_Damage); 

 157  gl_FragColor = real_color * vec4(light, 1.0); 

 158  } 

 159  

 160  [vert.hlsl] 

 161  

 162  void main(float3 in_Vertex : POSITION, 

 163  float3 in_Normal : NORMAL, 

 164  float4 in_Color : COLOR, 

 165  uniform float4x4 in_ModelView, 

 166  uniform float4x4 in_Model, 

 167  uniform float4x4 in_Proj, 

 168  uniform float3x3 in_NormalMat, 

 169  out float4 pass_Vertex : TEXCOORD0, 

 170  out float3 pass_TNormal : TEXCOORD1, 

 171  out float4 pass_Color : COLOR, 

 172  out float4 out_Position : POSITION) 

 173  { 

 174  float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0)); 

 175  float3 tnorm = normalize(mul(in_NormalMat, in_Normal)); 

 176  

 177  pass_Vertex = eye; 

 178  pass_TNormal = tnorm; 

 179  #ifdef _XBOX 

 180  pass_Color = in_Color.abgr; 

 181  #else 

 182  pass_Color = in_Color; 

 183  #endif 

 184  

 185  out_Position = mul(in_Proj, eye); 

 186  } 

 187  

 188  [frag.hlsl] 

 189  

 190  void main(float4 pass_Vertex : TEXCOORD0, 

 191  float3 pass_TNormal : TEXCOORD1, 

 192  float4 pass_Color : COLOR, 

 193  uniform float in_Damage, 

 194  out float4 out_FragColor : COLOR) 

 195  { 

 196  float3 in_LightDir = float3(0.3, 0.3, 0.7); 

 197  

 198  /* Material properties */ 

 199  float3 specular_reflect = float3(0.8, 0.75, 0.4); 

 200  float specular_power = 60.0; 

 201  

 202  /* World properties */ 

 203  float ambient_mul = 0.5; 

 204  float3 ambient_color = float3(0.25, 0.2, 0.35); 

 205  float3 diffuse_color = float3(1.0, 1.0, 0.6); 

 206  float3 specular_color = float3(1.0, 1.0, 0.6); 

 207  

 208  float3 s = normalize(in_LightDir); /* normalize(pass_Vertex  lightpos); */ 

 209  float3 v = normalize(pass_Vertex.xyz); 

 210  float3 r = reflect(s, pass_TNormal); 

 211  

 212  float3 ambient = ambient_color; 

 213  float sdotn = max(dot(s, pass_TNormal), 0.0); 

 214  float3 diffuse = diffuse_color * sdotn; 

 215  float3 specular = float3(0.0, 0.0, 0.0); 

 216  if (sdotn > 0.0) 

 217  specular = specular_color * specular_reflect 

 218  * pow(max(dot(r, v), 0.0), specular_power); 

 219  float3 light = ambient + diffuse + specular; 

 220  

 221  float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0) 

 222  + (1.0  in_Damage) * pass_Color; 

 223  out_FragColor = real_color * float4(light, 1.0); 

 224  } 

 225  
