Skip to content

Commit

Permalink
WIP. shadowmap
Browse files Browse the repository at this point in the history
  • Loading branch information
sasha240100 committed Dec 7, 2015
1 parent 62aa0a6 commit 40df944
Show file tree
Hide file tree
Showing 10 changed files with 663 additions and 322 deletions.
Binary file added assets/terrain/NormalMap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
533 changes: 348 additions & 185 deletions build/whitestorm.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions build/whitestorm.min.js

Large diffs are not rendered by default.

Binary file added examples/assets/terrain/NormalMap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 16 additions & 3 deletions examples/fps.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@
GAME.light1 = GAME.addLight("directional", {
color: 0xffffff, //0x00ff00,
intensity: 1
}, {
x: 80, // 100,
y: 110, // 30,
z: 80, // 100
}, {
x: 0,
y: 0,
z: 0
});

/*GAME.light1 = GAME.addLight("point", {
color: 0xffffff, //0x00ff00,
intensity: 0.8
}, {
x: 100, // 100,
y: 110, // 30,
Expand All @@ -62,11 +75,11 @@
x: 0,
y: 0,
z: 0
});
});*/


// NOTE: Default light.
GAME.light1 = GAME.addLight("directional", {
/*GAME.light1 = GAME.addLight("directional", {
color: 0xffffff, //0x00ff00,
intensity: 1
}, {
Expand All @@ -77,7 +90,7 @@
x: 70,
y: 72,
z: 70
});
});*/

GAME.parrot = GAME.addMorph("assets/models/morph/parrot.js", {
geometryOptions: {
Expand Down
30 changes: 24 additions & 6 deletions src/Ground/addGround.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ WHS.init.prototype.addGround = function(type, size, material, pos) {

var normalMap = new THREE.WebGLRenderTarget( rx, ry, pars );
normalMap.texture = api.TextureLoader()
.load('../assets/terrain/default_terrain.png');
.load('../assets/terrain/NormalMap.png');

var specularMap = new THREE.WebGLRenderTarget( 256, 256, pars ); //2048
specularMap.texture = api.TextureLoader()
Expand Down Expand Up @@ -178,8 +178,7 @@ WHS.init.prototype.addGround = function(type, size, material, pos) {
});

uniformsTerrain[ "tDisplacement" ].value = heightMap;

//uniformsTerrain[ "shadowMap" ].value = heightMap;
uniformsTerrain[ "shadowMap" ].value = [normalMap];

uniformsTerrain[ "uDisplacementScale" ].value = 100;

Expand All @@ -196,7 +195,9 @@ WHS.init.prototype.addGround = function(type, size, material, pos) {
shading: THREE.SmoothShading
} );

var geom = new THREE.PlaneGeometry(256, 256, 256, 256);
var geom = new THREE.PlaneGeometry(256, 256, 255, 255);

//THREE.BufferGeometryUtils.computeTangents( geom );

geom.verticesNeedUpdate = true;

Expand All @@ -207,16 +208,33 @@ WHS.init.prototype.addGround = function(type, size, material, pos) {

scope._rot.set(Math.PI / 180 * -90, 0, 0);

var hgtdata = []; // new Array(256);

var hgtdata = [], index = 0, i = 0; // new Array(256);
var imgdata = ctx.getImageData(0, 0, 256, 256).data;
//console.log(geom);
for (var x=0; x <= 255; x++) {
hgtdata[x] = new Uint8Array(256);

for (var y=255; y >= 0; y--) {
hgtdata[x][255-y] = ctx.getImageData(x, y, 1, 1).data[0]/255 * 100;
geom.vertices[index].z = imgdata[i]/255 * 100;
i += 4;
index++;
}
}


/*var height_img_data = ctx.getImageData(0, 0, 256, 256).data;
var z, index = 0;
for( var i = 0, l = height_img_data.length; i<l; i+=4){
z = height_img_data[i];
geom.vertices[index].z = z / 255 * 100;
index = index + 1;
}*/

geom.computeVertexNormals();
geom.computeFaceNormals();
geom.computeTangents();

scope.visible.updateMatrix();
scope.physic = new CANNON.Heightfield(
hgtdata,
Expand Down
19 changes: 13 additions & 6 deletions src/Light/addLight.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ WHS.init.prototype.addLight = function(type, opts, pos, target) {
options.distance
);

//scope.visible.visible = false;

break;

case "spot":
Expand All @@ -82,21 +84,26 @@ WHS.init.prototype.addLight = function(type, opts, pos, target) {
break;
}

scope.visible.shadowCameraVisible = true;
//scope.visible.shadowCameraVisible = true;

scope.visible.castShadow = true;

// #FIXME:20 Shadow default parameters.
scope.visible.shadowMapWidth = 1024;
scope.visible.shadowMapHeight = 1024;
scope.visible.shadowMapWidth = 2048;
scope.visible.shadowMapHeight = 2048;
//scope.visible.shadowBias = 0.05;

scope.visible.shadowCameraNear = 50;
scope.visible.shadowCameraFar = 4000;
scope.visible.shadowCameraFar = 200;
scope.visible.shadowCameraFov = 30;
scope.visible.shadowDarkness = 0.5;

var d = 120;

if(type == "directional")
var debug = new THREE.DirectionalLightHelper( scope.visible, 1 );
scope.visible.shadowCameraLeft = -d
scope.visible.shadowCameraRight = d
scope.visible.shadowCameraTop = d
scope.visible.shadowCameraBottom = -d


if (scope.visible.target)
Expand Down

0 comments on commit 40df944

Please sign in to comment.