Giter VIP home page Giter VIP logo

three-skybox's Introduction

SkyBox

stable

NPM

A self contained class for drawing a skybox for three.js. This feature now exists in three.js (Scene.background) but uses matrices to compute the camera. This one has a slightly different approach, since the cameraPosition is available in shaders as a uniform by default, we can avoid some computation that happens with the backgroundBoxCamera in THREE.WebGLRenderer.

The shader here does one addition and 2 matrix multiplications:

	vec4 wp = vec4( position + cameraPosition , 1. ); 

	vViewDir = position; //no normalization

	gl_Position = projectionMatrix * viewMatrix * wp;

It probably doesnt really affect anything since the cube has a few vertices, but it saves one multiplication and the normalization at the cost of one addition ( the original has 3 multiplications and a normalization ).

Where it could provide some performance saving is by removing the need for the Scene.background logic. There is no need to copy the properties into a different camera, and no need to obtain the mvp matrix since it already cuts on one multiplication in the shader:

	backgroundBoxCamera.projectionMatrix.copy( camera.projectionMatrix ); //no need to copy

	backgroundBoxCamera.matrixWorld.extractRotation( camera.matrixWorld ); //these are somewhat expensive operations
	backgroundBoxCamera.matrixWorldInverse.getInverse( backgroundBoxCamera.matrixWorld );
	backgroundBoxMesh.modelViewMatrix.multiplyMatrices( backgroundBoxCamera.matrixWorldInverse, backgroundBoxMesh.matrixWorld );

Constructor

  • SkyBox( renderer:[ THREE.WebGLRenderer ] , (opt) cubemap:[ THREE.TextureCube ] )

    The renderer is required for construction, the cubemap can be assigned later.

Properties

  • cubemap:[ THREE.TextureCube ]

    the cubemap currently assigned to the skybox

Methods

  • void render( camera:[THREE.Camera] )

    renders the skybox to the window frame buffer, call it before rendering the main scene

Install

$ npm install three-skybox

Usage

var SkyBox = require('three-skybox')(THREE);

var skybox = new SkyBox( renderer , myTextureCube );


function render(){

	skybox.render( camera );

	renderer.render( scene , camera )

}

three-skybox's People

Contributors

pailhead avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.