Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: native webvr #45

Merged
merged 3 commits into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: move shaders to their own files
  • Loading branch information
brandonocasey committed Jan 17, 2018
commit 977d8cb9a672d0a6b9f55b2ff4d92087451094cc
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"watch:js-modules": "rollup -c scripts/modules.rollup.config.js -w",
"watch:js-umd": "rollup -c scripts/umd.rollup.config.js -w",
"watch:test": "rollup -c scripts/test.rollup.config.js -w",
"prepublishOnly": "npm run build",
"prepublish": "not-in-install && npm run build || in-install",
"prepush": "npm run lint",
"precommit": "npm run docs:toc && git add README.md"
},
Expand Down Expand Up @@ -105,6 +105,7 @@
"doctoc": "^1.3.0",
"es5-shim": "^4.5.9",
"husky": "^0.13.3",
"in-publish": "^2.0.0",
"jsdoc": "^3.4.3",
"karma": "~1.3.0",
"karma-chrome-launcher": "^2.1.1",
Expand Down
51 changes: 13 additions & 38 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import * as THREE from 'three';
import VRControls from 'three/examples/js/controls/VRControls.js';
import VREffect from 'three/examples/js/effects/VREffect.js';
import OrbitControls from 'three/examples/js/controls/OrbitControls.js';
import rgbFragmentShader from './rgb-fragment-shader';
import rgbaFragmentShader from './rgba-fragment-shader';
import vertexShader from './vertex-shader';

// import controls so they get regisetered with videojs
import './cardboard-button';
Expand Down Expand Up @@ -387,45 +390,17 @@ class VR extends Plugin {
this.videoTexture.format = THREE.RGBFormat;
}

if (this.videoTexture.format === THREE.RGBAFormat && this.videoTexture.flipY === false) {
this.movieMaterial = new THREE.ShaderMaterial({
uniforms: {
texture: { value: this.videoTexture }
},
vertexShader: [
'varying vec2 vUV;',
'void main() {',
' vUV = vec2( uv.x, 1.0 - uv.y );',
' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
'}'
].join('\n'),
fragmentShader: [
'uniform sampler2D texture;',
'varying vec2 vUV;',
'void main() {',
' gl_FragColor = texture2D( texture, vUV ).bgra;',
'}'
].join('\n')
});
} else if (this.videoTexture.format === THREE.RGBFormat && this.videoTexture.flipY === false) {
if ((this.videoTexture.format === THREE.RGBAFormat || this.videoTexture.format === THREE.RGBFormat) && this.videoTexture.flipY === false) {
let fragmentShader = rgbFragmentShader;

if (this.videoTexture.format === THREE.RGBAFormat) {
fragmentShader = rgbaFragmentShader;
}

this.movieMaterial = new THREE.ShaderMaterial({
uniforms: {
texture: { value: this.videoTexture }
},
vertexShader: [
'varying vec2 vUV;',
'void main() {',
' vUV = vec2( uv.x, 1.0 - uv.y );',
' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
'}'
].join('\n'),
fragmentShader: [
'uniform sampler2D texture;',
'varying vec2 vUV;',
'void main() {',
' gl_FragColor = texture2D( texture, vUV );',
'}'
].join('\n')
uniforms: {texture: {value: this.videoTexture}},
vertexShader,
fragmentShader
});
} else {
this.movieMaterial = new THREE.MeshBasicMaterial({ map: this.videoTexture, overdraw: true, side: THREE.DoubleSide });
Expand Down
5 changes: 5 additions & 0 deletions src/rgb-fragment-shader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = `uniform sampler2D texture;
varying vec2 vUV;
void main() {
gl_FragColor = texture2D(texture, vUV);
}`;
5 changes: 5 additions & 0 deletions src/rgba-fragment-shader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = `uniform sampler2D texture;
varying vec2 vUV;
void main() {
gl_FragColor = texture2D(texture, vUV).bgra;
}`;
5 changes: 5 additions & 0 deletions src/vertex-shader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = `varying vec2 vUV;
void main() {
vUV = vec2( uv.x, 1.0 - uv.y );
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}`;