cleaning up shaders lol

pull/1/head
BuildTools 2019-05-27 19:48:06 +10:00
parent 510afd48a2
commit 6f873a81a8
6 changed files with 29 additions and 38 deletions

View File

@ -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());
}
}

View File

@ -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));
}
}

View File

@ -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);

View File

@ -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);