Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jhughes committed Sep 20, 2018
0 parents commit a0fc792
Show file tree
Hide file tree
Showing 36 changed files with 2,704 additions and 0 deletions.
Binary file added assets/metallic.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/normal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/nx (1).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/nx.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/nx_3js.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ny.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ny_3js.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/nz.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/nz_3js.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/px.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/px_3js.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/py.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/py_3js (1).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/py_3js.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/pz.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/pz_3js.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/roughness.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprite_additive_rect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
body{
min-width: 1024px;
overflow: hidden;
margin: 0px;
padding: 0px;
background: #000;
font-family: Helvetica, arial, sans-serif;
}
canvas{
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}

::-webkit-scrollbar {
width: 2px;
}
::-webkit-scrollbar-track {
border-radius: 2px;
background: #333;
}
::-webkit-scrollbar-thumb {
border-radius: 2px;
background: #999;
}
::-webkit-scrollbar-thumb:window-inactive {
background: #999;
}


31 changes: 31 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<!--css-->
<link rel="stylesheet" type="text/css" href="css/style.css">
<!--libraries-->
<script type="text/javascript" src="js/three.min.js"></script>
<script type="text/javascript" src="js/dat.gui.min.js"></script>
<!--tools-->
<script type="text/javascript" src="js/AudioAnalyzer.js"></script>
<script type="text/javascript" src="js/ThreeSharedRenderer.js"></script>
<script type="text/javascript" src="js/ThreePBR.js"></script>
<script type="text/javascript" src="js/ThreePointLight.js"></script>
<script type="text/javascript" src="js/DeviceChecker.js"></script>
<!--shaders-->
<script type="text/javascript" src="shaders/blob.vert.js"></script>
<script type="text/javascript" src="shaders/blob.frag.js"></script>
<script type="text/javascript" src="shaders/skybox.vert.js"></script>
<script type="text/javascript" src="shaders/skybox.frag.js"></script>
<!--objects-->
<script type="text/javascript" src="js/NoiseBlob.js"></script>
<script type="text/javascript" src="js/Ctrl.js"></script>
<!--main-->
<script type="text/javascript" src="js/script.js"></script>
</head>
<body>
<canvas></canvas>
</body>
</html>
189 changes: 189 additions & 0 deletions js/AudioAnalyzer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
var AudioAnalyzer = function(){
this.is_init = false;
this.is_pulse = false;

navigator.getUserMedia = (
navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);

if (navigator.getUserMedia) {
console.log('getUserMedia supported.');
navigator.getUserMedia ({
audio: true
}, this.init.bind(this),
this.init_without_stream.bind(this));
} else {
if(window.location.protocol == 'https:')
this.init_without_stream();
console.log('getUserMedia not supported on your browser!');
}
};

AudioAnalyzer.prototype.init = function(_stream){
var _ctx = new (
window.AudioContext ||
window.webkitAudioContext ||
window.mozAudioContext ||
window.msAudioContext)();

var _source = _ctx.createMediaStreamSource(_stream);

// https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode
this.analyzer = _ctx.createAnalyser();
this.analyzer.fftSize = 128;

this.gain = _ctx.createGain();
_source.connect(this.gain);
this.gain.connect(this.analyzer);
this.gain.gain.value = 70.;

this.bass = 0.;
this.mid = 0.;
this.high = 0.;
this.level = 0.;

this.frame = 0;

this.reset_history();

this.buffer_length = this.analyzer.frequencyBinCount;
this.audio_buffer = new Uint8Array(this.buffer_length);

console.log("audio analyzer is init");

this.is_init = true;
};

AudioAnalyzer.prototype.init_without_stream = function(){
alert("microphone is not detected. pulse is activated instead of mic input");

this.bass = 0.;
this.mid = 0.;
this.high = 0.;
this.level = 0.;

this.frame = 0;

this.reset_history();

console.log("audio analyzer is init without mic");

this.is_init = true;
this.is_pulse = true;
};

AudioAnalyzer.prototype.update = function(){
if(this.is_init){
var _bass = 0., _mid = 0., _high = 0.;

if(!this.is_pulse){
this.analyzer.getByteFrequencyData(this.audio_buffer);

var _pass_size = this.buffer_length/3.;
for(var i = 0; i < this.buffer_length; i++){
var _val = Math.pow(this.audio_buffer[i] / 256., 2.);

if(i < _pass_size)
_bass += _val;
else if(i >= _pass_size && i < _pass_size*2)
_mid += _val;
else if(i >= _pass_size*2)
_high += _val;
}

_bass /= _pass_size;
_mid /= _pass_size;
_high /= _pass_size;
} else {
if(this.frame % 40 == (Math.floor(Math.random()*40.))){
_bass = Math.random();
_mid = Math.random();
_high = Math.random();
}
}

this.bass = this.bass > _bass ? this.bass * .96 : _bass;
this.mid = this.mid > _mid ? this.mid * .96 : _mid;
this.high = this.high > _high ? this.high * .96 : _high;

this.level = (this.bass + this.mid + this.high)/3.;

this.history += this.level * .01 + .005;
}

this.frame++;
};

AudioAnalyzer.prototype.reset_history = function(){
this.history = 0.;
};

AudioAnalyzer.prototype.set_gain = function(_val){
if(this.gain)
this.gain.gain.value = _val;
};

AudioAnalyzer.prototype.get_gain = function(){
if(this.gain)
this.gain.gain.value;
};

AudioAnalyzer.prototype.get_bass = function(){
return this.bass == undefined ? 0. : this.bass;
};

AudioAnalyzer.prototype.get_mid = function(){
return this.mid == undefined ? 0. : this.mid;
};

AudioAnalyzer.prototype.get_high = function(){
return this.high == undefined ? 0. : this.high;
};

AudioAnalyzer.prototype.get_level = function(){
return this.level == undefined ? 0. : this.level;
};

AudioAnalyzer.prototype.get_history = function(){
return this.history == undefined ? 0. : this.history;
};

AudioAnalyzer.prototype.trigger_pulse = function(_is_pulse){
this.is_pulse = _is_pulse;
};

AudioAnalyzer.prototype.debug = function(_canvas){
var _ctx = _canvas.getContext("2d");

_ctx.fillStyle = 'rgb(0, 0, 0)';
_ctx.fillRect(0, 0, _canvas.width, _canvas.height);

var _w = (_canvas.width / this.buffer_length);
var _h;
var _x = 0;

_x = 0;
_w = (_canvas.width / 4.);

_h = this.bass * _canvas.height;
_ctx.fillStyle = 'rgb(200,0,0)';
_ctx.fillRect(_x,_canvas.height-_h,_w,_h);
_x += _w;

_h = this.mid * _canvas.height;
_ctx.fillStyle = 'rgb(0,200,0)';
_ctx.fillRect(_x,_canvas.height-_h,_w,_h);
_x += _w;

_h = this.high * _canvas.height;
_ctx.fillStyle = 'rgb(0,0,200)';
_ctx.fillRect(_x,_canvas.height-_h,_w,_h);
_x += _w;

_h = this.level * _canvas.height;
_ctx.fillStyle = 'rgb(200,200,200)';
_ctx.fillRect(_x,_canvas.height-_h,_w,_h);
_x += _w;
};
45 changes: 45 additions & 0 deletions js/Ctrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// need datgui lib & threejs lib

var Ctrl = function(_blob, _light, _pbr, _audio){
this.params = {
show_hdr: true,
debug_shadow_map: false,
cam_ziggle: true,
light_ziggle: true,
audio_gain: 70.
}

// var _g_blob = new dat.GUI();
var _g_scene = new dat.GUI();

this.blob = _blob;
this.light = _light;
this.pbr = _pbr;
this.audio = _audio;

// _g_scene.add(this.params, 'debug_shadow_map').onFinishChange( this.update_params.bind(this) );

// _g_scene.add(this.params, 'cam_ziggle');
// _g_scene.add(this.params, 'light_ziggle');
_g_scene.add(this.params, 'audio_gain', 0., 500.).onChange( this.update_params.bind(this) );
_g_scene.add(this.audio, 'is_pulse');
_g_scene.add(this.blob, 'show_hdr').onFinishChange( this.blob.toggle_cubemap.bind(this.blob) );

// _g_blob.add(this.pbr, 'normal', 0., 5.);
// _g_blob.add(this.pbr, 'roughness', 0., 10.);
// _g_blob.add(this.pbr, 'metallic', 0., 10.);
// _g_blob.add(this.pbr, 'exposure', 0., 20.);
// _g_blob.add(this.pbr, 'gamma', 0., 10.);

this.update_params();

// dat.GUI.toggleHide();
};

Ctrl.prototype.update_params = function(){
var _p = this.params;

this.blob.debug_shadow_map(_p.debug_shadow_map);
this.audio.set_gain(this.params.audio_gain);
this.light.set_light_pos( new THREE.Vector3(_p.light_posx, _p.light_posy, _p.light_posz) );
};
16 changes: 16 additions & 0 deletions js/DeviceChecker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a0fc792

Please sign in to comment.