Skip to content

Commit

Permalink
Merge pull request #18099 from zeux/uv2-matrix
Browse files Browse the repository at this point in the history
Implement support for texture matrix for uv2
  • Loading branch information
mrdoob authored Dec 7, 2019
2 parents 20c5150 + 203a725 commit f8f6265
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2161,6 +2161,40 @@ function WebGLRenderer( parameters ) {

}

// uv repeat and offset setting priorities for uv2
// 1. ao map
// 2. light map

var uv2ScaleMap;

if ( material.aoMap ) {

uv2ScaleMap = material.aoMap;

} else if ( material.lightMap ) {

uv2ScaleMap = material.lightMap;

}

if ( uvScaleMap !== undefined ) {

// backwards compatibility
if ( uv2ScaleMap.isWebGLRenderTarget ) {

uv2ScaleMap = uv2ScaleMap.texture;

}

if ( uv2ScaleMap.matrixAutoUpdate === true ) {

uv2ScaleMap.updateMatrix();

}

uniforms.uv2Transform.value.copy( uv2ScaleMap.matrix );

}
}

function refreshUniformsLine( uniforms, material ) {
Expand Down
2 changes: 2 additions & 0 deletions src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ export default /* glsl */`
attribute vec2 uv2;
varying vec2 vUv2;
uniform mat3 uv2Transform;
#endif
`;
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderChunk/uv2_vertex.glsl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default /* glsl */`
#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )
vUv2 = uv2;
vUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;
#endif
`;
1 change: 1 addition & 0 deletions src/renderers/shaders/UniformsLib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export let UniformsLib: {
opacity: IUniform;
map: IUniform;
uvTransform: IUniform;
uv2Transform: IUniform;
alphaMap: IUniform;
};
specularmap: {
Expand Down
1 change: 1 addition & 0 deletions src/renderers/shaders/UniformsLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var UniformsLib = {

map: { value: null },
uvTransform: { value: new Matrix3() },
uv2Transform: { value: new Matrix3() },

alphaMap: { value: null },

Expand Down

0 comments on commit f8f6265

Please sign in to comment.