Changeset 2289
- Timestamp:
- Jan 28, 2013, 2:23:57 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile.am
r2265 r2289 15 15 worldentity.cpp worldentity.h gradient.cpp gradient.h gradient.lolfx \ 16 16 platform.cpp platform.h sprite.cpp sprite.h camera.cpp camera.h \ 17 light.cpp light.h \ 17 18 \ 18 19 lol/base/log.h lol/base/array.h lol/base/types.h lol/base/array.h \ -
trunk/src/core.h
r2277 r2289 117 117 118 118 #include "camera.h" 119 #include "light.h" 119 120 #include "emitter.h" 120 121 #include "font.h" -
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 } -
trunk/src/entity.h
r2216 r2289 60 60 { 61 61 DRAWGROUP_BEFORE = GAMEGROUP_END, 62 DRAWGROUP_LIGHT, 62 63 DRAWGROUP_CAMERA, 63 64 DRAWGROUP_DEFAULT, -
trunk/src/lolcore.vcxproj
r2265 r2289 274 274 <ClCompile Include="input\stick.cpp" /> 275 275 <ClCompile Include="layer.cpp" /> 276 <ClCompile Include="light.cpp" /> 276 277 <ClCompile Include="map.cpp" /> 277 278 <ClCompile Include="math\geometry.cpp" /> … … 584 585 <ClInclude Include="input\stick.h" /> 585 586 <ClInclude Include="layer.h" /> 587 <ClInclude Include="light.h" /> 586 588 <ClInclude Include="loldebug.h" /> 587 589 <ClInclude Include="lolgl.h" /> -
trunk/src/lolcore.vcxproj.filters
r2265 r2289 190 190 <Filter>...</Filter> 191 191 </ClCompile> 192 <ClCompile Include="light.cpp"> 193 <Filter>...</Filter> 194 </ClCompile> 192 195 <ClCompile Include="ticker.cpp"> 193 196 <Filter>...</Filter> … … 775 778 </ClInclude> 776 779 <ClInclude Include="layer.h"> 780 <Filter>...</Filter> 781 </ClInclude> 782 <ClInclude Include="light.h"> 777 783 <Filter>...</Filter> 778 784 </ClInclude> -
trunk/src/scene.cpp
r2277 r2289 62 62 mat4 m_proj_matrix; 63 63 64 Array<Tile> tiles; 64 Array<Tile> m_tiles; 65 Array<Light *> m_lights; 65 66 66 67 Shader *m_shader; … … 114 115 delete data->bufs[i]; 115 116 data->bufs.Empty(); 117 data->m_lights.Empty(); 116 118 } 117 119 … … 147 149 t.scale = scale; 148 150 149 data->tiles.Push(t); 151 data->m_tiles.Push(t); 152 } 153 154 void Scene::AddLight(Light *l) 155 { 156 data->m_lights.Push(l); 157 } 158 159 Array<Light *> const &Scene::GetLights() const 160 { 161 return data->m_lights; 150 162 } 151 163 … … 153 165 { 154 166 /* Early exit if nothing needs to be rendered */ 155 if (!data-> tiles.Count())167 if (!data->m_tiles.Count()) 156 168 return; 157 169 … … 161 173 #if 0 162 174 // Randomise, then sort. 163 for (int i = 0; i < data-> tiles.Count(); i++)175 for (int i = 0; i < data->m_tiles.Count(); i++) 164 176 { 165 Tile tmp = data-> tiles[i];166 int j = rand() % data-> tiles.Count();167 data-> tiles[i] = data->tiles[j];168 data-> tiles[j] = tmp;177 Tile tmp = data->m_tiles[i]; 178 int j = rand() % data->m_tiles.Count(); 179 data->m_tiles[i] = data->m_tiles[j]; 180 data->m_tiles[j] = tmp; 169 181 } 170 182 #endif 171 qsort(&data-> tiles[0], data->tiles.Count(),183 qsort(&data->m_tiles[0], data->m_tiles.Count(), 172 184 sizeof(Tile), SceneData::Compare); 173 185 … … 220 232 #endif 221 233 222 for (int buf = 0, i = 0, n; i < data-> tiles.Count(); i = n, buf += 2)234 for (int buf = 0, i = 0, n; i < data->m_tiles.Count(); i = n, buf += 2) 223 235 { 224 236 /* Count how many quads will be needed */ 225 for (n = i + 1; n < data-> tiles.Count(); n++)226 if (data-> tiles[i].tileset != data->tiles[n].tileset)237 for (n = i + 1; n < data->m_tiles.Count(); n++) 238 if (data->m_tiles[i].tileset != data->m_tiles[n].tileset) 227 239 break; 228 240 … … 238 250 for (int j = i; j < n; j++) 239 251 { 240 data-> tiles[i].tileset->BlitTile(data->tiles[j].id,241 data-> tiles[j].pos, data->tiles[j].o,242 data-> tiles[j].scale,252 data->m_tiles[i].tileset->BlitTile(data->m_tiles[j].id, 253 data->m_tiles[j].pos, data->m_tiles[j].o, 254 data->m_tiles[j].scale, 243 255 vertex + 18 * (j - i), texture + 12 * (j - i)); 244 256 } … … 248 260 249 261 /* Bind texture */ 250 data-> tiles[i].tileset->Bind();262 data->m_tiles[i].tileset->Bind(); 251 263 252 264 /* Bind vertex and texture coordinate buffers */ … … 258 270 data->m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, (n - i) * 6); 259 271 data->m_vdecl->Unbind(); 260 data-> tiles[i].tileset->Unbind();272 data->m_tiles[i].tileset->Unbind(); 261 273 } 262 274 263 data-> tiles.Empty();275 data->m_tiles.Empty(); 264 276 265 277 data->m_shader->Unbind(); -
trunk/src/scene.h
r2216 r2289 20 20 21 21 #include "tileset.h" 22 #include "light.h" 22 23 23 24 namespace lol … … 46 47 void AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale); 47 48 49 void AddLight(Light *light); 50 Array<Light *> const &GetLights() const; 51 48 52 private: 49 53 SceneData *data; -
trunk/tutorial/05_easymesh.cpp
r2237 r2289 55 55 Ticker::Ref(m_camera); 56 56 57 /* Add a white directional light */ 58 m_light1 = new Light(); 59 m_light1->SetPosition(vec4(0.2f, 0.2f, 0.f, 0.f)); 60 m_light1->SetColor(vec4(0.5f, 0.5f, 0.5f, 1.f)); 61 Ticker::Ref(m_light1); 62 63 /* Add an orangeish point light */ 64 m_light2 = new Light(); 65 m_light2->SetPosition(vec4(-15.f, 15.f, 15.f, 1.f)); 66 m_light2->SetColor(vec4(0.4f, 0.3f, 0.2f, 1.f)); 67 Ticker::Ref(m_light2); 68 57 69 m_ready = false; 58 70 } … … 61 73 { 62 74 Ticker::Unref(m_camera); 75 Ticker::Unref(m_light1); 76 Ticker::Unref(m_light2); 63 77 } 64 78 … … 115 129 mat4 m_mat; 116 130 Camera *m_camera; 131 Light *m_light1, *m_light2; 117 132 118 133 bool m_ready;
Note: See TracChangeset
for help on using the changeset viewer.