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

pass all blending parameters to setBlending in SpritePlugin #11322

Merged
merged 1 commit into from
May 14, 2017
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
1 change: 1 addition & 0 deletions examples/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ var files = {
"webgl_simple_gi",
"webgl_skinning_simple",
"webgl_sprites",
"webgl_sprites_alpha",
"webgl_terrain_dynamic",
"webgl_test_memory",
"webgl_test_memory2",
Expand Down
Binary file added examples/textures/sprite3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 107 additions & 0 deletions examples/webgl_sprites_alpha.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - sprites - premultiplied alpha</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
padding:0;
margin:0;
font-weight: bold;
overflow:hidden;
}
</style>
</head>

<body>


<div id="info">
<a href="http://threejs.org" target="_blank">three.js</a> - webgl sprites alpha example -
left is without premultiplied alpha, right is with premultiplied alpha
</div>

<script src="../build/three.js"></script>

<script>

var camera, scene, renderer;

init();
animate();

function init() {

var width = window.innerWidth;
var height = window.innerHeight;

camera = new THREE.PerspectiveCamera( 60, width / height, 1, 1000 );
camera.position.z = 100;

scene = new THREE.Scene();

// create sprites
var textureLoader = new THREE.TextureLoader();
var spriteTexture = textureLoader.load( "textures/sprite3.png" );
var spriteTexturePremultiplied = textureLoader.load( "textures/sprite3.png" );
spriteTexturePremultiplied.premultiplyAlpha = true;

var materialPremultiplied = new THREE.SpriteMaterial( {
map: spriteTexturePremultiplied,
premultipliedAlpha: true
} );
var spritePremultiplied = new THREE.Sprite( materialPremultiplied );
spritePremultiplied.scale.set( 40, 40, 40 );
spritePremultiplied.position.set( 20, 0, 0 );
scene.add( spritePremultiplied );

var materialNonPremultiplied = new THREE.SpriteMaterial( { map: spriteTexture } );
var spriteNonPremultiplied = new THREE.Sprite( materialNonPremultiplied );
spriteNonPremultiplied.scale.set( 40, 40, 40 );
spriteNonPremultiplied.position.set( -20, 0, 0 );
scene.add( spriteNonPremultiplied );

// renderer

renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( new THREE.Color( 'white' ) );

document.body.appendChild( renderer.domElement );

//

window.addEventListener( 'resize', onWindowResize, false );

}

function onWindowResize() {

var width = window.innerWidth;
var height = window.innerHeight;

camera.aspect = width / height;
camera.updateProjectionMatrix();

renderer.setSize( window.innerWidth, window.innerHeight );

}

function animate() {

requestAnimationFrame( animate );
render();

}

function render() {

renderer.render( scene, camera );

}

</script>
</body>
</html>
2 changes: 1 addition & 1 deletion src/renderers/webgl/plugins/SpritePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function SpritePlugin( renderer, sprites ) {
gl.uniform1f( uniforms.rotation, material.rotation );
gl.uniform2fv( uniforms.scale, scale );

state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
state.buffers.depth.setTest( material.depthTest );
state.buffers.depth.setMask( material.depthWrite );

Expand Down