123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- package eu.tankernn.gameEngine.shaders;
- import java.util.List;
- import org.lwjgl.util.vector.Matrix4f;
- import org.lwjgl.util.vector.Vector2f;
- import org.lwjgl.util.vector.Vector3f;
- import org.lwjgl.util.vector.Vector4f;
- import eu.tankernn.gameEngine.entities.Camera;
- import eu.tankernn.gameEngine.entities.Light;
- import eu.tankernn.gameEngine.util.Maths;
- public class StaticShader extends ShaderProgram {
-
- private static final int MAX_LIGHTS = 4;
-
- private static final String VERTEX_FILE = "vertexShader.glsl";
- private static final String FRAGMENT_FILE = "fragmentShader.glsl";
-
- private int location_transformationMatrix;
- private int location_projecttionMatrix;
- private int location_viewMatrix;
- private int[] location_lightPosition;
- private int[] location_lightColor;
- private int[] location_attenuation;
- private int location_shineDamper;
- private int location_reflectivity;
- private int location_useFakeLighting;
- private int location_skyColor;
- private int location_numberOfRows;
- private int location_offset;
- private int location_plane;
- private int location_toShadowMapSpace;
- private int location_shadowMap;
- private int location_shadowDistance;
- private int location_specularMap;
- private int location_usesSpecularMap;
- private int location_modelTexture;
- private int location_cameraPosition;
- private int location_enviroMap;
-
- public StaticShader() {
- super(VERTEX_FILE, FRAGMENT_FILE);
- }
-
- @Override
- protected void bindAttributes() {
- super.bindAttribute(0, "position");
- super.bindAttribute(1, "textureCoords");
- super.bindAttribute(2, "normal");
- }
-
- @Override
- protected void getAllUniformLocations() {
- location_transformationMatrix = super.getUniformLocation("transformationMatrix");
- location_projecttionMatrix = super.getUniformLocation("projectionMatrix");
- location_viewMatrix = super.getUniformLocation("viewMatrix");
- location_shineDamper = super.getUniformLocation("shineDamper");
- location_reflectivity = super.getUniformLocation("reflectivity");
- location_useFakeLighting = super.getUniformLocation("useFakeLighting");
- location_skyColor = super.getUniformLocation("skyColor");
- location_numberOfRows = super.getUniformLocation("numberOfRows");
- location_offset = super.getUniformLocation("offset");
- location_plane = super.getUniformLocation("plane");
- location_toShadowMapSpace = super.getUniformLocation("toShadowMapSpace");
- location_shadowMap = super.getUniformLocation("shadowMap");
- location_shadowDistance = super.getUniformLocation("shadowDistance");
- location_specularMap = super.getUniformLocation("specularMap");
- location_usesSpecularMap = super.getUniformLocation("usesSpecularMap");
- location_modelTexture = super.getUniformLocation("modelTexture");
- location_cameraPosition = super.getUniformLocation("cameraPosition");
- location_enviroMap = super.getUniformLocation("enviroMap");
-
- location_lightPosition = new int[MAX_LIGHTS];
- location_lightColor = 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_lightColor[i] = super.getUniformLocation("lightColor[" + i + "]");
- location_attenuation[i] = super.getUniformLocation("attenuation[" + i + "]");
- }
- }
-
- public void connectTextureUnits() {
- super.loadInt(location_shadowMap, 5);
- super.loadInt(location_modelTexture, 0);
- super.loadInt(location_specularMap, 1);
- super.loadInt(location_enviroMap, 10);
- }
-
- public void loadUseSpecularMap(boolean useSpecularMap) {
- super.loadBoolean(location_usesSpecularMap, useSpecularMap);
- }
-
- public void loadShadowDistance(float distance) {
- super.loadFloat(location_shadowDistance, distance);
- }
-
- public void loadToShadowSpaceMatrix(Matrix4f matrix) {
- super.loadMatrix(location_toShadowMapSpace, matrix);
- }
-
- public void loadClipPlane(Vector4f plane) {
- super.loadVector(location_plane, plane);
- }
-
- public void loadNumberOfRows(int numberOfRows) {
- super.loadFloat(location_numberOfRows, numberOfRows);
- }
-
- public void loadOffset(float x, float y) {
- super.load2DVector(location_offset, new Vector2f(x, y));
- }
-
- public void loadSkyColor(float r, float g, float b) {
- super.loadVector(location_skyColor, new Vector3f(r, g, b));
- }
-
- public void loadFakeLightingVariable(boolean useFake) {
- super.loadBoolean(location_useFakeLighting, useFake);
- }
-
- public void loadShineVariables(float damper, float reflectivity) {
- super.loadFloat(location_shineDamper, damper);
- super.loadFloat(location_reflectivity, reflectivity);
- }
-
- public void loadTransformationMatrix(Matrix4f matrix) {
- super.loadMatrix(location_transformationMatrix, matrix);
- }
-
- public void loadCameraPosition(Vector3f vector) {
- super.loadVector(location_cameraPosition, vector);
- }
-
- 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_lightColor[i], lights.get(i).getColor());
- super.loadVector(location_attenuation[i], lights.get(i).getAttenuation());
- } else {
- super.loadVector(location_lightPosition[i], new Vector3f(0, 0, 0));
- super.loadVector(location_lightColor[i], new Vector3f(0, 0, 0));
- super.loadVector(location_attenuation[i], new Vector3f(1, 0, 0));
- }
- }
- }
-
- public void loadViewMatrix(Camera camera) {
- Matrix4f viewMatrix = Maths.createViewMatrix(camera);
- super.loadMatrix(location_viewMatrix, viewMatrix);
- }
-
- public void loadProjectionMatrix(Matrix4f projection) {
- super.loadMatrix(location_projecttionMatrix, projection);
- }
- }
|