Skip to content

Commit

Permalink
Added "glow" to lights and fixed soft shadows so that the lowest posi…
Browse files Browse the repository at this point in the history
…tion is the same as hard shadows.
  • Loading branch information
mtwoodard committed Jan 21, 2019
1 parent 279eeeb commit e5bf3dc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
4 changes: 1 addition & 3 deletions js/HyperSpace.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ var loadShaders = function(){ //Since our shader is made up of strings we can co
}

var finishInit = function(fShader){
// console.log(fShader);
g_material = new THREE.ShaderMaterial({
uniforms:{
isStereo:{type: "i", value: 0},
Expand All @@ -288,12 +287,11 @@ var finishInit = function(fShader){
lightIntensities:{type:"v3v", value:lightIntensities},
attnModel:{type:"i", value:attnModel},
renderShadows:{type:"bv", value:[false, false]},
shadSoft:{type:"f", value:128.0},
shadSoft:{type:"f", value:10000.0},
texture:{type:"t", value: new THREE.TextureLoader().load("images/concrete2.png")},
// texture:{type:"t", value: new THREE.TextureLoader().load("images/white.png")},
controllerCount:{type:"i", value: 0},
controllerBoosts:{type:"m4", value:g_controllerBoosts},
//controllerDualPoints:{type:"v4v", value:g_controllerDualPoints},
globalObjectBoosts:{type:"m4v", value:globalObjectBoosts},
invGlobalObjectBoosts:{type:"m4v", value:invGlobalObjectBoosts},
globalObjectRadii:{type:"v3v", value:globalObjectRadii},
Expand Down
2 changes: 1 addition & 1 deletion js/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ var initGui = function(){

softnessController.onChange(function(value){
if(value === 0.0){
g_material.uniforms.shadSoft.value = 128.0;
g_material.uniforms.shadSoft.value = 10000.0;
}
else{
g_material.uniforms.shadSoft.value = 1.0/value;
Expand Down
13 changes: 12 additions & 1 deletion shaders/fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//GLOBAL OBJECTS SCENE ++++++++++++++++++++++++++++++++++++++++++++++++
float globalSceneSDF(vec4 samplePoint, mat4 globalTransMatrix, bool collideWithLights){
float distance = maxDist;
float glowStrength = 4.0;
if(collideWithLights){
//Light Objects
for(int i=0; i<NUM_LIGHTS; i++){
Expand All @@ -14,6 +15,9 @@ float globalSceneSDF(vec4 samplePoint, mat4 globalTransMatrix, bool collideWithL
globalLightColor = lightIntensities[i];
return distance;
}
else{
glow[i] = max(glow[i], 1.0-(glowStrength*distance));
}
}
}
//Controller Objects
Expand Down Expand Up @@ -212,13 +216,20 @@ void main(){
rayDirV *= currentBoost;
//generate direction then transform to hyperboloid ------------------------
vec4 rayDirVPrime = geometryDirection(rayOrigin, rayDirV);

for(int i = 0; i<NUM_LIGHTS+1; i++){
glow[i] = 0.0;
}

//get our raymarched distance back ------------------------
mat4 totalFixMatrix = mat4(1.0);
raymarch(rayOrigin, rayDirVPrime, totalFixMatrix);

//Based on hitWhich decide whether we hit a global object, local object, or nothing
if(hitWhich == 0){ //Didn't hit anything ------------------------
gl_FragColor = vec4(0.0);
for(int i = 0; i<NUM_LIGHTS; i++){
gl_FragColor = vec4(0.2 * glow[i] * lightIntensities[i].xyz, 1.0);
}
return;
}
else if(hitWhich == 1){ // global lights
Expand Down
1 change: 1 addition & 0 deletions shaders/globalsInclude.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ vec4 sampleTangentVector = vec4(1, 1, 1, 1);
vec4 N = ORIGIN; //normal vector
vec4 globalLightColor = ORIGIN;
int hitWhich = 0;
float glow[NUM_LIGHTS+1];
//-------------------------------------------
//Translation & Utility Variables
//--------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions shaders/lighting.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ vec3 phongModel(mat4 invObjectBoost, bool isGlobal, mat4 globalTransMatrix){
if(lightIntensities[i].w != 0.0){
TLP = lightPositions[i]*globalTransMatrix;
color += lightingCalculations(SP, TLP, V, baseColor, lightIntensities[i], globalTransMatrix);
color += 0.2 * glow[i] * lightIntensities[i].xyz;
}
}

Expand Down

0 comments on commit e5bf3dc

Please sign in to comment.