100 lines
3.3 KiB
Java
100 lines
3.3 KiB
Java
package io.github.hydos.ginger.engine.render.shaders;
|
|
|
|
import java.util.List;
|
|
|
|
import org.joml.*;
|
|
|
|
import io.github.hydos.ginger.engine.cameras.ThirdPersonCamera;
|
|
import io.github.hydos.ginger.engine.elements.objects.Light;
|
|
import io.github.hydos.ginger.engine.math.Maths;
|
|
|
|
public class StaticShader extends ShaderProgram
|
|
{
|
|
private static final int MAX_LIGHTS = 5;
|
|
private int location_transformationMatrix;
|
|
private int location_projectionMatrix;
|
|
private int location_viewMatrix;
|
|
private int location_lightColour[];
|
|
private int location_lightPosition[];
|
|
private int location_attenuation[];
|
|
private int location_shineDamper;
|
|
private int location_reflectivity;
|
|
private int location_useFakeLighting;
|
|
private int location_skyColour;
|
|
|
|
public StaticShader()
|
|
{ super("entityVertexShader.glsl", "entityFragmentShader.glsl"); }
|
|
|
|
@Override
|
|
protected void getAllUniformLocations()
|
|
{
|
|
location_transformationMatrix = super.getUniformLocation("transformationMatrix");
|
|
location_projectionMatrix = super.getUniformLocation("projectionMatrix");
|
|
location_viewMatrix = super.getUniformLocation("viewMatrix");
|
|
location_shineDamper = super.getUniformLocation("shineDamper");
|
|
location_reflectivity = super.getUniformLocation("reflectivity");
|
|
location_useFakeLighting = super.getUniformLocation("useFakeLighting");
|
|
location_skyColour = super.getUniformLocation("skyColour");
|
|
location_lightPosition = new int[MAX_LIGHTS];
|
|
location_lightColour = new int[MAX_LIGHTS];
|
|
location_attenuation = new int[MAX_LIGHTS];
|
|
for (int i = 0; i < MAX_LIGHTS; i++)
|
|
{
|
|
location_lightPosition[i] = super.getUniformLocation("lightPosition[" + i + "]");
|
|
location_lightColour[i] = super.getUniformLocation("lightColour[" + i + "]");
|
|
location_attenuation[i] = super.getUniformLocation("attenuation[" + i + "]");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void bindAttributes()
|
|
{
|
|
super.bindAttribute(0, "position");
|
|
super.bindAttribute(1, "textureCoords");
|
|
super.bindAttribute(2, "normal");
|
|
}
|
|
|
|
public void loadTransformationMatrix(Matrix4f matrix)
|
|
{ super.loadMatrix(location_transformationMatrix, matrix); }
|
|
|
|
public void loadProjectionMatrix(Matrix4f matrix)
|
|
{ super.loadMatrix(location_projectionMatrix, matrix); }
|
|
|
|
public void loadViewMatrix(ThirdPersonCamera camera)
|
|
{
|
|
Matrix4f matrix = Maths.createViewMatrix(camera);
|
|
super.loadMatrix(location_viewMatrix, matrix);
|
|
}
|
|
|
|
public void loadLights(List<Light> lights)
|
|
{
|
|
for (int i = 0; i < MAX_LIGHTS; i++)
|
|
{
|
|
if (i < lights.size())
|
|
{
|
|
super.loadVector(location_lightPosition[i], lights.get(i).getPosition());
|
|
super.loadVector(location_lightColour[i], lights.get(i).getColour());
|
|
super.loadVector(location_attenuation[i], lights.get(i).getAttenuation());
|
|
}
|
|
else
|
|
{
|
|
super.loadVector(location_lightPosition[i], new Vector3f(0, 0, 0));
|
|
super.loadVector(location_lightColour[i], new Vector3f(0, 0, 0));
|
|
super.loadVector(location_attenuation[i], new Vector3f(1, 0, 0));
|
|
}
|
|
}
|
|
}
|
|
|
|
public void loadShine(float damper, float reflectivity)
|
|
{
|
|
super.loadFloat(location_shineDamper, damper);
|
|
super.loadFloat(location_reflectivity, reflectivity);
|
|
}
|
|
|
|
public void loadFakeLightingVariable(boolean useFake)
|
|
{ super.loadBoolean(location_useFakeLighting, useFake); }
|
|
|
|
public void loadSkyColour(Vector3f colour)
|
|
{ super.loadVector(location_skyColour, colour); }
|
|
}
|