This commit is contained in:
Richard Davey 2023-10-10 20:22:31 +01:00
commit 181a022348
10 changed files with 74 additions and 48 deletions

View file

@ -949,13 +949,13 @@ var TransformMatrix = new Class({
quad[6] = xw * a + y * c + e;
quad[7] = xw * b + y * d + f;
if (roundPixels)
{
quad.forEach(function (value, index)
{
quad[index] = Math.round(value);
});
}
// if (roundPixels)
// {
// quad.forEach(function (value, index)
// {
// quad[index] = Math.round(value);
// });
// }
return quad;
},

View file

@ -104,7 +104,11 @@ var MobilePipeline = new Class({
{
WebGLPipeline.prototype.boot.call(this);
var renderer = this.renderer;
this.set1i('uMainSampler', 0);
this.set2f('uResolution', renderer.width, renderer.height);
this.set1i('uRoundPixels', renderer.config.roundPixels);
}
});

View file

@ -277,7 +277,11 @@ var MultiPipeline = new Class({
{
WebGLPipeline.prototype.boot.call(this);
this.currentShader.set1iv('uMainSampler', this.renderer.textureIndexes);
var renderer = this.renderer;
this.set1iv('uMainSampler', renderer.textureIndexes);
this.set2f('uResolution', renderer.width, renderer.height);
this.set1i('uRoundPixels', renderer.config.roundPixels);
},
/**
@ -369,11 +373,11 @@ var MultiPipeline = new Class({
var gx = gameObject.x;
var gy = gameObject.y;
// if (camera.roundPixels)
// {
// gx = Math.floor(gx);
// gy = Math.floor(gy);
// }
if (camera.roundPixels)
{
gx = Math.floor(gx);
gy = Math.floor(gy);
}
spriteMatrix.applyITRS(gx, gy, gameObject.rotation, gameObject.scaleX * flipX, gameObject.scaleY * flipY);
@ -397,7 +401,7 @@ var MultiPipeline = new Class({
// Multiply by the Sprite matrix, store result in calcMatrix
camMatrix.multiply(spriteMatrix, calcMatrix);
var quad = calcMatrix.setQuad(x, y, x + frameWidth, y + frameHeight, camera.roundPixels);
var quad = calcMatrix.setQuad(x, y, x + frameWidth, y + frameHeight);
var getTint = Utils.getTintAppendFloatAlpha;
var cameraAlpha = camera.alpha;
@ -416,6 +420,8 @@ var MultiPipeline = new Class({
this.manager.preBatch(gameObject);
this.currentShader.set1i('uRoundPixels', camera.roundPixels);
this.batchQuad(gameObject, quad[0], quad[1], quad[2], quad[3], quad[4], quad[5], quad[6], quad[7], u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, gameObject.tintFill, texture, unit);
this.manager.postBatch(gameObject);
@ -549,11 +555,11 @@ var MultiPipeline = new Class({
y += srcHeight;
}
// if (camera.roundPixels)
// {
// srcX = Math.floor(srcX);
// srcY = Math.floor(srcY);
// }
if (camera.roundPixels)
{
srcX = Math.floor(srcX);
srcY = Math.floor(srcY);
}
spriteMatrix.applyITRS(srcX, srcY, rotation, scaleX, scaleY);
@ -577,11 +583,10 @@ var MultiPipeline = new Class({
// Multiply by the Sprite matrix, store result in calcMatrix
camMatrix.multiply(spriteMatrix, calcMatrix);
var quad = calcMatrix.setQuad(x, y, x + width, y + height, camera.roundPixels);
var quad = calcMatrix.setQuad(x, y, x + width, y + height);
if (textureUnit === undefined)
{
// textureUnit = this.renderer.setTexture2D(texture);
textureUnit = this.setTexture2D(texture);
}
@ -590,6 +595,8 @@ var MultiPipeline = new Class({
this.manager.preBatch(gameObject);
}
this.currentShader.set1i('uRoundPixels', camera.roundPixels);
this.batchQuad(gameObject, quad[0], quad[1], quad[2], quad[3], quad[4], quad[5], quad[6], quad[7], u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect, texture, textureUnit);
if (gameObject)

View file

@ -63,7 +63,11 @@ var SinglePipeline = new Class({
{
WebGLPipeline.prototype.boot.call(this);
var renderer = this.renderer;
this.set1i('uMainSampler', 0);
this.set2f('uResolution', renderer.width, renderer.height);
this.set1i('uRoundPixels', renderer.config.roundPixels);
}
});

View file

@ -1,11 +1,9 @@
module.exports = [
'#define SHADER_NAME PHASER_MOBILE_VS',
'#ifdef GL_FRAGMENT_PRECISION_HIGH',
'precision highp float;',
'#else',
'precision mediump float;',
'#endif',
'uniform mat4 uProjectionMatrix;',
'uniform int uRoundPixels;',
'uniform vec2 uResolution;',
'attribute vec2 inPosition;',
'attribute vec2 inTexCoord;',
'attribute float inTexId;',
@ -17,6 +15,10 @@ module.exports = [
'void main ()',
'{',
' gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0);',
' if (uRoundPixels == 1)',
' {',
' gl_Position.xy = floor((gl_Position.xy + 1.0) * 0.5 * uResolution) / uResolution * 2.0 - 1.0;',
' }',
' outTexCoord = inTexCoord;',
' outTint = inTint;',
' outTintEffect = inTintEffect;',

View file

@ -1,11 +1,9 @@
module.exports = [
'#define SHADER_NAME PHASER_MULTI_VS',
'#ifdef GL_FRAGMENT_PRECISION_HIGH',
'precision highp float;',
'#else',
'precision mediump float;',
'#endif',
'uniform mat4 uProjectionMatrix;',
'uniform int uRoundPixels;',
'uniform vec2 uResolution;',
'attribute vec2 inPosition;',
'attribute vec2 inTexCoord;',
'attribute float inTexId;',
@ -15,15 +13,17 @@ module.exports = [
'varying float outTexId;',
'varying float outTintEffect;',
'varying vec4 outTint;',
'vec2 roundPixels (vec2 position, vec2 targetSize)',
'{',
' return (floor((position * 0.5 + 0.5) * targetSize) / targetSize) * 2.0 - 1.0;',
'}',
'void main ()',
'{',
' gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0);',
' /*',
' if (uRoundPixels)',
' if (uRoundPixels == 1)',
' {',
' gl_Position.xy = round((gl_Position.xy + 1.0) * 0.5 * uResolution) / uResolution * 2.0 - 1.0;',
' gl_Position.xy = roundPixels(gl_Position.xy, uResolution);',
' }',
' */',
' outTexCoord = inTexCoord;',
' outTexId = inTexId;',
' outTint = inTint;',

View file

@ -2,6 +2,8 @@ module.exports = [
'#define SHADER_NAME PHASER_SINGLE_VS',
'precision mediump float;',
'uniform mat4 uProjectionMatrix;',
'uniform int uRoundPixels;',
'uniform vec2 uResolution;',
'attribute vec2 inPosition;',
'attribute vec2 inTexCoord;',
'attribute float inTexId;',
@ -13,6 +15,10 @@ module.exports = [
'void main ()',
'{',
' gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0);',
' if (uRoundPixels == 1)',
' {',
' gl_Position.xy = floor((gl_Position.xy + 1.0) * 0.5 * uResolution) / uResolution * 2.0 - 1.0;',
' }',
' outTexCoord = inTexCoord;',
' outTint = inTint;',
' outTintEffect = inTintEffect;',

View file

@ -1,12 +1,10 @@
#define SHADER_NAME PHASER_MOBILE_VS
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
uniform mat4 uProjectionMatrix;
uniform int uRoundPixels;
uniform vec2 uResolution;
attribute vec2 inPosition;
attribute vec2 inTexCoord;
@ -22,6 +20,11 @@ void main ()
{
gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0);
if (uRoundPixels == 1)
{
gl_Position.xy = floor((gl_Position.xy + 1.0) * 0.5 * uResolution) / uResolution * 2.0 - 1.0;
}
outTexCoord = inTexCoord;
outTint = inTint;
outTintEffect = inTintEffect;

View file

@ -1,14 +1,10 @@
#define SHADER_NAME PHASER_MULTI_VS
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
uniform mat4 uProjectionMatrix;
// uniform bool uRoundPixels;
// uniform vec2 uResolution;
uniform int uRoundPixels;
uniform vec2 uResolution;
attribute vec2 inPosition;
attribute vec2 inTexCoord;
@ -25,13 +21,10 @@ void main ()
{
gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0);
/*
if (uRoundPixels)
if (uRoundPixels == 1)
{
// Round to nearest pixel
gl_Position.xy = round((gl_Position.xy + 1.0) * 0.5 * uResolution) / uResolution * 2.0 - 1.0;
gl_Position.xy = floor((gl_Position.xy + 1.0) * 0.5 * uResolution) / uResolution * 2.0 - 1.0;
}
*/
outTexCoord = inTexCoord;
outTexId = inTexId;

View file

@ -3,6 +3,8 @@
precision mediump float;
uniform mat4 uProjectionMatrix;
uniform int uRoundPixels;
uniform vec2 uResolution;
attribute vec2 inPosition;
attribute vec2 inTexCoord;
@ -18,6 +20,11 @@ void main ()
{
gl_Position = uProjectionMatrix * vec4(inPosition, 1.0, 1.0);
if (uRoundPixels == 1)
{
gl_Position.xy = floor((gl_Position.xy + 1.0) * 0.5 * uResolution) / uResolution * 2.0 - 1.0;
}
outTexCoord = inTexCoord;
outTint = inTint;
outTintEffect = inTintEffect;