cleaning up shaders lol
parent
510afd48a2
commit
6f873a81a8
|
@ -39,10 +39,9 @@ public class ParticleRenderer {
|
||||||
for(ParticleTexture texture : particles.keySet()) {
|
for(ParticleTexture texture : particles.keySet()) {
|
||||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID());
|
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID());
|
||||||
|
shader.loadNumberOfRows(texture.getNumberOfRows());
|
||||||
for(Particle particle : particles.get(texture)) {
|
for(Particle particle : particles.get(texture)) {
|
||||||
updateModelViewMatrix(particle.getPosition(), particle.getRotation(), particle.getScale().x, viewMatrix);
|
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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,15 @@
|
||||||
package io.github.hydos.ginger.engine.renderEngine.shaders;
|
package io.github.hydos.ginger.engine.renderEngine.shaders;
|
||||||
|
|
||||||
import io.github.hydos.ginger.engine.mathEngine.matrixes.Matrix4f;
|
import io.github.hydos.ginger.engine.mathEngine.matrixes.Matrix4f;
|
||||||
import io.github.hydos.ginger.engine.mathEngine.vectors.Vector2f;
|
|
||||||
|
|
||||||
public class ParticleShader extends ShaderProgram {
|
public class ParticleShader extends ShaderProgram {
|
||||||
|
|
||||||
private static final String VERTEX_FILE = "particleVertexShader.glsl";
|
private static final String VERTEX_FILE = "particleVertexShader.glsl";
|
||||||
private static final String FRAGMENT_FILE = "particleFragmentShader.glsl";
|
private static final String FRAGMENT_FILE = "particleFragmentShader.glsl";
|
||||||
|
|
||||||
private int location_modelViewMatrix;
|
private int location_numberOfRows;
|
||||||
private int location_projectionMatrix;
|
private int location_projectionMatrix;
|
||||||
private int location_texOffset1;
|
|
||||||
private int location_texOffset2;
|
|
||||||
private int location_texCoordInfo;
|
|
||||||
|
|
||||||
public ParticleShader() {
|
public ParticleShader() {
|
||||||
super(VERTEX_FILE, FRAGMENT_FILE);
|
super(VERTEX_FILE, FRAGMENT_FILE);
|
||||||
|
@ -20,30 +17,23 @@ public class ParticleShader extends ShaderProgram {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void getAllUniformLocations() {
|
protected void getAllUniformLocations() {
|
||||||
location_modelViewMatrix = super.getUniformLocation("modelViewMatrix");
|
location_numberOfRows = super.getUniformLocation("numberOfRows");
|
||||||
location_projectionMatrix = super.getUniformLocation("projectionMatrix");
|
location_projectionMatrix = super.getUniformLocation("projectionMatrix");
|
||||||
location_texOffset1 = super.getUniformLocation("texOffset1");
|
|
||||||
location_texOffset2 = super.getUniformLocation("texOffset2");
|
|
||||||
location_texCoordInfo = super.getUniformLocation("texCoordInfo");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void bindAttributes() {
|
protected void bindAttributes() {
|
||||||
super.bindAttribute(0, "position");
|
super.bindAttribute(0, "position");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadModelViewMatrix(Matrix4f modelView) {
|
public void loadNumberOfRows(float numberOfRows) {
|
||||||
super.loadMatrix(location_modelViewMatrix, modelView);
|
super.loadFloat(location_numberOfRows, numberOfRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadProjectionMatrix(Matrix4f projectionMatrix) {
|
public void loadProjectionMatrix(Matrix4f projectionMatrix) {
|
||||||
super.loadMatrix(location_projectionMatrix, 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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,26 +2,27 @@
|
||||||
|
|
||||||
in vec2 position;
|
in vec2 position;
|
||||||
|
|
||||||
|
uniform mat4 modelViewMatrix;
|
||||||
|
uniform vec4 texOffsets;
|
||||||
|
uniform float blendFactor;
|
||||||
|
|
||||||
|
|
||||||
out vec2 textureCoords1;
|
out vec2 textureCoords1;
|
||||||
out vec2 textureCoords2;
|
out vec2 textureCoords2;
|
||||||
out float blend;
|
out float blend;
|
||||||
|
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 projectionMatrix;
|
||||||
uniform mat4 modelViewMatrix;
|
uniform float nuberOfRows;
|
||||||
|
|
||||||
uniform vec2 texOffset1;
|
|
||||||
uniform vec2 texOffset2;
|
|
||||||
uniform vec2 texCoordInfo;
|
|
||||||
|
|
||||||
void main(void){
|
void main(void){
|
||||||
|
|
||||||
vec2 textureCoords = position + vec2(0.5, 0.5);
|
vec2 textureCoords = position + vec2(0.5, 0.5);
|
||||||
textureCoords.y = 1.0 - textureCoords.y;
|
textureCoords.y = 1.0 - textureCoords.y;
|
||||||
|
|
||||||
textureCoords /= texCoordInfo.x;
|
textureCoords /= nuberOfRows;
|
||||||
textureCoords1 = textureCoords + texOffset1;
|
textureCoords1 = textureCoords + texOffsets.xy;
|
||||||
textureCoords2 = textureCoords + texOffset2;
|
textureCoords2 = textureCoords + texOffsets.zw;
|
||||||
blend = texCoordInfo.y;
|
blend = blendFactor;
|
||||||
|
|
||||||
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 0.0, 1.0);
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 0.0, 1.0);
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -2,26 +2,27 @@
|
||||||
|
|
||||||
in vec2 position;
|
in vec2 position;
|
||||||
|
|
||||||
|
uniform mat4 modelViewMatrix;
|
||||||
|
uniform vec4 texOffsets;
|
||||||
|
uniform float blendFactor;
|
||||||
|
|
||||||
|
|
||||||
out vec2 textureCoords1;
|
out vec2 textureCoords1;
|
||||||
out vec2 textureCoords2;
|
out vec2 textureCoords2;
|
||||||
out float blend;
|
out float blend;
|
||||||
|
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 projectionMatrix;
|
||||||
uniform mat4 modelViewMatrix;
|
uniform float nuberOfRows;
|
||||||
|
|
||||||
uniform vec2 texOffset1;
|
|
||||||
uniform vec2 texOffset2;
|
|
||||||
uniform vec2 texCoordInfo;
|
|
||||||
|
|
||||||
void main(void){
|
void main(void){
|
||||||
|
|
||||||
vec2 textureCoords = position + vec2(0.5, 0.5);
|
vec2 textureCoords = position + vec2(0.5, 0.5);
|
||||||
textureCoords.y = 1.0 - textureCoords.y;
|
textureCoords.y = 1.0 - textureCoords.y;
|
||||||
|
|
||||||
textureCoords /= texCoordInfo.x;
|
textureCoords /= nuberOfRows;
|
||||||
textureCoords1 = textureCoords + texOffset1;
|
textureCoords1 = textureCoords + texOffsets.xy;
|
||||||
textureCoords2 = textureCoords + texOffset2;
|
textureCoords2 = textureCoords + texOffsets.zw;
|
||||||
blend = texCoordInfo.y;
|
blend = blendFactor;
|
||||||
|
|
||||||
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 0.0, 1.0);
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 0.0, 1.0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue