From 76689942c0787cdff3126ef4d974afb0d5b125b7 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 14 Jul 2020 17:43:29 +0100 Subject: [PATCH] Add texture ID to shaders --- src/renderer/webgl/shaders/TextureTint-frag.js | 8 ++++++-- src/renderer/webgl/shaders/TextureTint-vert.js | 3 +++ src/renderer/webgl/shaders/src/TextureTint.frag | 8 ++++++-- src/renderer/webgl/shaders/src/TextureTint.vert | 5 ++++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/renderer/webgl/shaders/TextureTint-frag.js b/src/renderer/webgl/shaders/TextureTint-frag.js index fc7cfdaf6..e956899e6 100644 --- a/src/renderer/webgl/shaders/TextureTint-frag.js +++ b/src/renderer/webgl/shaders/TextureTint-frag.js @@ -3,15 +3,19 @@ module.exports = [ '', 'precision mediump float;', '', - 'uniform sampler2D uMainSampler;', + 'uniform sampler2D uMainSampler[%count%];', '', 'varying vec2 outTexCoord;', + 'varying float outTexId;', 'varying float outTintEffect;', 'varying vec4 outTint;', '', 'void main()', '{', - ' vec4 texture = texture2D(uMainSampler, outTexCoord);', + ' vec4 texture;', + '', + ' %forloop%', + '', ' vec4 texel = vec4(outTint.rgb * outTint.a, outTint.a);', ' vec4 color = texture;', '', diff --git a/src/renderer/webgl/shaders/TextureTint-vert.js b/src/renderer/webgl/shaders/TextureTint-vert.js index a9461d030..253767e9f 100644 --- a/src/renderer/webgl/shaders/TextureTint-vert.js +++ b/src/renderer/webgl/shaders/TextureTint-vert.js @@ -9,10 +9,12 @@ module.exports = [ '', 'attribute vec2 inPosition;', 'attribute vec2 inTexCoord;', + 'attribute float inTexId;', 'attribute float inTintEffect;', 'attribute vec4 inTint;', '', 'varying vec2 outTexCoord;', + 'varying float outTexId;', 'varying float outTintEffect;', 'varying vec4 outTint;', '', @@ -21,6 +23,7 @@ module.exports = [ ' gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(inPosition, 1.0, 1.0);', '', ' outTexCoord = inTexCoord;', + ' outTexId = inTexId;', ' outTint = inTint;', ' outTintEffect = inTintEffect;', '}', diff --git a/src/renderer/webgl/shaders/src/TextureTint.frag b/src/renderer/webgl/shaders/src/TextureTint.frag index c4e90fdd1..f0729f414 100644 --- a/src/renderer/webgl/shaders/src/TextureTint.frag +++ b/src/renderer/webgl/shaders/src/TextureTint.frag @@ -2,15 +2,19 @@ precision mediump float; -uniform sampler2D uMainSampler; +uniform sampler2D uMainSampler[%count%]; varying vec2 outTexCoord; +varying float outTexId; varying float outTintEffect; varying vec4 outTint; void main() { - vec4 texture = texture2D(uMainSampler, outTexCoord); + vec4 texture; + + %forloop% + vec4 texel = vec4(outTint.rgb * outTint.a, outTint.a); vec4 color = texture; diff --git a/src/renderer/webgl/shaders/src/TextureTint.vert b/src/renderer/webgl/shaders/src/TextureTint.vert index 819df76eb..bd4a91124 100644 --- a/src/renderer/webgl/shaders/src/TextureTint.vert +++ b/src/renderer/webgl/shaders/src/TextureTint.vert @@ -8,18 +8,21 @@ uniform mat4 uModelMatrix; attribute vec2 inPosition; attribute vec2 inTexCoord; +attribute float inTexId; attribute float inTintEffect; attribute vec4 inTint; varying vec2 outTexCoord; +varying float outTexId; varying float outTintEffect; varying vec4 outTint; -void main () +void main () { gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(inPosition, 1.0, 1.0); outTexCoord = inTexCoord; + outTexId = inTexId; outTint = inTint; outTintEffect = inTintEffect; }