Skip to content

Commit

Permalink
Setup for recording video
Browse files Browse the repository at this point in the history
  • Loading branch information
henryseg committed Jan 26, 2019
1 parent c769544 commit a2bcbcd
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 41 deletions.
9 changes: 7 additions & 2 deletions js/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ var onResize = function(){
console.log(controller.inspect());
controller.addEventListener('primary press began', function(){ g_controllerMove = true; });
controller.addEventListener('primary press ended', function(){ g_controllerMove = false; });
g_material.uniforms.controllerCount.value++;

//This only works for OpenVR controllers
//For example the oculus uses thumbstick instead of thumbpad
controller.addEventListener('thumbpad axes changed', function(event){
var HueSat = axesToHueSat(event.axes);
console.log(HueSat);
//console.log(HueSat);
if(HueSat.x !== 0.5 && HueSat.y !== 0){
var HSV = new THREE.Vector3(HueSat.x, HueSat.y, 1.0);
var RGB = HSVtoRGB(HSV);
lightIntensities[event.target.gamepad.index + 4] = new THREE.Vector4(RGB.x, RGB.y, RGB.z, 2.0);
lightIntensities[4] = new THREE.Vector4(RGB.x, RGB.y, RGB.z, 2.0);
}
});
}
Expand Down Expand Up @@ -78,6 +79,10 @@ var onResize = function(){
document.body.addEventListener('click', function(event){
if(event.target.id === "vr-icon"){
event.target.style.display = "none";
if (navigator.getVRDisplays) navigator.getVRDisplays().then( g_effect.gotVRDisplay );
else if ( navigator.getVRDevices ) navigator.getVRDevices().then( g_effect.gotVRDevices );
else navigator.mozGetVRDevices( g_effect.gotVRDevices );

}
});

Expand Down
6 changes: 2 additions & 4 deletions js/HyperSpace.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ var initLights = function(g){
PointLightObject(g, new THREE.Vector3(0,-1.1,0), new THREE.Vector4(1,1,1,1));
//Add light info for controllers
lightIntensities.push(new THREE.Vector4(0.49, 0.28, 1.0, 2));
lightIntensities.push(new THREE.Vector4(1.0, 0.404, 0.19, 2));
}

//-------------------------------------------------------
Expand All @@ -188,9 +187,8 @@ var initObjects = function(g){
invGlobalObjectBoosts = [];
globalObjectRadii = [];
globalObjectTypes = [];
SphereObject(g, new THREE.Vector3(-0.5,0,0), 0.2); // geometry, position, radius/radii
SphereObject(g, new THREE.Vector3(0.5,0,0), 0.05); //radii must be less than one!
for(var i = 2; i<4; i++){ // We need to fill out our arrays with empty objects for glsl to be happy
SphereObject(g, new THREE.Vector3(0,-0.7,0), 0.2); // geometry, position, radius/radii
for(var i = 1; i<4; i++){ // We need to fill out our arrays with empty objects for glsl to be happy
EmptyObject();
}
}
Expand Down
28 changes: 16 additions & 12 deletions shaders/fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ float globalSceneSDF(vec4 samplePoint, mat4 globalTransMatrix, bool collideWithL
float distance = maxDist;
if(collideWithLights){
//Light Objects
for(int i=0; i<NUM_LIGHTS; i++){
for(int i=0; i<3; i++){
float objDist;
if(lightIntensities[i].w == 0.0) { objDist = maxDist; }
else{
Expand All @@ -16,20 +16,24 @@ float globalSceneSDF(vec4 samplePoint, mat4 globalTransMatrix, bool collideWithL
}
}
}
//Controller Objects
for(int i=0; i<2; i++){
if(controllerCount != 0){
float objDist = sphereSDF(samplePoint, ORIGIN*controllerBoosts[i]*currentBoost, 1.0/(10.0 * lightIntensities[i+NUM_LIGHTS].w));
distance = min(distance, objDist);
if(distance < EPSILON){
hitWhich = 1;
globalLightColor = lightIntensities[i+4];
return distance;
}
if(controllerCount == 1) break;
if(controllerCount != 0){
float objDist = sphereSDF(samplePoint, ORIGIN*controllerBoosts[0]*currentBoost, 1.0/(10.0 * lightIntensities[4].w));
distance = min(distance, objDist);
if(distance < EPSILON){
hitWhich = 1;
globalLightColor = lightIntensities[4];
return distance;
}
}
}
if(controllerCount == 2){
float objDist = sphereSDF(samplePoint, ORIGIN*controllerBoosts[1]*currentBoost, 1.0/(10.0 * lightIntensities[4].w));
distance = min(distance, objDist);
if(distance < EPSILON){
hitWhich = 2;
return distance;
}
}
//Global Objects
for(int i=0; i<NUM_OBJECTS; i++) {
float objDist;
Expand Down
3 changes: 1 addition & 2 deletions shaders/globalsInclude.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ uniform float maxDist;
//Lighting Variables & Global Object Variables
//--------------------------------------------
uniform vec4 lightPositions[4];
uniform vec4 lightIntensities[6]; //w component is the light's attenuation -- 6 since we need controllers
uniform vec4 lightIntensities[5]; //w component is the light's attenuation -- 5 for our controller
uniform int attnModel;
uniform bool renderShadows[2];
uniform float shadSoft;
uniform sampler2D texture;
uniform int controllerCount; //Max is two
uniform mat4 controllerBoosts[2];
//uniform vec4 controllerDualPoints[6];
uniform mat4 globalObjectBoosts[4];
uniform mat4 invGlobalObjectBoosts[4];
uniform vec3 globalObjectRadii[4];
Expand Down
14 changes: 5 additions & 9 deletions shaders/lighting.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,17 @@ vec3 phongModel(mat4 invObjectBoost, bool isGlobal, mat4 globalTransMatrix){
//Lighting Calculations
//--------------------------------------------
//Standard Light Objects
for(int i = 0; i<NUM_LIGHTS; i++){
for(int i = 0; i<3; i++){
if(lightIntensities[i].w != 0.0){
TLP = lightPositions[i]*globalTransMatrix;
color += lightingCalculations(SP, TLP, V, baseColor, lightIntensities[i], globalTransMatrix);
}
}

//Lights for Controllers
for(int i = 0; i<2; i++){
if(controllerCount == 0) break; //if there are no controllers do nothing
else TLP = ORIGIN*controllerBoosts[i]*currentBoost*cellBoost*globalTransMatrix;

color += lightingCalculations(SP, TLP, V, baseColor, lightIntensities[i+4], globalTransMatrix);

if(controllerCount == 1) break; //if there is one controller only do one loop
//Light for Controller
if(controllerCount != 0){
TLP = ORIGIN*controllerBoosts[0]*currentBoost*cellBoost*globalTransMatrix;
color += lightingCalculations(SP, TLP, V, baseColor, lightIntensities[4], globalTransMatrix);
}

return color;
Expand Down
11 changes: 5 additions & 6 deletions vr/VRController.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ THREE.VRController = function( gamepad ){
})
}
if( supported.buttons !== undefined ){
supported.buttons.forEach( function( buttonName, i ){
buttons[ i ].name = buttonName
})
//supported.buttons.forEach( function( buttonName, i ){
// buttons[ i ].name = buttonName
//})
}
buttonNamePrimary = supported.primary
}
Expand All @@ -85,7 +85,7 @@ THREE.VRController = function( gamepad ){
})

if( buttonNamePrimary === undefined ) buttonNamePrimary = gamepad.buttons.length > 1 ? 'button_1' : 'button_0'
buttons.byName[ buttonNamePrimary ].isPrimary = true
//buttons.byName[ buttonNamePrimary ].isPrimary = true

// Let’s make some getters!
this.getHandedness = function(){
Expand Down Expand Up @@ -297,7 +297,6 @@ THREE.VRController.prototype.update = function(){
g_controllerDualPoints[5] = hyperPos.geometryDirection(g_geometry, hyperPos.applyMatrix4(translateByVector(g_geometry, new THREE.Vector3(0.0, 0.0, 0.1))));
}*/

g_material.uniforms.controllerCount.value = this.controllers.length;
this.pollForChanges()
this.applyVibes()
if( typeof this.updateCallback === 'function' ) this.updateCallback()
Expand Down Expand Up @@ -420,7 +419,7 @@ THREE.VRController.onGamepadDisconnect = function( gamepad ){

THREE.VRController.update = function(){
var gamepads, gamepad, i

if( navigator.getGamepads === undefined ) return
gamepads = navigator.getGamepads()
for( i = 0; i < gamepads.length; i ++ ){
Expand Down
14 changes: 8 additions & 6 deletions vr/VREffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ THREE.VREffect = function ( renderer, done ) {
return;
}

if (navigator.getVRDisplays) navigator.getVRDisplays().then( gotVRDisplay );
else if ( navigator.getVRDevices ) navigator.getVRDevices().then( gotVRDevices );
else navigator.mozGetVRDevices( gotVRDevices );
//if (navigator.getVRDisplays) navigator.getVRDisplays().then( gotVRDisplay );
//else if ( navigator.getVRDevices ) navigator.getVRDevices().then( gotVRDevices );
//else navigator.mozGetVRDevices( gotVRDevices );

if(self.leftEyeTranslation.x == undefined){
//we need these to be objects instead of arrays in order to process the information correctly
Expand All @@ -67,7 +67,7 @@ THREE.VREffect = function ( renderer, done ) {
self.getEyeRotation(self.leftEyeTranslation.x);
}

function gotVRDisplay( devices ) {
this.gotVRDisplay = function( devices ) {
var vrHMD;
var error;
for ( var i = 0; i < devices.length; ++i ) {
Expand All @@ -83,6 +83,7 @@ THREE.VREffect = function ( renderer, done ) {
document.getElementById("crosshair").style.visibility = 'hidden';
guiInfo.toggleStereo = true;
self.getEyeRotation(self.leftEyeTranslation.x);
g_material.uniforms.isStereo.value = 1;
break; // We keep the first we encounter
}
}
Expand All @@ -93,7 +94,7 @@ THREE.VREffect = function ( renderer, done ) {
}
}

function gotVRDevices( devices ) {
this.gotVRDevices = function( devices ) {
var vrHMD;
var error;
for ( var i = 0; i < devices.length; ++i ) {
Expand Down Expand Up @@ -129,12 +130,13 @@ THREE.VREffect = function ( renderer, done ) {
var vrHMD = this._vrHMD;
// VR render mode if HMD is available
if ( vrHMD ) {
g_material.uniforms.isStereo.value = 1;
vrHMD.requestAnimationFrame(animate);
renderer.render.apply( this._renderer, [scene, camera] );
if (vrHMD.submitFrame !== undefined && this._vrMode) {
// vrHMD.getAnimationFrame(frameData);
vrHMD.submitFrame();
}
return;
}

requestAnimationFrame(animate);
Expand Down

0 comments on commit a2bcbcd

Please sign in to comment.