From 6f873a81a8595e49ad0b55ed79efc4006071e816 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 27 May 2019 19:48:06 +1000 Subject: [PATCH] cleaning up shaders lol --- .../renderers/ParticleRenderer.java | 3 +- .../renderEngine/shaders/ParticleShader.java | 26 ++++++------------ .../shaders/particleVertexShader.glsl | 19 +++++++------ .../renderers/ParticleRenderer.class | Bin 6235 -> 4604 bytes .../renderEngine/shaders/ParticleShader.class | Bin 2303 -> 1539 bytes .../classes/shaders/particleVertexShader.glsl | 19 +++++++------ 6 files changed, 29 insertions(+), 38 deletions(-) diff --git a/src/main/java/io/github/hydos/ginger/engine/renderEngine/renderers/ParticleRenderer.java b/src/main/java/io/github/hydos/ginger/engine/renderEngine/renderers/ParticleRenderer.java index e5830da..6012cef 100644 --- a/src/main/java/io/github/hydos/ginger/engine/renderEngine/renderers/ParticleRenderer.java +++ b/src/main/java/io/github/hydos/ginger/engine/renderEngine/renderers/ParticleRenderer.java @@ -39,10 +39,9 @@ public class ParticleRenderer { for(ParticleTexture texture : particles.keySet()) { GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID()); + shader.loadNumberOfRows(texture.getNumberOfRows()); for(Particle particle : particles.get(texture)) { updateModelViewMatrix(particle.getPosition(), particle.getRotation(), particle.getScale().x, viewMatrix); - shader.loadTextureCoordInfo(particle.getTexOffset1(), particle.getTexOffset2(), texture.getNumberOfRows(), particle.getBlend()); - GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, quad.getVertexCount()); } } diff --git a/src/main/java/io/github/hydos/ginger/engine/renderEngine/shaders/ParticleShader.java b/src/main/java/io/github/hydos/ginger/engine/renderEngine/shaders/ParticleShader.java index e3f0854..a90ecf2 100644 --- a/src/main/java/io/github/hydos/ginger/engine/renderEngine/shaders/ParticleShader.java +++ b/src/main/java/io/github/hydos/ginger/engine/renderEngine/shaders/ParticleShader.java @@ -1,18 +1,15 @@ package io.github.hydos.ginger.engine.renderEngine.shaders; import io.github.hydos.ginger.engine.mathEngine.matrixes.Matrix4f; -import io.github.hydos.ginger.engine.mathEngine.vectors.Vector2f; public class ParticleShader extends ShaderProgram { private static final String VERTEX_FILE = "particleVertexShader.glsl"; private static final String FRAGMENT_FILE = "particleFragmentShader.glsl"; - private int location_modelViewMatrix; + private int location_numberOfRows; private int location_projectionMatrix; - private int location_texOffset1; - private int location_texOffset2; - private int location_texCoordInfo; + public ParticleShader() { super(VERTEX_FILE, FRAGMENT_FILE); @@ -20,30 +17,23 @@ public class ParticleShader extends ShaderProgram { @Override protected void getAllUniformLocations() { - location_modelViewMatrix = super.getUniformLocation("modelViewMatrix"); + location_numberOfRows = super.getUniformLocation("numberOfRows"); location_projectionMatrix = super.getUniformLocation("projectionMatrix"); - location_texOffset1 = super.getUniformLocation("texOffset1"); - location_texOffset2 = super.getUniformLocation("texOffset2"); - location_texCoordInfo = super.getUniformLocation("texCoordInfo"); + } @Override protected void bindAttributes() { super.bindAttribute(0, "position"); } - - public void loadModelViewMatrix(Matrix4f modelView) { - super.loadMatrix(location_modelViewMatrix, modelView); + + public void loadNumberOfRows(float numberOfRows) { + super.loadFloat(location_numberOfRows, numberOfRows); } public void loadProjectionMatrix(Matrix4f projectionMatrix) { super.loadMatrix(location_projectionMatrix, projectionMatrix); } - - public void loadTextureCoordInfo(Vector2f offset1, Vector2f offset2, float numRows, float blend) { - super.load2DVector(location_texOffset1, offset1); - super.load2DVector(location_texOffset2, offset2); - super.load2DVector(location_texCoordInfo, new Vector2f(numRows, blend)); - } + } diff --git a/src/main/resources/shaders/particleVertexShader.glsl b/src/main/resources/shaders/particleVertexShader.glsl index 81931d1..3b9d9ce 100644 --- a/src/main/resources/shaders/particleVertexShader.glsl +++ b/src/main/resources/shaders/particleVertexShader.glsl @@ -2,26 +2,27 @@ in vec2 position; +uniform mat4 modelViewMatrix; +uniform vec4 texOffsets; +uniform float blendFactor; + + out vec2 textureCoords1; out vec2 textureCoords2; out float blend; uniform mat4 projectionMatrix; -uniform mat4 modelViewMatrix; - -uniform vec2 texOffset1; -uniform vec2 texOffset2; -uniform vec2 texCoordInfo; +uniform float nuberOfRows; void main(void){ vec2 textureCoords = position + vec2(0.5, 0.5); textureCoords.y = 1.0 - textureCoords.y; - textureCoords /= texCoordInfo.x; - textureCoords1 = textureCoords + texOffset1; - textureCoords2 = textureCoords + texOffset2; - blend = texCoordInfo.y; + textureCoords /= nuberOfRows; + textureCoords1 = textureCoords + texOffsets.xy; + textureCoords2 = textureCoords + texOffsets.zw; + blend = blendFactor; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 0.0, 1.0); diff --git a/target/classes/io/github/hydos/ginger/engine/renderEngine/renderers/ParticleRenderer.class b/target/classes/io/github/hydos/ginger/engine/renderEngine/renderers/ParticleRenderer.class index b9ecccab14b81f1904e808351c1e721bb63d7854..d00a04639abfeb3344f34ddf693f00576c27de6a 100644 GIT binary patch delta 1377 zcmY+D>vI!j6vm%7Nweu@ktW)7QqftcV$&8=n94}4f*o35XiH1mI54BklDti}Zg<0G zd-E1S#CwY@iXvW7>%G>NHUWhyUS|9QoKZjFf8ck=dUlhc_+ig`^1jdc?Rie#{j>R> zx~gCQy?7Zw3w{ycVd${`_H@h*{^1XZ=mVE9WY1Pcnq*`os2FCb(hMclGdgmZoBM|L z8{;_!UwvmR5yTE?5=Nlg+l0-xWf^W7R>qY0sHJN0E;VNbVPLla(#LJ)i;E&mj7k{8 zxV?)*HFO4VeXP@wJ}KcTj57r2v_Gk6yb@32n1G`U+w3DO zW>2lHs*&&vjx(?cdZ>!wgoNktynQZkWR*KAgb61+v4DJj(-NL_G%qlmUHQ# zZh=JcPU>|dDsdNO^=Lp0_fTv{Ba&#M8{UZHbT)-%oWf?@Ocf8nPtnHRh|}t1C-ExX zNhdo+k0(#aDV!#`m!OC68eXSYCQ*Ykc!P@HB&k#`IEk~Ay+u1c@U0*UzW^p+hk$be z-hn`00akE70yl08=yML-!woCc{Qryc?g3%x##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6oHf^1AhA*NwIrlX8BCvxcDC>Nz` zaTPWpk0z9_&NeTE!MWMC;s^Ywj;a+uVVR0vD}5N2(QFATb;>%rwgo@ay!DjJgcBqg zlz2;g(a9iAX@mI7Vm=;3uSKh|XthD6>90FhrIMKBOjxMG!I*^$hzXCe6Qw^cpfw`1w9?Zlx3rZ;6eC3#Bkdc|mq+$FYq-^i( diff --git a/target/classes/io/github/hydos/ginger/engine/renderEngine/shaders/ParticleShader.class b/target/classes/io/github/hydos/ginger/engine/renderEngine/shaders/ParticleShader.class index df7017f21ba175f2fd82dd2fce15f32d601d9256..2060310c65e71545511eb841825f5cf0ced0e6d9 100644 GIT binary patch delta 704 zcmZ{i-A)=o6vzLE1-fjfh%1Y&;ul~Gi~YdXkG5!H8!@IT#tUx^2qxQD*1($fjtd{a zi@EVNOxh58(FbVyBz*|=jBJn?y*YEv%zu9KKPPiFcp{9ym%sl2c!%Y4!=!|D=D$Px4- zx8*3gV&(;A@KWw+`7g0Uw^G~c^UBV$rQEKP6$EDSmJm^z5(keE%C7S%fl7q9+TZRO zk!RXQcv0XzKFI&t4i#lNWXpe=DObZY6qL!W3uen{4_P7-bpSh%?#ZINV3I zdej#^>by_YZOzPfVBdne&PMSF$v%eeGYGHn+Hda@GgKFbZU4j+J9^W;iZl9^hs0QB9FhWKRJsT?049W*Pth literal 2303 zcmbtVZF3S=6n<_(*?54}2>GWfN zQD@p=rk&{z=#T33xyuF;LhIX?z31F>?sMMH{{7D%e*wtgMG#{GS;I~>47b^-rkX$1 z>^2#zA)S=8NXV2Ut(tW5J*M5%$+T0uy5kxLrrh`VAOZqg9{|&PzU$ZxM{fyCR`Pr0 z{PUNEVks{WExpoT>nT&W8mWEPp;PMu=X18zc6H0G=w?TT5Ehs}^qr|l$CXDt%+-e3 zHmP3N%Rb)D@02~v5Hx`+$La+~Z?vT4o_a86+6TI8*w)LIU6W?TkZ-ni8b1;cMcV3% z4;}lJJW!g)^69>eUOcVW+tR%wFyb~XaQUQe&bFOe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