Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions docs/api/en/materials/SpriteMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ <h3>[name]( [param:Object parameters] )</h3>
<h2>Properties</h2>
<p>See the base [page:Material] class for common properties.</p>

<h3>[property:Texture alphaMap]</h3>
<p>The alpha map is a grayscale texture that controls the opacity across the surface
(black: fully transparent; white: fully opaque). Default is null.<br /><br />

Only the color of the texture is used, ignoring the alpha channel if one exists.
For RGB and RGBA textures, the [page:WebGLRenderer WebGL] renderer will use the
green channel when sampling this texture due to the extra bit of precision provided
for green in DXT-compressed and uncompressed RGB 565 formats. Luminance-only and
luminance/alpha textures will also still work as expected.
</p>

<h3>[property:Color color]</h3>
<p>[page:Color] of the material, by default set to white (0xffffff). The [page:.map] is mutiplied by the color.</p>

Expand Down
2 changes: 2 additions & 0 deletions src/materials/SpriteMaterial.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MaterialParameters, Material } from './Material';
export interface SpriteMaterialParameters extends MaterialParameters {
color?: Color | string | number;
map?: Texture | null;
alphaMap?: Texture | null;
rotation?: number;
sizeAttenuation?: boolean;
}
Expand All @@ -15,6 +16,7 @@ export class SpriteMaterial extends Material {

color: Color;
map: Texture | null;
alphaMap: Texture | null;
rotation: number;
sizeAttenuation: boolean;
isSpriteMaterial: true;
Expand Down
7 changes: 7 additions & 0 deletions src/materials/SpriteMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Color } from '../math/Color.js';
* parameters = {
* color: <hex>,
* map: new THREE.Texture( <Image> ),
* alphaMap: new THREE.Texture( <Image> ),
* rotation: <float>,
* sizeAttenuation: <bool>
* }
Expand All @@ -19,8 +20,11 @@ function SpriteMaterial( parameters ) {
this.type = 'SpriteMaterial';

this.color = new Color( 0xffffff );

this.map = null;

this.alphaMap = null;

this.rotation = 0;

this.sizeAttenuation = true;
Expand All @@ -40,8 +44,11 @@ SpriteMaterial.prototype.copy = function ( source ) {
Material.prototype.copy.call( this, source );

this.color.copy( source.color );

this.map = source.map;

this.alphaMap = source.alphaMap;

this.rotation = source.rotation;

this.sizeAttenuation = source.sizeAttenuation;
Expand Down
37 changes: 32 additions & 5 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2202,17 +2202,44 @@ function WebGLRenderer( parameters ) {
uniforms.diffuse.value.copy( material.color );
uniforms.opacity.value = material.opacity;
uniforms.rotation.value = material.rotation;
uniforms.map.value = material.map;

if ( material.map !== null ) {
if ( material.map ) {

if ( material.map.matrixAutoUpdate === true ) {
uniforms.map.value = material.map;

material.map.updateMatrix();
}

if ( material.alphaMap ) {

uniforms.alphaMap.value = material.alphaMap;

}

// uv repeat and offset setting priorities
// 1. color map
// 2. alpha map

var uvScaleMap;

if ( material.map ) {

uvScaleMap = material.map;

} else if ( material.alphaMap ) {

uvScaleMap = material.alphaMap;

}

if ( uvScaleMap !== undefined ) {

if ( uvScaleMap.matrixAutoUpdate === true ) {

uvScaleMap.updateMatrix();

}

uniforms.uvTransform.value.copy( material.map.matrix );
uniforms.uvTransform.value.copy( uvScaleMap.matrix );

}

Expand Down
2 changes: 2 additions & 0 deletions src/renderers/shaders/ShaderLib/sprite_frag.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ uniform float opacity;
#include <common>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <fog_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
Expand All @@ -18,6 +19,7 @@ void main() {

#include <logdepthbuf_fragment>
#include <map_fragment>
#include <alphamap_fragment>
#include <alphatest_fragment>

outgoingLight = diffuseColor.rgb;
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 @@ -193,6 +193,7 @@ var UniformsLib = {
center: { value: new Vector2( 0.5, 0.5 ) },
rotation: { value: 0.0 },
map: { value: null },
alphaMap: { value: null },
uvTransform: { value: new Matrix3() }

}
Expand Down