Changeset 2289 for trunk/src/easymesh
 Timestamp:
 Jan 28, 2013, 2:23:57 PM (7 years ago)
 Location:
 trunk/src/easymesh
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/easymesh/easymesh.cpp
r2277 r2289 80 80 m_gpu.normalmat = m_gpu.shader>GetUniformLocation("in_NormalMat"); 81 81 m_gpu.damage = m_gpu.shader>GetUniformLocation("in_Damage"); 82 m_gpu.lights = m_gpu.shader>GetUniformLocation("u_Lights"); 82 83 m_gpu.coord = m_gpu.shader>GetAttribLocation("in_Vertex", 83 84 VertexUsage::Position, 0); … … 126 127 127 128 m_gpu.shader>Bind(); 129 130 /* FIXME: this should be hidden in the shader */ 131 /* FIXME: the 4th component of the position can be used for other things */ 132 Array<Light *> const lights = Scene::GetDefault()>GetLights(); 133 Array<vec4> light_data; 134 for (int i = 0; i < lights.Count(); ++i) 135 light_data << lights[i]>GetPosition() << lights[i]>GetColor(); 136 while (light_data.Count() < 8) 137 light_data << vec4(0.f) << vec4(0.f); 138 m_gpu.shader>SetUniform(m_gpu.lights, light_data); 139 128 140 m_gpu.shader>SetUniform(m_gpu.modelview, modelview); 129 141 m_gpu.shader>SetUniform(m_gpu.view, Scene::GetDefault()>GetViewMatrix()); 
trunk/src/easymesh/easymesh.h
r2229 r2289 120 120 Shader *shader; 121 121 ShaderAttrib coord, norm, color; 122 ShaderUniform modelview, view, invview, proj, normalmat, damage ;122 ShaderUniform modelview, view, invview, proj, normalmat, damage, lights; 123 123 VertexDeclaration *vdecl; 124 124 VertexBuffer *vbo; 
trunk/src/easymesh/shiny.lolfx
r2232 r2289 39 39 uniform mat4 in_Inv_View; 40 40 41 uniform vec4 u_Lights[8 * 2]; 42 41 43 varying vec4 pass_Vertex; /* View space */ 42 44 varying vec3 pass_TNormal; 43 45 varying vec4 pass_Color; 44 46 45 // FIXME: all the light parameters should be passed in the code 46 //Dir Light 47 vec3 in_LightDir = vec3(0.3, 0.3, 0.7); 48 49 //Point Light 50 vec4 in_Light2_Pos = vec4(20.0, 10.0, 0.0, 1.0); 51 float in_Light2_Radius = 20.0; 52 vec3 in_Light2_diffuse = vec3(0.4, 0.4, 1.0); 53 47 #if 0 54 48 //Cube Light 55 49 vec4 in_Light3_Pos = vec4(10.0, 10.0, 5.0, 1.0); … … 57 51 vec3 in_Light3_Size_Outer = vec3(15.0, 15.0, 15.0); 58 52 vec3 in_Light3_diffuse = vec3(0.4, 1.0, 0.4); 53 #endif 59 54 60 55 void main(void) … … 65 60 66 61 /* World properties */ 67 float ambient_mul = 0.5; 68 vec3 ambient_color = vec3(0.0, 0.0, 0.0); 69 vec3 diffuse_color = vec3(0.4, 0.4, 0.4); 70 vec3 specular_color = vec3(1.0, 1.0, 0.6); 71 72 vec3 ambient = ambient_color; 62 vec3 ambient = vec3(0.1, 0.1, 0.1); 73 63 vec3 specular = vec3(0.0, 0.0, 0.0); 74 64 vec3 diffuse = vec3(0.0, 0.0, 0.0); 75 vec3 s = vec3(0.0, 0.0, 0.0);76 vec3 v = vec3(0.0, 0.0, 0.0);77 vec3 r = vec3(0.0, 0.0, 0.0);78 float sdotn = 0.0;79 float light_radius_mod = 0.0;80 65 81 //Light calculation for directional light 82 s = normalize(in_LightDir); 83 v = normalize(pass_Vertex.xyz); 84 r = reflect(s, pass_TNormal); 66 /* Light precalculations */ 67 vec3 v = normalize(pass_Vertex.xyz); 85 68 86 sdotn = max(dot(s, pass_TNormal), 0.0);87 diffuse += diffuse_color * sdotn;88 if (sdotn > 0.0)89 specular += specular_color * specular_reflect90 * pow(max(dot(r, v), 0.0), specular_power);91 //69 /* Apply lighting */ 70 for (int i = 0; i < 8; i++) 71 { 72 vec4 pos = u_Lights[i * 2]; 73 vec4 color = u_Lights[i * 2 + 1]; 74 vec3 s, r; 92 75 93 //Light calculation for point light 94 vec3 tmpLightDir = (in_View * in_Light2_Pos).xyz  pass_Vertex.xyz; 95 light_radius_mod = max(0.0, 1.0  (length(tmpLightDir) / in_Light2_Radius)); 96 s = normalize(tmpLightDir); 97 v = normalize(pass_Vertex.xyz); 98 r = reflect(s, pass_TNormal); 76 if (pos.w > 0.0) 77 { 78 /* Point light  no attenuation yet */ 79 s = normalize((in_View * pos).xyz  pass_Vertex.xyz); 80 r = reflect(s, pass_TNormal); 81 } 82 else 83 { 84 /* Directional light */ 85 s = normalize(pos.xyz); 86 r = reflect(s, pass_TNormal); 87 } 99 88 100 sdotn = max(dot(s, pass_TNormal), 0.0);101 diffuse += in_Light2_diffuse * min(sdotn, light_radius_mod);102 if (sdotn > 0.0 && light_radius_mod> 0.0)103 specular += specular_color * min(specular_reflect, light_radius_mod)104 * pow(max(dot(r, v), 0.0), specular_power);105 //89 float sdotn = max(dot(s, pass_TNormal), 0.0); 90 diffuse += color.xyz * sdotn; 91 if (sdotn > 0.0) 92 specular += color.xyz * specular_reflect 93 * pow(max(dot(r, v), 0.0), specular_power); 94 } 106 95 96 #if 0 107 97 //Light calculation for cube light 98 vec3 specular_color = vec3(1.0, 1.0, 0.6); 108 99 vec3 Local_Vertex = (in_Inv_View * pass_Vertex).xyz  (in_Light3_Pos).xyz; 109 100 vec3 Proj_Vertex = clamp(Local_Vertex.xyz, in_Light3_Size_Inner, in_Light3_Size_Inner); … … 111 102 112 103 vec3 light_radius = max(vec3(0.0,0.0,0.0), vec3(1.0,1.0,1.0)  abs(new_LightDir / in_Light3_Size_Outer)); 113 light_radius_mod = min(light_radius.x, min(light_radius.y, light_radius.z));104 float light_radius_mod = min(light_radius.x, min(light_radius.y, light_radius.z)); 114 105 115 106 if (length(new_LightDir) == 0.0) … … 126 117 diffuse += in_Light3_diffuse * min(sdotn, light_radius_mod); 127 118 // 119 #endif 128 120 129 121 vec3 light = ambient + diffuse + specular; 130 122 131 vec4 real_color = in_Damage * vec4(1.2, 1.2, 1.2, 1.0) 132 + (1.0  in_Damage) * pass_Color; 123 vec4 real_color = mix(pass_Color, vec4(1.2, 1.2, 1.2, 1.0), in_Damage); 133 124 gl_FragColor = real_color * vec4(light, 1.0); 134 125 }
Note: See TracChangeset
for help on using the changeset viewer.