preping for using normal mapping
parent
b6459bb737
commit
a3e6425134
|
@ -1,4 +1,4 @@
|
|||
package normalMappingRenderer;
|
||||
package io.github.hydos.ginger.renderEngine.renderers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -7,17 +7,18 @@ import org.lwjgl.opengl.GL11;
|
|||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.lwjgl.util.vector.Matrix4f;
|
||||
import org.lwjgl.util.vector.Vector4f;
|
||||
|
||||
import entities.Camera;
|
||||
import entities.Entity;
|
||||
import entities.Light;
|
||||
import models.RawModel;
|
||||
import models.TexturedModel;
|
||||
import renderEngine.MasterRenderer;
|
||||
import textures.ModelTexture;
|
||||
import toolbox.Maths;
|
||||
import io.github.hydos.ginger.elements.Entity;
|
||||
import io.github.hydos.ginger.elements.Light;
|
||||
import io.github.hydos.ginger.elements.ThirdPersonCamera;
|
||||
import io.github.hydos.ginger.io.Window;
|
||||
import io.github.hydos.ginger.mathEngine.Maths;
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix4f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector4f;
|
||||
import io.github.hydos.ginger.renderEngine.models.RawModel;
|
||||
import io.github.hydos.ginger.renderEngine.models.TexturedModel;
|
||||
import io.github.hydos.ginger.renderEngine.shaders.NormalMappingShader;
|
||||
import io.github.hydos.ginger.renderEngine.texture.ModelTexture;
|
||||
|
||||
public class NormalMappingRenderer {
|
||||
|
||||
|
@ -31,7 +32,7 @@ public class NormalMappingRenderer {
|
|||
shader.stop();
|
||||
}
|
||||
|
||||
public void render(Map<TexturedModel, List<Entity>> entities, Vector4f clipPlane, List<Light> lights, Camera camera) {
|
||||
public void render(Map<TexturedModel, List<Entity>> entities, Vector4f clipPlane, List<Light> lights, ThirdPersonCamera camera) {
|
||||
shader.start();
|
||||
prepare(clipPlane, lights, camera);
|
||||
for (TexturedModel model : entities.keySet()) {
|
||||
|
@ -57,13 +58,12 @@ public class NormalMappingRenderer {
|
|||
GL20.glEnableVertexAttribArray(1);
|
||||
GL20.glEnableVertexAttribArray(2);
|
||||
ModelTexture texture = model.getTexture();
|
||||
shader.loadNumberOfRows(texture.getNumberOfRows());
|
||||
if (texture.isHasTransparency()) {
|
||||
if (texture.isTransparent()) {
|
||||
MasterRenderer.disableCulling();
|
||||
}
|
||||
shader.loadShineVariables(texture.getShineDamper(), texture.getReflectivity());
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, model.getTexture().getID());
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, model.getTexture().getTextureID());
|
||||
}
|
||||
|
||||
private void unbindTexturedModel() {
|
||||
|
@ -78,13 +78,13 @@ public class NormalMappingRenderer {
|
|||
Matrix4f transformationMatrix = Maths.createTransformationMatrix(entity.getPosition(), entity.getRotX(),
|
||||
entity.getRotY(), entity.getRotZ(), entity.getScale());
|
||||
shader.loadTransformationMatrix(transformationMatrix);
|
||||
shader.loadOffset(entity.getTextureXOffset(), entity.getTextureYOffset());
|
||||
shader.loadOffset(0, 0);
|
||||
}
|
||||
|
||||
private void prepare(Vector4f clipPlane, List<Light> lights, Camera camera) {
|
||||
private void prepare(Vector4f clipPlane, List<Light> lights, ThirdPersonCamera camera) {
|
||||
shader.loadClipPlane(clipPlane);
|
||||
//need to be public variables in MasterRenderer
|
||||
shader.loadSkyColour(MasterRenderer.RED, MasterRenderer.GREEN, MasterRenderer.BLUE);
|
||||
shader.loadSkyColour(Window.getColour());
|
||||
Matrix4f viewMatrix = Maths.createViewMatrix(camera);
|
||||
|
||||
shader.loadLights(lights, viewMatrix);
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
package normalMappingRenderer;
|
||||
package io.github.hydos.ginger.renderEngine.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 entities.Light;
|
||||
import shaders.ShaderProgram;
|
||||
import io.github.hydos.ginger.elements.Light;
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix4f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector2f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector4f;
|
||||
|
||||
public class NormalMappingShader extends ShaderProgram{
|
||||
|
||||
|
@ -65,36 +63,36 @@ public class NormalMappingShader extends ShaderProgram{
|
|||
}
|
||||
}
|
||||
|
||||
protected void connectTextureUnits(){
|
||||
public void connectTextureUnits(){
|
||||
super.loadInt(location_modelTexture, 0);
|
||||
}
|
||||
|
||||
protected void loadClipPlane(Vector4f plane){
|
||||
public void loadClipPlane(Vector4f plane){
|
||||
super.loadVector(location_plane, plane);
|
||||
}
|
||||
|
||||
protected void loadNumberOfRows(int numberOfRows){
|
||||
public void loadNumberOfRows(int numberOfRows){
|
||||
super.loadFloat(location_numberOfRows, numberOfRows);
|
||||
}
|
||||
|
||||
protected void loadOffset(float x, float y){
|
||||
public void loadOffset(float x, float y){
|
||||
super.load2DVector(location_offset, new Vector2f(x,y));
|
||||
}
|
||||
|
||||
protected void loadSkyColour(float r, float g, float b){
|
||||
public void loadSkyColour(float r, float g, float b){
|
||||
super.loadVector(location_skyColour, new Vector3f(r,g,b));
|
||||
}
|
||||
|
||||
protected void loadShineVariables(float damper,float reflectivity){
|
||||
public void loadShineVariables(float damper,float reflectivity){
|
||||
super.loadFloat(location_shineDamper, damper);
|
||||
super.loadFloat(location_reflectivity, reflectivity);
|
||||
}
|
||||
|
||||
protected void loadTransformationMatrix(Matrix4f matrix){
|
||||
public void loadTransformationMatrix(Matrix4f matrix){
|
||||
super.loadMatrix(location_transformationMatrix, matrix);
|
||||
}
|
||||
|
||||
protected void loadLights(List<Light> lights, Matrix4f viewMatrix){
|
||||
public void loadLights(List<Light> lights, Matrix4f viewMatrix){
|
||||
for(int i=0;i<MAX_LIGHTS;i++){
|
||||
if(i<lights.size()){
|
||||
super.loadVector(location_lightPositionEyeSpace[i], getEyeSpacePosition(lights.get(i), viewMatrix));
|
||||
|
@ -108,20 +106,25 @@ public class NormalMappingShader extends ShaderProgram{
|
|||
}
|
||||
}
|
||||
|
||||
protected void loadViewMatrix(Matrix4f viewMatrix){
|
||||
public void loadViewMatrix(Matrix4f viewMatrix){
|
||||
super.loadMatrix(location_viewMatrix, viewMatrix);
|
||||
}
|
||||
|
||||
protected void loadProjectionMatrix(Matrix4f projection){
|
||||
public void loadProjectionMatrix(Matrix4f projection){
|
||||
super.loadMatrix(location_projectionMatrix, projection);
|
||||
}
|
||||
|
||||
private Vector3f getEyeSpacePosition(Light light, Matrix4f viewMatrix){
|
||||
public Vector3f getEyeSpacePosition(Light light, Matrix4f viewMatrix){
|
||||
Vector3f position = light.getPosition();
|
||||
Vector4f eyeSpacePos = new Vector4f(position.x,position.y, position.z, 1f);
|
||||
Matrix4f.transform(viewMatrix, eyeSpacePos, eyeSpacePos);
|
||||
return new Vector3f(eyeSpacePos);
|
||||
}
|
||||
|
||||
public void loadSkyColour(Vector3f colour) {
|
||||
super.loadVector(location_skyColour, colour);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue