Skip to content

Commit

Permalink
Merge pull request #15138 from WestLangley/dev-background_offset_repeat
Browse files Browse the repository at this point in the history
Background shader: support texture offset/repeat
  • Loading branch information
mrdoob committed Oct 31, 2018
2 parents 6081478 + e59c0b6 commit ef9c0fe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/renderers/shaders/ShaderLib.js
Expand Up @@ -3,6 +3,7 @@ import { UniformsUtils } from './UniformsUtils.js';
import { Vector3 } from '../../math/Vector3.js';
import { UniformsLib } from './UniformsLib.js';
import { Color } from '../../math/Color.js';
import { Matrix3 } from '../../math/Matrix3.js';

/**
* @author alteredq / http://alteredqualia.com/
Expand Down Expand Up @@ -195,6 +196,7 @@ var ShaderLib = {
background: {

uniforms: {
uvTransform: { value: new Matrix3() },
t2D: { value: null },
},

Expand Down
3 changes: 2 additions & 1 deletion src/renderers/shaders/ShaderLib/background_vert.glsl
@@ -1,8 +1,9 @@
varying vec2 vUv;
uniform mat3 uvTransform;

void main() {

vUv = uv;
vUv = ( uvTransform * vec3( uv, 1 ) ).xy;

gl_Position = vec4( position, 1.0 );
gl_Position.z = 1.0;
Expand Down
10 changes: 10 additions & 0 deletions src/renderers/webgl/WebGLBackground.js
Expand Up @@ -47,6 +47,7 @@ function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
boxMesh = new Mesh(
new BoxBufferGeometry( 1, 1, 1 ),
new ShaderMaterial( {
type: 'BackgroundCubeMaterial',
uniforms: UniformsUtils.clone( ShaderLib.cube.uniforms ),
vertexShader: ShaderLib.cube.vertexShader,
fragmentShader: ShaderLib.cube.fragmentShader,
Expand Down Expand Up @@ -83,6 +84,7 @@ function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
planeMesh = new Mesh(
new PlaneBufferGeometry( 2, 2 ),
new ShaderMaterial( {
type: 'BackgroundMaterial',
uniforms: UniformsUtils.clone( ShaderLib.background.uniforms ),
vertexShader: ShaderLib.background.vertexShader,
fragmentShader: ShaderLib.background.fragmentShader,
Expand All @@ -101,6 +103,14 @@ function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {

planeMesh.material.uniforms.t2D.value = background;

if ( background.matrixAutoUpdate === true ) {

background.updateMatrix();

}

planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );

// push to the pre-sorted opaque render list
renderList.push( planeMesh, planeMesh.geometry, planeMesh.material, 0, null );

Expand Down

0 comments on commit ef9c0fe

Please sign in to comment.