Skip to content

Commit

Permalink
Revert some unintenional changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tsherif committed Apr 7, 2016
1 parent cfbc03d commit 23937a6
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 94 deletions.
122 changes: 115 additions & 7 deletions api/latest/scenejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* A WebGL-based 3D scene graph from xeoLabs
* http://scenejs.org/
*
* Built on 2016-04-04
* Built on 2016-04-07
*
* MIT License
* Copyright 2016, Lindsay Kay
Expand Down Expand Up @@ -10290,10 +10290,10 @@ SceneJS.Library.prototype._compile = function(ctx) { // Bypass child nodes
this._core.lights[index] = light;

var mode = cfg.mode || "dir";
if (mode != "dir" && mode != "point" && mode != "ambient") {
if (mode != "dir" && mode != "point" && mode != "ambient" && mode != "spot") {
throw SceneJS_error.fatalError(
SceneJS.errors.ILLEGAL_NODE_CONFIG,
"Light mode not supported - should be 'dir' or 'point' or 'ambient'");
"Light mode not supported - should be 'dir' or 'point' or 'spot' or 'ambient'");
}

var pos = cfg.pos;
Expand All @@ -10310,8 +10310,10 @@ SceneJS.Library.prototype._compile = function(ctx) { // Bypass child nodes
light.mode = mode;
light.diffuse = (mode == "ambient") ? true : ((cfg.diffuse != undefined) ? cfg.diffuse : true);
light.specular = (mode == "ambient") ? false : ((cfg.specular != undefined) ? cfg.specular : true);
light.pos = cfg.pos ? [ pos.x || 0, pos.y || 0, pos.z || 0 ] : [0, 0, 0];
light.pos = cfg.pos ? [pos.x || 0, pos.y || 0, pos.z || 0 ] : [0, 0, 0];
light.dir = cfg.dir ? [dir.x || 0, dir.y || 0, dir.z || 0] : [0, 0, 1];
light.innerCone = cfg.innerCone != undefined ? cfg.innerCone : 0.25;
light.outerCone = cfg.outerCone != undefined ? cfg.outerCone : 0.5;
light.attenuation = [
cfg.constantAttenuation != undefined ? cfg.constantAttenuation : 0.0,
cfg.linearAttenuation || 0.0,
Expand Down Expand Up @@ -10398,6 +10400,16 @@ SceneJS.Library.prototype._compile = function(ctx) { // Bypass child nodes
imageDirty = true;
}

if (cfg.innerCone != undefined && cfg.innerCone != light.innerCone) {
light.innerCone = cfg.innerCone;
imageDirty = true;
}

if (cfg.outerCone != undefined && cfg.outerCone != light.outerCone) {
light.outerCone = cfg.outerCone;
imageDirty = true;
}

if (cfg.constantAttenuation != undefined) {
light.attenuation[0] = cfg.constantAttenuation;
imageDirty = true;
Expand Down Expand Up @@ -10453,7 +10465,8 @@ SceneJS.Library.prototype._compile = function(ctx) { // Bypass child nodes
coreStack[stackLen] = null; // Release memory
};

})();;(function () {
})();
;(function () {

var defaultMatrix = SceneJS_math_lookAtMat4c(0, 0, 10, 0, 0, 0, 0, 1, 0);
var defaultMat = new Float32Array(defaultMatrix);
Expand Down Expand Up @@ -18277,6 +18290,14 @@ var SceneJS_ProgramSourceFactory = new (function () {
add("uniform vec3 SCENEJS_uLightPos" + i + ";");
}

if (light.mode == "spot") {
add("uniform vec3 SCENEJS_uLightAttenuation" + i + ";");
add("uniform vec3 SCENEJS_uLightPos" + i + ";");
add("uniform vec3 SCENEJS_uLightDir" + i + ";");
add("uniform float SCENEJS_uInnerCone" + i + ";");
add("uniform float SCENEJS_uOuterCone" + i + ";");
}

}
}

Expand Down Expand Up @@ -18517,8 +18538,11 @@ var SceneJS_ProgramSourceFactory = new (function () {
add(" vec3 lightValue = vec3(0.0, 0.0, 0.0);");
add(" vec3 specularValue = vec3(0.0, 0.0, 0.0);");
add(" vec3 viewLightVec;");
add(" vec3 viewLightDir;")
add(" float dotN;");
add(" float spotDirRatio;");
add(" float lightDist;");
add(" float coneDiff;");

if (tangents) {

Expand Down Expand Up @@ -18587,6 +18611,69 @@ var SceneJS_ProgramSourceFactory = new (function () {
}
}

if (light.mode == "spot") {

add("viewLightDir = SCENEJS_uLightDir" + i + ";")

if (light.space == "world") {

// World space

add("viewLightVec = SCENEJS_uLightPos" + i + " - SCENEJS_vWorldVertex.xyz;"); // Vector from World coordinate to light pos

// Transform to View space
add("viewLightVec = vec3(SCENEJS_uVMatrix * vec4(viewLightVec, 0.0)).xyz;");
add("viewLightDir = vec3(SCENEJS_uVMatrix * vec4(viewLightDir, 0.0)).xyz;");

if (tangents) {

// Transform to Tangent space
add("viewLightVec *= TBM;");
add("viewLightDir *= TBM;");
}

} else {

// View space

add("viewLightVec = SCENEJS_uLightPos" + i + ".xyz - SCENEJS_vViewVertex.xyz;"); // Vector from View coordinate to light pos

if (tangents) {

// Transform to tangent space
add("viewLightVec *= TBM;");
add("viewLightDir *= TBM;");
}
}

add("dotN = max(dot(viewNormalVec, normalize(viewLightVec)), 0.0);");
add("spotDirRatio = 1.0 - max(dot(normalize(viewLightDir), normalize(-viewLightVec)), 0.0);");

add("lightDist = length( SCENEJS_uLightPos" + i + " - SCENEJS_vWorldVertex.xyz);");

add("attenuation = 1.0 - (" +
" SCENEJS_uLightAttenuation" + i + "[0] + " +
" SCENEJS_uLightAttenuation" + i + "[1] * lightDist + " +
" SCENEJS_uLightAttenuation" + i + "[2] * lightDist * lightDist);");

add("coneDiff = SCENEJS_uOuterCone" + i + " - SCENEJS_uInnerCone" + i + ";");

add("if (coneDiff == 0.0) {");
add(" attenuation *= 1.0 - step(SCENEJS_uInnerCone" + i + ", spotDirRatio);");
add("} else {");
add(" attenuation *= 1.0 - clamp((spotDirRatio - SCENEJS_uInnerCone" + i + ") / coneDiff, 0.0, 1.0);");
add("}");

if (light.diffuse) {
add(" lightValue += dotN * SCENEJS_uLightColor" + i + " * attenuation;");
}

if (light.specular) {
add(" specularValue += specularColor * SCENEJS_uLightColor" + i +
" * specular * pow(max(dot(reflect(normalize(-viewLightVec), normalize(-viewNormalVec)), normalize(-SCENEJS_vViewVertex.xyz)), 0.0), shine) * attenuation;");
}
}

if (light.mode == "dir") {

if (light.space == "world") {
Expand Down Expand Up @@ -18767,7 +18854,8 @@ var SceneJS_ProgramSourceFactory = new (function () {
}

})
();;/**
();
;/**
* @class Source code for pick and draw shader programs, to be compiled into one or more {@link SceneJS_Program}s
* @private
*
Expand Down Expand Up @@ -20005,6 +20093,8 @@ SceneJS_ChunkFactory.createChunkType({
this._uLightCutOff = this._uLightCutOff || [];
this._uLightSpotExp = this._uLightSpotExp || [];
this._uLightAttenuation = this._uLightAttenuation || [];
this._uInnerCone = this._uInnerCone || [];
this._uOuterCone = this._uOuterCone || [];

var lights = this.core.lights;
var program = this.program;
Expand All @@ -20029,6 +20119,15 @@ SceneJS_ChunkFactory.createChunkType({
this._uLightDir[i] = null;
this._uLightAttenuation[i] = program.draw.getUniform("SCENEJS_uLightAttenuation" + i);
break;

case "spot":
this._uLightColor[i] = program.draw.getUniform("SCENEJS_uLightColor" + i);
this._uLightPos[i] = program.draw.getUniform("SCENEJS_uLightPos" + i);
this._uLightDir[i] = program.draw.getUniform("SCENEJS_uLightDir" + i);
this._uLightAttenuation[i] = program.draw.getUniform("SCENEJS_uLightAttenuation" + i);
this._uInnerCone[i] = program.draw.getUniform("SCENEJS_uInnerCone" + i);
this._uOuterCone[i] = program.draw.getUniform("SCENEJS_uOuterCone" + i);
break;
}
}
},
Expand Down Expand Up @@ -20068,10 +20167,19 @@ SceneJS_ChunkFactory.createChunkType({
if (this._uLightDir[i]) {
this._uLightDir[i].setValue(light.dir);
}

if (this._uInnerCone[i]) {
this._uInnerCone[i].setValue(light.innerCone);
}

if (this._uOuterCone[i]) {
this._uOuterCone[i].setValue(light.outerCone);
}
}
}
}
});;/**
});
;/**
*
*/
SceneJS_ChunkFactory.createChunkType({
Expand Down
20 changes: 10 additions & 10 deletions api/latest/scenejs.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/lighting_directional_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
</style>

<script src="../api/latest/scenejs.js"></script>
<script src="../api/latest/scenejs.min.js"></script>
<script src="libs/dat.gui.min.js"></script>
<link href="css/styles.css" rel="stylesheet"/>

Expand Down Expand Up @@ -168,4 +168,4 @@

</script>
</body>
</html>
</html>
76 changes: 1 addition & 75 deletions src/extras/gui/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SceneJS.GUI = function (scene, nodeIds) {
lookat(node);
break;
case "lights":
spotLight(node, 0);
pointLight(node, 0);
break;
case "material":
material(node);
Expand Down Expand Up @@ -155,80 +155,6 @@ SceneJS.GUI = function (scene, nodeIds) {
folder.open();
}

function spotLight(lights) {
var Menu = function () {
this["pos.x"] = 10.0;
this["pos.y"] = 10.0;
this["pos.z"] = 10.0;
this["color.r"] = 1.0;
this["color.g"] = 1.0;
this["color.b"] = 1.0;
this["dir.x"] = 0.0;
this["dir.y"] = 0.0;
this["dir.z"] = -1.0;
this.innerCone = 0.25;
this.outerCone = 0.3;
this.constantAttenuation = 0.0;
this.linearAttenuation = 0.0;
this.quadraticAttenuation = 0.0;
this.specular = true;
this.diffuse = true;

var self = this;

var update = function () {
lights.setLights({
"0":{
pos:{
x:self["pos.x"],
y:self["pos.y"],
z:self["pos.z"]
},
color:{
r:self["color.r"],
g:self["color.g"],
b:self["color.b"]
},
dir:{
x:self["dir.x"],
y:self["dir.y"],
z:self["dir.z"]
},
innerCone:self.innerCone,
outerCone:self.outerCone,
constantAttenuation:self.constantAttenuation,
linearAttenuation:self.linearAttenuation,
quadraticAttenuation:self.quadraticAttenuation,
specular:self.specular,
diffuse:self.diffuse
}
});
requestAnimationFrame(update);
};
update();
};

var folder = gui.addFolder('Light ' + index);
var menu = new Menu();
folder.add(menu, 'pos.x', -10.0, 10.0);
folder.add(menu, 'pos.y', -10.0, 10.0);
folder.add(menu, 'pos.z', -10.0, 10.0);
folder.add(menu, 'color.r', 0.0, 1.0);
folder.add(menu, 'color.g', 0.0, 1.0);
folder.add(menu, 'color.b', 0.0, 1.0);
folder.add(menu, 'dir.x', 0.0, 1.0);
folder.add(menu, 'dir.y', 0.0, 1.0);
folder.add(menu, 'dir.z', 0.0, 1.0);
folder.add(menu, 'innerCone', 0.0, 1.0);
folder.add(menu, 'outerCone', 0.0, 1.0);
folder.add(menu, 'specular');
folder.add(menu, 'diffuse');
folder.add(menu, 'constantAttenuation', 0.0, 1.0);
folder.add(menu, 'linearAttenuation', 0.0, 1.0);
folder.add(menu, 'quadraticAttenuation', 0.0, 1.0);
folder.open();
}

function dirLight(lights, index, cfg) {

var Menu = function () {
Expand Down

0 comments on commit 23937a6

Please sign in to comment.