Changeset 539
- Timestamp:
- 05/16/08 17:10:24 (8 months ago)
- Files:
-
- trunk/run/data/shaders/model-pixel.glsl (modified) (2 diffs)
- trunk/run/data/shaders/shadowmap.glsl (modified) (2 diffs)
- trunk/run/data/shaders/terrain-pixel.glsl (modified) (3 diffs)
- trunk/run/defend.cfg (modified) (1 diff)
- trunk/src/defend/Config.d (modified) (2 diffs)
- trunk/src/defend/Main.d (modified) (2 diffs)
- trunk/src/defend/game/Game.d (modified) (1 diff)
- trunk/src/defend/objects/SceneNode.d (modified) (2 diffs)
- trunk/src/defend/terrain/Terrain.d (modified) (3 diffs)
- trunk/src/gen/util/Config.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/run/data/shaders/model-pixel.glsl
r538 r539 5 5 # include "shadowmap.glsl" 6 6 7 uniform sampler2D shadow ;7 uniform sampler2D shadowTexture; 8 8 9 9 varying vec4 lightSpacePos; 10 10 #endif 11 11 12 // The model's team color 12 13 uniform vec3 color; 13 14 … … 19 20 gl_FragColor = vec4(tex.rgb * tex.a + color * (1 - tex.a), 1.0) * (light * 2); 20 21 21 /*#ifdef SHADOWMAPPING22 gl_FragColor *= shadowMap(shadow , lightSpacePos);22 #ifdef SHADOWMAPPING 23 gl_FragColor *= shadowMap(shadowTexture, lightSpacePos); 23 24 #else 24 25 gl_FragColor *= gl_Color; 25 #endif */26 #endif 26 27 } trunk/run/data/shaders/shadowmap.glsl
r538 r539 5 5 float shadowMapDistance = texture2D(sampler, shadowMapCoord).r; 6 6 7 return (shadowMapCoord.x >= 0 && shadowMapCoord.x <= 1 && shadowMapCoord.y >= 0 && shadowMapCoord.y <= 1 && 8 lightDistance >= shadowMapDistance && shadowMapDistance != 1.0f) ? 0.35f : 1.0f; 7 return (shadowMapCoord.x >= 0 && 8 shadowMapCoord.x <= 1 && 9 shadowMapCoord.y >= 0 && 10 shadowMapCoord.y <= 1 && 11 12 lightDistance >= shadowMapDistance && 13 shadowMapDistance != 1.0f) ? 0.4f : 1.0f; 9 14 } 10 15 … … 12 17 { 13 18 vec2 shadowMapCoord = 0.5f * lightSpacePos.xy / lightSpacePos.w + vec2(0.5f, 0.5f); 14 float bias = -0.0008f; // avoid shadow aliasing by offseting the shadow a bit19 const float bias = -0.0008f; // avoid shadow aliasing by offseting the shadow a bit 15 20 float lightDistance = 0.5f + bias + lightSpacePos.z / lightSpacePos.w * 0.5f; 16 21 17 22 float val = 0.1f; 18 float o1 = 0.001f;19 float o2 = 0.0005f;23 const float o1 = 0.001f; 24 const float o2 = 0.0005f; 20 25 21 26 #if SHADOWMAPPING_SAMPLES > 0 trunk/run/data/shaders/terrain-pixel.glsl
r537 r539 1 uniform sampler2D alpha ;1 uniform sampler2D alphaMap; 2 2 uniform sampler2D texture1; 3 3 uniform sampler2D texture2; 4 4 uniform sampler2D texture3; 5 uniform sampler2D light map;5 uniform sampler2D lightMap; 6 6 7 7 #ifdef SHADOWMAPPING 8 8 # include "shadowmap.glsl" 9 9 10 uniform sampler2D shadow ;10 uniform sampler2D shadowTexture; 11 11 12 12 varying vec4 lightSpacePos; … … 18 18 vec2 coord1 = vec2(gl_TexCoord[1]); 19 19 20 vec4 a = texture2D(alpha , coord0);20 vec4 a = texture2D(alphaMap, coord0); 21 21 vec4 c1 = texture2D(texture1, coord1); 22 22 vec4 c2 = texture2D(texture2, coord1); 23 23 vec4 c3 = texture2D(texture3, coord1); 24 vec4 l = texture2D(light map, coord0);24 vec4 l = texture2D(lightMap, coord0); 25 25 26 26 float inverse = 1.0f / (a.r + a.g + a.b); … … 32 32 33 33 #ifdef SHADOWMAPPING 34 gl_FragColor *= shadowMap(shadow , lightSpacePos);34 gl_FragColor *= shadowMap(shadowTexture, lightSpacePos); 35 35 #endif 36 36 } trunk/run/defend.cfg
r538 r539 22 22 // port for multiplayer 23 23 port = 31337 24 24 25 25 [graphics] 26 26 // shadow mapping 27 shadowmapping = 128 29 27 [shadowmapping] 28 enable = 1 29 30 30 size = 2048 31 31 samples = 1 trunk/src/defend/Config.d
r535 r539 2 2 3 3 import tango.io.FilePath; 4 //import tango.text.Properties;5 //import tango.util.Convert;6 4 7 5 import gen.math.Vector; … … 52 50 } 53 51 54 Config defendConfig; 55 56 version(none) class Config 57 { 58 static: 59 60 void load(char[] file) 61 { 62 Properties!(char).load(new FilePath(file), (char[] name, char[] value) 63 { 64 entries[name] = value; 65 }); 66 } 67 68 Unstatic!(T) opCall(T)(char[] name, T def) 69 { 70 if(auto entry = name in entries) 71 return to!(Unstatic!(T))(*entry); 72 73 return def; 74 } 75 76 private 77 { 78 char[][char[]] entries; 79 } 80 } 52 CachedConfig!("int graphics.shadowmapping.enable;" 53 "int graphics.shadowmapping.size;" 54 "int graphics.shadowmapping.samples;" 55 "int graphics.lighting;") 56 57 defendConfig; trunk/src/defend/Main.d
r537 r539 78 78 79 79 // Load the config 80 defendConfig = new Config(file);80 defendConfig = new typeof(defendConfig)(file); 81 81 } 82 82 … … 244 244 245 245 // Mirror config settings to shader defines 246 if(defendConfig ("graphics").integer("shadowmapping"))246 if(defendConfig.graphics.shadowmapping.enable) 247 247 { 248 248 Shader.define("SHADOWMAPPING"); trunk/src/defend/game/Game.d
r537 r539 275 275 sceneGraph.addCamera("main", mainCamera, vec3(0, 0, 0.2)); 276 276 277 if(defendConfig ("graphics").integer("shadowmapping"))277 if(defendConfig.graphics.shadowmapping.enable) 278 278 initShadowMapping(); 279 279 trunk/src/defend/objects/SceneNode.d
r538 r539 79 79 Mesh mesh; 80 80 81 CameraData shadowCamera; 82 81 83 public: 82 84 mixin MAllocator; … … 119 121 shader.setUniform("lightTexture", 1); 120 122 121 if(defendConfig ("graphics").integer("shadowmapping"))123 if(defendConfig.graphics.shadowmapping.enable) 122 124 { 123 auto shadow = sceneGraph.getCamera("shadow"); 124 assert(shadow.core !is null); 125 126 shader.setUniform("shadow", 2); 127 shader.setUniform("lightTransform", shadow.core.projection * shadow.core.modelview); 125 shadowCamera = sceneGraph.getCamera("shadow"); 126 127 shader.setUniform("shadowTexture", 2); 128 shader.setUniform("lightTransform", shadowCamera.core.projection * shadowCamera.core.modelview); 128 129 shader.setUniform("modelTransform", absoluteModelview); 129 130 130 renderer.setTexture(2, shadow .framebuffer.texture);131 renderer.setTexture(2, shadowCamera.framebuffer.texture); 131 132 } 132 133 trunk/src/defend/terrain/Terrain.d
r538 r539 398 398 renderer.setTexture(4, lightmapTexture); 399 399 400 shader.setUniform("alpha ", 0);400 shader.setUniform("alphaMap", 0); 401 401 shader.setUniform("texture1", 1); 402 402 shader.setUniform("texture2", 2); 403 403 shader.setUniform("texture3", 3); 404 shader.setUniform("light map", 4);405 406 if(defendConfig ("graphics").integer("shadowmapping"))404 shader.setUniform("lightMap", 4); 405 406 if(defendConfig.graphics.shadowmapping.enable) 407 407 { 408 408 auto shadow = sceneGraph.getCamera("shadow"); … … 410 410 411 411 renderer.setTexture(5, shadow.framebuffer.texture); 412 shader.setUniform("shadow ", 5);412 shader.setUniform("shadowTexture", 5); 413 413 414 414 shader.setUniform("lightTransform", shadow.core.projection * shadow.core.modelview); … … 458 458 renderer.setTexture(4, lightmapTexture); 459 459 460 localShader.setUniform("alpha ", 0);460 localShader.setUniform("alphaMap", 0); 461 461 localShader.setUniform("texture1", 1); 462 462 localShader.setUniform("texture2", 2); 463 463 localShader.setUniform("texture3", 3); 464 localShader.setUniform("light map", 4);464 localShader.setUniform("lightMap", 4); 465 465 466 466 foreach(patch; patches) trunk/src/gen/util/Config.d
r537 r539 6 6 7 7 - structure by indentation (tabs!) 8 - "section"creates a new section8 - [section] creates a new section 9 9 - sections may be nested 10 10 - a = b defines a variable … … 17 17 Example: 18 18 19 section name19 [name] 20 20 a = "b" 21 21 c = 37 22 22 23 section blubber23 [blubber] 24 24 foo = vec3(1, 2, 3) 25 25 blablabla = "blabl\nabla?" … … 50 50 } 51 51 52 finalclass Config : ConfigSection52 class Config : ConfigSection 53 53 { 54 54 private: … … 78 78 return path.dup.pop.toString() ~ "/"; 79 79 } 80 } 81 82 class CachedConfig(char[] names) : Config 83 { 84 private: 85 static char[] extractNames(out char[][] types, out char[][] ids) 86 { 87 char[] result; 88 89 int position; 90 91 do 92 { 93 char[] name; 94 char[] type; 95 char[] id; 96 97 while(names[position] == ' ' || names[position] == '\n' || names[position] == '\r') 98 position++; 99 100 while(names[position] != ';' && position < names.length) 101 name ~= names[position++]; 102 103 position++; 104 105 { 106 int i; 107 108 while(name[i] != ' ' && i < name.length) 109 type ~= name[i++]; 110 111 i++; 112 113 while(i < name.length) 114 id ~= name[i++]; 115 } 116 117 types ~= type; 118 ids ~= id; 119 } 120 while(position != names.length); 121 122 return result; 123 } 124 125 static char[][] splitParts(char[] id) 126 { 127 char[][] result; 128 129 { 130 char[] part; 131 132 foreach(c; id) 133 { 134 if(c != '.') 135 part ~= c; 136 else 137 { 138 result ~= part; 139 part = ""; 140 } 141 } 142 143 result ~= part; 144 } 145 146 return result; 147 } 148 149 static char[] genAssign(char[] type, char[] id) 150 { 151 char[] result = "\t" ~ id ~ " = this"; 152 153 { 154 char[][] parts = splitParts(id); 155 156 for(uint i = 0; i < parts.length; i++) 157 { 158 auto part = parts[i]; 159 160 if(i == parts.length - 1) 161 { 162 result ~= "."; 163 164 if(type == "int") 165 result ~= "integer"; 166 else if(type == "string") 167 result ~= "string"; 168 else 169 assert(false, "unknown type: " ~ type); 170 } 171 else 172 result ~= ".child"; 173 174 result ~= "(\"" ~ part ~ "\")"; 175 } 176 } 177 178 return result ~ ";\n"; 179 } 180 181 static char[] genStructs(char[][] types, char[][] ids, char[] level = "", uint depth = 0) 182 { 183 char[] result = ""; 184 char[][] done = []; 185 186 foreach(i, id; ids) 187 { 188 char[][] parts = splitParts(id); 189 190 if(id.length > level.length && id[0 .. level.length] == level) 191 { 192 if(parts.length == depth + 1) 193 result ~= types[i] ~ " " ~ parts[$ - 1] ~ ";\n"; 194 else 195 { 196 char[] newLevel = level ~ (depth ? "." : "") ~ parts[depth]; 197 198 bool found = false; 199 200 foreach(d; done) 201 { 202 if(d == newLevel) 203 { 204 found = true; 205 break; 206 } 207 } 208 209 if(found) 210 continue; 211 212 done ~= newLevel; 213 214 result ~= "struct _" ~ parts[depth] ~ "\n{\n"; 215 result ~= genStructs(types, ids, newLevel, depth + 1); 216 result ~= "}\n_" ~ parts[depth] ~ " " ~ parts[depth] ~ ";\n"; 217 } 218 } 219 } 220 221 return result; 222 } 223 224 static char[] genCode() 225 { 226 char[] result = ""; 227 228 { 229 char[][] types; 230 char[][] ids; 231 232 extractNames(types, ids); 233 234 result ~= genStructs(types, ids); 235 236 result ~= "this(char[] c)\n{\n\tsuper(c);\n"; 237 238 for(uint i = 0; i < types.length; i++) 239 result ~= genAssign(types[i], ids[i]); 240 241 result ~= "}"; 242 } 243 244 return result; 245 } 246 247 public: 248 //pragma(msg, genCode()); 249 mixin(genCode()); 80 250 } 81 251
