geometry shader

This commit is contained in:
austin 2022-03-16 02:19:56 -04:00
parent 7cee38e268
commit 1f00532448
23 changed files with 719 additions and 45 deletions

Binary file not shown.

BIN
assets/Models/grass1.fbx Normal file

Binary file not shown.

View File

@ -0,0 +1,26 @@
#version 330 core
out vec4 fragColor;
uniform float time;
in vec3 FragPos;
in vec3 Normal;
in vec2 TexCoord;
in vec3 origCoord;
void main(){
vec4 color = vec4(
0.25 * origCoord.y,
0.50 * origCoord.y,
0.25 * origCoord.y,
1.0
);
// Output to screen
fragColor = color;
}

View File

@ -0,0 +1,58 @@
#version 330 core
layout (triangles) in;
layout (triangle_strip, max_vertices = 150) out;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
out vec3 origCoord;
void main() {
vec4 triangle1Pos = gl_in[0].gl_Position;
for(float x = 0; x < 5; x++){
for(float y = 0; y < 5; y++){
float xPos = x / 10.0;
float yPos = y / 10.0;
origCoord = (triangle1Pos + vec4( 0.0 + xPos, 0.0, 0.0 + yPos, 0.0)).xyz;
gl_Position = projection * view * model * (triangle1Pos + vec4( 0.0 + xPos, 0.0, 0.0 + yPos, 0.0));
EmitVertex();
origCoord = (triangle1Pos + vec4( 0.1 + xPos, 0.5, 0.0 + yPos, 0.0)).xyz;
gl_Position = projection * view * model * (triangle1Pos + vec4( 0.1 + xPos, 0.5, 0.0 + yPos, 0.0));
EmitVertex();
origCoord = (triangle1Pos + vec4( 0.0 + xPos, 1.0, 0.0 + yPos, 0.0)).xyz;
gl_Position = projection * view * model * (triangle1Pos + vec4( 0.0 + xPos, 1.0, 0.0 + yPos, 0.0));
EmitVertex();
}
EndPrimitive();
}
// gl_Position = projection * view * model * (gl_in[0].gl_Position + vec4( 1.0, 1.0, 0.0, 1.0));
// EmitVertex();
// gl_Position = projection * view * model * (gl_in[0].gl_Position + vec4( 0.0, 1.0, 0.0, 1.0));
// EmitVertex();
// gl_Position = projection * view * model * (gl_in[0].gl_Position + vec4( 0.0, 0.0, 0.0, 1.0));
// EmitVertex();
// EndPrimitive();
// gl_Position = projection * view * model * (gl_in[1].gl_Position + vec4( 1.0, 0.0, 0.0, 1.0));
// EmitVertex();
// gl_Position = projection * view * model * (gl_in[1].gl_Position + vec4( 0.0, 1.0, 0.0, 1.0));
// EmitVertex();
// gl_Position = projection * view * model * (gl_in[1].gl_Position + vec4( 0.0, 0.0, 0.0, 1.0));
// EmitVertex();
// EndPrimitive();
// gl_Position = projection * view * model * (gl_in[2].gl_Position + vec4( 1.0, 0.0, 0.0, 1.0));
// EmitVertex();
// gl_Position = projection * view * model * (gl_in[2].gl_Position + vec4( 0.0, 1.0, 0.0, 1.0));
// EmitVertex();
// gl_Position = projection * view * model * (gl_in[2].gl_Position + vec4( 0.0, 0.0, 0.0, 1.0));
// EmitVertex();
// EndPrimitive();
}

View File

@ -0,0 +1,42 @@
//Vertex Shader
#version 330 core
//input buffers
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 4) in vec2 aTex;
//coordinate space transformation matrices
uniform mat4 transform;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform float time;
//output buffers
out vec3 Normal;
out vec3 FragPos;
out vec2 TexCoord;
void main() {
//normalize posiiton and normal
vec4 FinalVertex = vec4(aPos, 1.0);
vec4 FinalNormal = vec4(aNormal, 1.0);
//push frag, normal, and texture positions to fragment shader
FragPos = vec3(model * FinalVertex);
Normal = mat3(transpose(inverse(model))) * aNormal;
TexCoord = aTex;
//set final position with opengl space
gl_Position = FinalVertex;
}

View File

@ -17,11 +17,11 @@ void main(){
);
gl_Position = vec4(finalPos.x, finalPos.y, 0.0, 1.0);
// vec2 finalTex = vec2(
// aTexCoords.x * tDimension.x + tPosition.x,
// aTexCoords.y * tDimension.y + tPosition.y
// );
vec2 finalTex = aTexCoords;
vec2 finalTex = vec2(
aTexCoords.x * tDimension.x + tPosition.x,
aTexCoords.y * tDimension.y + tPosition.y
);
// vec2 finalTex = aTexCoords;
// vec2 finalTex = vec2(
// aTexCoords.x + 0.7,
// aTexCoords.y

View File

@ -75,6 +75,7 @@ public class ControlHandler {
public static final String DATA_STRING_INPUT_CODE_MENU_INCREMENT = "menuIncrement";
public static final String DATA_STRING_INPUT_CODE_MENU_DECREMENT = "menuDecrement";
public static final String DATA_STRING_INPUT_CODE_MENU_SELECT = "menuSelect";
public static final String INPUT_CODE_MENU_MOUSE_PRIMARY = "menuMousePrimary";
public static final String DATA_STRING_INPUT_CODE_MENU_BACKOUT = "menuBackout";
@ -198,6 +199,7 @@ public class ControlHandler {
handler.addControl(DATA_STRING_INPUT_CODE_MENU_DECREMENT, new Control(ControlType.KEY,GLFW_KEY_UP));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_SELECT, new Control(ControlType.KEY,GLFW_KEY_ENTER));
handler.addControl(DATA_STRING_INPUT_CODE_MENU_BACKOUT, new Control(ControlType.KEY,GLFW_KEY_ESCAPE));
handler.addControl(INPUT_CODE_MENU_MOUSE_PRIMARY, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_LEFT));
/*
Map the typing controls
@ -520,7 +522,6 @@ public class ControlHandler {
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
if(
(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN) &&
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) &&
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()))
){
@ -534,7 +535,6 @@ public class ControlHandler {
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
if(
(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN) &&
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) &&
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()))
){
@ -741,10 +741,10 @@ public class ControlHandler {
// Globals.elementManager.registerWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, MenuGenerators.createInGameMainMenu());
// Globals.controlHandler.setHandlerState(ControlsState.IN_GAME_MAIN_MENU);
Window mainMenuWindow = new Window(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
Element mainMenuInGame = MenuGenerators.createInGameMainMenu();
mainMenuWindow.addChild(mainMenuInGame);
Globals.elementManager.registerWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, mainMenuWindow);
// Window mainMenuWindow = new Window(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
Window mainMenuInGame = MenuGenerators.createInGameMainMenu();
// mainMenuWindow.addChild(mainMenuInGame);
Globals.elementManager.registerWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, mainMenuInGame);
WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN), true);
Globals.elementManager.focusFirstElement();
Globals.controlHandler.setHandlerState(ControlsState.IN_GAME_MAIN_MENU);
@ -838,6 +838,18 @@ public class ControlHandler {
// MenuCallbacks.selectOption(Globals.currentMenu);
}});
menuNavigationControlList.add(controls.get(INPUT_CODE_MENU_MOUSE_PRIMARY));
mainGameDebugControlList.add(controls.get(INPUT_CODE_MENU_MOUSE_PRIMARY));
controls.get(INPUT_CODE_MENU_MOUSE_PRIMARY).setOnClick(new ControlMethod(){public void execute(){
Globals.elementManager.click(new ClickEvent(
(int)xpos,
(int)ypos,
true,
Globals.mouseCallback.getButton(GLFW_MOUSE_BUTTON_2)
));
}});
controls.get(INPUT_CODE_MENU_MOUSE_PRIMARY).setRepeatTimeout(0.5f);
menuNavigationControlList.add(controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT));
// controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).setOnPress(new ControlMethod(){public void execute(){
// // MenuCallbacks.backout(Globals.currentMenu);

View File

@ -675,10 +675,10 @@ public class LoadingThread extends Thread {
Entity sword = ItemUtils.spawnBasicItem("Katana");
EntityUtils.getPosition(sword).set(new Vector3f(1,0.1f,2));
Entity shorts = ItemUtils.spawnBasicItem("boots1");
EntityUtils.getPosition(shorts).set(new Vector3f(2,0.1f,2));
// Entity hair = ItemUtils.spawnBasicItem("hairshort1");
// EntityUtils.getPosition(hair).set(new Vector3f(2,0.1f,1));
// Entity shorts = ItemUtils.spawnBasicItem("boots1");
// EntityUtils.getPosition(shorts).set(new Vector3f(2,0.1f,2));
// // Entity hair = ItemUtils.spawnBasicItem("hairshort1");
// // EntityUtils.getPosition(hair).set(new Vector3f(2,0.1f,1));
Entity bow = ItemUtils.spawnBasicItem("bow1");
EntityUtils.getPosition(bow).set(new Vector3f(2,0.1f,1));
@ -715,6 +715,22 @@ public class LoadingThread extends Thread {
//set draw volumetric
cube.putData(EntityDataStrings.DRAW_VOLUMETRIC, true);
//queue grass shader
Globals.assetManager.addShaderToQueue("Shaders/grass1/grass1.vs", "Shaders/grass1/grass1.gs", "Shaders/grass1/grass1.fs");
for(int x = 0; x < 10; x++){
for(int y = 0; y < 10; y++){
Entity grass = EntityUtils.spawnDrawableEntity("Models/grass1.fbx");
//shader mask
EntityUtils.getActor(grass).maskShader("Cube", "Shaders/grass1/grass1.vs", "Shaders/grass1/grass1.gs", "Shaders/grass1/grass1.fs");
EntityUtils.getPosition(grass).set(2 + x / 2.0f,0.0,2 + y / 2.0f);
}
}
// goblin = CreatureUtils.spawnBasicCreature("Goblin");
// CollisionObjUtils.positionCharacter(goblin, new Vector3f(3, 0, 4));
// EntityUtils.getScale(goblin).set(0.005f);

View File

@ -59,10 +59,18 @@ public class AssetManager {
}
for(ActorShaderMask currentShader : shadersInQueue){
shadersInQueue.remove(currentShader);
shadersLoadedIntoMemory.put(
getShaderKey(currentShader.getVertexShaderPath(),currentShader.getFragmentShaderPath()),
ShaderProgram.loadSpecificShader(currentShader.getVertexShaderPath(),currentShader.getFragmentShaderPath())
);
String key = getShaderKey(currentShader.getVertexShaderPath(),currentShader.getGeometryShaderPath(),currentShader.getFragmentShaderPath());
if(currentShader.getGeometryShaderPath() == null){
shadersLoadedIntoMemory.put(
key,
ShaderProgram.loadSpecificShader(currentShader.getVertexShaderPath(),currentShader.getFragmentShaderPath())
);
} else {
shadersLoadedIntoMemory.put(
key,
ShaderProgram.loadSpecificShader(currentShader.getVertexShaderPath(),currentShader.getGeometryShaderPath(),currentShader.getFragmentShaderPath())
);
}
}
performMeshOverrides();
}
@ -214,11 +222,15 @@ public class AssetManager {
//SHADERS
//
public void addShaderToQueue(String vertexShader, String fragmentShader){
shadersInQueue.add(new ActorShaderMask("","",vertexShader,fragmentShader));
shadersInQueue.add(new ActorShaderMask("","",vertexShader,null,fragmentShader));
}
public ShaderProgram fetchShader(String vertexPath, String fragmentPath){
String path = getShaderKey(vertexPath,fragmentPath);
public void addShaderToQueue(String vertexShader, String geometryShader, String fragmentShader){
shadersInQueue.add(new ActorShaderMask("","",vertexShader,geometryShader,fragmentShader));
}
public ShaderProgram fetchShader(String vertexPath, String geometryShader, String fragmentPath){
String path = getShaderKey(vertexPath,geometryShader,fragmentPath);
ShaderProgram rVal = null;
if(shadersLoadedIntoMemory.containsKey(path)){
rVal = shadersLoadedIntoMemory.get(path);
@ -226,8 +238,8 @@ public class AssetManager {
return rVal;
}
static String getShaderKey(String vertexPath, String fragmentPath){
return vertexPath + "-" + fragmentPath;
static String getShaderKey(String vertexPath, String geometryPath, String fragmentPath){
return vertexPath + "-" + geometryPath + "-" + fragmentPath;
}

View File

@ -39,6 +39,8 @@ public class EntityDataStrings {
public static final String DATA_STRING_ACCELERATION = "acceleration";
public static final String DATA_STRING_MAX_NATURAL_VELOCITY = "velocityMaxNatural";
public static final String CREATURE_ATTRIBUTE_VARIANT = "creatureAttributeVariant";
public static final String ROTATOR_TREE = "rotatorTree";
/*
All Camera Types

View File

@ -313,7 +313,7 @@ public class AttackTree {
// EntityUtils.getRotation(currentEntity).rotationTo(new Vector3f(0,0,1), new Vector3f((float)facingAngle.x,(float)facingAngle.y,(float)facingAngle.z)).mul(parentActor.getBoneRotation(targetBone)).normalize();
}
Vector3f initialVector = new Vector3f((float)movementVector.x,(float)movementVector.y,(float)movementVector.z).normalize();
ProjectileUtils.spawnBasicProjectile(projectileToFire, spawnPosition, arrowRotation, 200, initialVector, 0.03f);
ProjectileUtils.spawnBasicProjectile(projectileToFire, spawnPosition, arrowRotation, 750, initialVector, 0.03f);
projectileToFire = null;
}
frameCurrent++;

View File

@ -11,6 +11,7 @@ import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.game.data.creature.type.CreatureType;
import electrosphere.game.data.creature.type.MovementSystem;
import electrosphere.entity.state.AttackTree;
import electrosphere.entity.state.BehaviorTree;
import electrosphere.entity.state.IdleTree;
import electrosphere.entity.state.collidable.CollidableTree;
import electrosphere.entity.state.equip.EquipState;
@ -26,6 +27,8 @@ import electrosphere.game.data.creature.type.CollidableTemplate;
import electrosphere.game.data.creature.type.SprintSystem;
import electrosphere.game.data.creature.type.attack.AttackMove;
import electrosphere.game.data.creature.type.equip.EquipPoint;
import electrosphere.game.data.creature.type.rotator.RotatorItem;
import electrosphere.game.data.creature.type.rotator.RotatorSystem;
import electrosphere.game.data.creature.type.visualattribute.AttributeVariant;
import electrosphere.game.data.creature.type.visualattribute.VisualAttribute;
import electrosphere.logger.LoggerInterface;
@ -38,6 +41,7 @@ import electrosphere.net.server.Player;
import electrosphere.renderer.Model;
import electrosphere.renderer.actor.Actor;
import electrosphere.renderer.actor.ActorUtils;
import electrosphere.renderer.light.PointLight;
import electrosphere.util.ModelLoader;
import java.util.LinkedList;
@ -215,6 +219,12 @@ public class CreatureUtils {
}
}
}
//rotator system
if(rawType.getRotatorSystem() != null){
RotatorSystem system = rawType.getRotatorSystem();
for(RotatorItem item : system.getRotatorItems()){
}
}
//add health system
rVal.putData(EntityDataStrings.LIFE_STATE, new LifeState(rVal, rawType.getHealthSystem()));
Globals.entityManager.registerLifeStateEntity(rVal);

View File

@ -27,6 +27,7 @@ import electrosphere.renderer.ui.elements.Button;
import electrosphere.renderer.ui.elements.Div;
import electrosphere.renderer.ui.elements.ImagePanel;
import electrosphere.renderer.ui.elements.Label;
import electrosphere.renderer.ui.elements.ScrollableContainer;
import electrosphere.renderer.ui.elements.TextInput;
import electrosphere.renderer.ui.events.ClickEvent;
import electrosphere.renderer.ui.events.DragEvent;
@ -430,14 +431,16 @@ public class MenuGenerators {
rVal.addChild(div);
return rVal;
}
public static Element createInGameMainMenu(){
public static Window createInGameMainMenu(){
// int screenTop = Globals.WINDOW_HEIGHT - 150;
int width = 500;
int height = 500;
Window rVal = new Window(0,0,width,height);
// int screenLeft = (Globals.WINDOW_WIDTH - width)/2;
Div rVal = new Div();
rVal.setOnNavigationCallback(new NavigationEventCallback() {public boolean execute(NavigationEvent event){
Div div = new Div();
rVal.addChild(div);
div.setOnNavigationCallback(new NavigationEventCallback() {public boolean execute(NavigationEvent event){
WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN), false);
Globals.elementManager.unregisterWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN);
Globals.controlHandler.setHandlerState(ControlsState.MAIN_GAME);
@ -450,14 +453,14 @@ public class MenuGenerators {
// imagePanel.setWidth(width);
// imagePanel.setHeight(height);
// imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.blackTexture));
rVal.addChild(imagePanel);
div.addChild(imagePanel);
//label 1 (back)
Button backButton = new Button();
Label backLabel = new Label(100,50,1.0f);
backLabel.setText("Back");
backButton.addChild(backLabel);
rVal.addChild(backButton);
div.addChild(backButton);
backButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN), false);
Globals.elementManager.unregisterWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN);
@ -470,14 +473,89 @@ public class MenuGenerators {
//label 2 (quit)
Button quitButton = new Button();
Label quitLabel = new Label(100,150,1.0f);
quitLabel.setText("QUIT");
quitLabel.setText("Quit");
quitButton.addChild(quitLabel);
rVal.addChild(quitButton);
div.addChild(quitButton);
quitButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
Main.running = false;
return false;
}});
//checking macro data is a poor man's check for whether we're arena or full gamemode
if(Globals.server != null && Globals.macroData == null){
//label 3 (debug)
Button debugButton = new Button();
Label debugLabel = new Label(100,250,1.0f);
debugLabel.setText("Debug");
debugButton.addChild(debugLabel);
div.addChild(debugButton);
debugButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, createInGameDebugMainMenu());
return false;
}});
}
return rVal;
}
public static Window createInGameDebugMainMenu(){
// int screenTop = Globals.WINDOW_HEIGHT - 150;
int width = 500;
int height = 500;
float fontSize = 0.4f;
Window rVal = new Window(0,0,width,height);
// int screenLeft = (Globals.WINDOW_WIDTH - width)/2;
Div div = new Div();
ScrollableContainer scrollable = new ScrollableContainer(0, 0, width, height);
rVal.addChild(scrollable);
scrollable.addChild(div);
div.setOnNavigationCallback(new NavigationEventCallback() {public boolean execute(NavigationEvent event){
WindowUtils.replaceWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, createInGameMainMenu());
return false;
}});
//black texture background
ImagePanel imagePanel = new ImagePanel(0,0,width,height + 1000,Globals.blackTexture);
// imagePanel.setWidth(width);
// imagePanel.setHeight(height);
// imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.blackTexture));
div.addChild(imagePanel);
//label 1 (back)
Button backButton = new Button();
Label backLabel = new Label(100,50,fontSize);
backLabel.setText("Back");
backButton.addChild(backLabel);
div.addChild(backButton);
backButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, createInGameMainMenu());
return false;
}});
//label 2 (quit)
Button quitButton = new Button();
Label quitLabel = new Label(100,150,fontSize);
quitLabel.setText("debug or smthn");
quitButton.addChild(quitLabel);
div.addChild(quitButton);
quitButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
// Main.running = false;
return false;
}});
for(int i = 0; i < 10; i++){
Button someButton = new Button();
Label someLabel = new Label(100,250 + i * 100,fontSize);
someLabel.setText("aaaaaa");
someButton.addChild(someLabel);
div.addChild(someButton);
someButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
// Main.running = false;
return false;
}});
}
return rVal;
}

View File

@ -237,7 +237,7 @@ public class Model {
if(shaderMask.containsKey(mesh.nodeID)){
ActorShaderMask specificMask = shaderMask.get(mesh.nodeID);
ShaderProgram overwriteShader = null;
if((overwriteShader = Globals.assetManager.fetchShader(specificMask.getVertexShaderPath(), specificMask.getFragmentShaderPath())) != null){
if((overwriteShader = Globals.assetManager.fetchShader(specificMask.getVertexShaderPath(), specificMask.getGeometryShaderPath(), specificMask.getFragmentShaderPath())) != null){
ShaderProgram oldProgram = mesh.shader;
rVal = overwriteShader;
}

View File

@ -10,7 +10,9 @@ import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL32;
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opengl.GL32.*;
/**
*
@ -21,6 +23,7 @@ public class ShaderProgram {
//Program stuff
//
int vertexShader;
int geometryShader;
int fragmentShader;
int shaderProgram;
@ -354,6 +357,105 @@ public class ShaderProgram {
return rVal;
}
public static ShaderProgram loadSpecificShader(String vertexPath, String geometryPath, String fragmentPath){
ShaderProgram rVal = new ShaderProgram();
//
//Read in shader programs
//
String vertexShaderSource = "";
String geometryShaderSource = "";
String fragmentShaderSource = "";
try {
vertexShaderSource = FileUtils.getAssetFileAsString(vertexPath);
geometryShaderSource = FileUtils.getAssetFileAsString(geometryPath);
fragmentShaderSource = FileUtils.getAssetFileAsString(fragmentPath);
} catch(IOException ex){
}
//Creates a new shader object and assigns its 'pointer' to the integer "vertexShader"
rVal.vertexShader = glCreateShader(GL_VERTEX_SHADER);
//This alerts openGL to the presence of a vertex shader and points the shader at its source
glShaderSource(rVal.vertexShader, vertexShaderSource);
//Compiles the source for the vertex shader object
glCompileShader(rVal.vertexShader);
//The following tests if the vertex shader compiles successfully
int success;
success = glGetShaderi(rVal.vertexShader, GL_COMPILE_STATUS);
if (success != GL_TRUE) {
LoggerInterface.loggerRenderer.WARNING("Vertex Shader failed to compile!");
LoggerInterface.loggerRenderer.WARNING("Source is: ");
LoggerInterface.loggerRenderer.WARNING(GL20.glGetShaderSource(rVal.vertexShader));
LoggerInterface.loggerRenderer.ERROR("Runtime Exception", new RuntimeException(GL20.glGetShaderInfoLog(rVal.vertexShader)));
}
//Creates a new shader object and assigns its 'pointer' to the integer "vertexShader"
rVal.geometryShader = glCreateShader(GL_GEOMETRY_SHADER);
//This alerts openGL to the presence of a vertex shader and points the shader at its source
glShaderSource(rVal.geometryShader, geometryShaderSource);
//Compiles the source for the vertex shader object
glCompileShader(rVal.geometryShader);
//The following tests if the vertex shader compiles successfully
success = glGetShaderi(rVal.geometryShader, GL_COMPILE_STATUS);
if (success != GL_TRUE) {
LoggerInterface.loggerRenderer.WARNING("Geometry Shader failed to compile!");
LoggerInterface.loggerRenderer.WARNING("Source is: ");
LoggerInterface.loggerRenderer.WARNING(GL20.glGetShaderSource(rVal.geometryShader));
LoggerInterface.loggerRenderer.ERROR("Runtime Exception", new RuntimeException(GL20.glGetShaderInfoLog(rVal.geometryShader)));
}
//Creates and opengl object for a fragment shader and assigns its 'pointer' to the integer fragmentShader
rVal.fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
//This points the opengl shadder object to its proper source
glShaderSource(rVal.fragmentShader, fragmentShaderSource);
//This compiles the shader object
glCompileShader(rVal.fragmentShader);
//This tests for the success of the compile attempt
success = glGetShaderi(rVal.fragmentShader, GL_COMPILE_STATUS);
if (success != GL_TRUE) {
LoggerInterface.loggerRenderer.WARNING("Fragment Shader failed to compile!");
LoggerInterface.loggerRenderer.WARNING("Source is: ");
LoggerInterface.loggerRenderer.WARNING(GL20.glGetShaderSource(rVal.fragmentShader));
LoggerInterface.loggerRenderer.ERROR("Runtime Exception", new RuntimeException(GL20.glGetShaderInfoLog(rVal.fragmentShader)));
}
//This creates a shader program opengl object and assigns its 'pointer' to the integer shaderProgram
rVal.shaderProgram = glCreateProgram();
//This attaches the vertex and fragment shaders to the program
glAttachShader(rVal.shaderProgram, rVal.vertexShader);
glAttachShader(rVal.shaderProgram, rVal.geometryShader);
glAttachShader(rVal.shaderProgram, rVal.fragmentShader);
//This links the program to the GPU (I think its to the GPU anyway)
glLinkProgram(rVal.shaderProgram);
//Tests for the success of the shader program creation
success = glGetProgrami(rVal.shaderProgram, GL_LINK_STATUS);
if (success != GL_TRUE) {
throw new RuntimeException(glGetProgramInfoLog(rVal.shaderProgram));
}
//Deletes the individual shader objects to free up memory
glDeleteShader(rVal.vertexShader);
glDeleteShader(rVal.geometryShader);
glDeleteShader(rVal.fragmentShader);
//
//Set locations
//
rVal.shaderVertexModelLoc = glGetUniformLocation(rVal.shaderProgram, "model");
rVal.shaderVertexViewLoc = glGetUniformLocation(rVal.shaderProgram, "view");
rVal.shaderVertexProjectionLoc = glGetUniformLocation(rVal.shaderProgram, "projection");
rVal.shaderVertexViewPosLoc = glGetUniformLocation(rVal.shaderProgram, "viewPos");
return rVal;
}

View File

@ -326,7 +326,11 @@ public class Actor {
}
public void maskShader(String mesh, String vertexShader, String fragmentShader){
shaderMasks.add(new ActorShaderMask(this.modelPath, mesh, vertexShader, fragmentShader));
shaderMasks.add(new ActorShaderMask(this.modelPath, mesh, vertexShader, null, fragmentShader));
}
public void maskShader(String mesh, String vertexShader, String geometryShader, String fragmentShader){
shaderMasks.add(new ActorShaderMask(this.modelPath, mesh, vertexShader, geometryShader, fragmentShader));
}
public void unmaskShader(String mesh){

View File

@ -5,12 +5,14 @@ public class ActorShaderMask {
String modelName;
String meshName;
String vertexShaderPath;
String geometryShaderPath;
String fragmentShaderPath;
public ActorShaderMask(String modelName, String meshName, String vertexShaderPath, String fragmentShaderPath){
public ActorShaderMask(String modelName, String meshName, String vertexShaderPath, String geometryShaderPath, String fragmentShaderPath){
this.modelName = modelName;
this.meshName = meshName;
this.vertexShaderPath = vertexShaderPath;
this.geometryShaderPath = geometryShaderPath;
this.fragmentShaderPath = fragmentShaderPath;
}
@ -26,6 +28,10 @@ public class ActorShaderMask {
return vertexShaderPath;
}
public String getGeometryShaderPath(){
return geometryShaderPath;
}
public String getFragmentShaderPath(){
return fragmentShaderPath;
}

View File

@ -66,6 +66,18 @@ public class LightManager {
pointLights[0].setQuadratic(1.8f);
pointLights[0].setSpecular(new Vector3f(0.0f,0.0f,0.0f));
// pointLights[0].setAmbient(new Vector3f(0.924500f, 0.369800f, 0.092450f));
// pointLights[0].setConstant(1.0f);
// pointLights[0].setDiffuse(new Vector3f(0.924500f, 0.369800f, 0.092450f));
// pointLights[0].setLinear(0.09f);
// pointLights[0].setPosition(new Vector3f(1.0f,0.05f,1.0f));
// pointLights[0].setQuadratic(0.032f);
// pointLights[0].setSpecular(new Vector3f(0.0f,0.0f,0.0f));
/*
Vector3f lightLoc = new Vector3f(0.2f,-1.0f,0.3f);
float temp[] = new float[3];
@ -109,6 +121,10 @@ public class LightManager {
//alternatively if want to use range, do glBindBufferRange(GL_UNIFORM_BUFFER, 2, uboExampleBlock, 0, 152);
}
public void setPointLight(PointLight light, int index){
pointLights[index] = light;
}
/**
* Call once per render loop to set buffer values
*/

View File

@ -102,10 +102,6 @@ public class Window implements DrawableElement, ContainerElement, NavigableEleme
}
}
}
public void destroy() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void setTextureCoord(int x, int y){
float ndcX = (float)x/Globals.WINDOW_WIDTH;

View File

@ -126,11 +126,19 @@ public class Button implements DrawableElement, FocusableElement, ContainerEleme
}
public void setPositionX(int positionX) {
int deltaX = this.positionX - positionX;
this.positionX = positionX;
for(Element child : childList){
child.setPositionX(child.getPositionX() + deltaX);
}
}
public void setPositionY(int positionY) {
int deltaY = this.positionY - positionY;
this.positionY = positionY;
for(Element child : childList){
child.setPositionY(child.getPositionY() + deltaY);
}
}
public void setVisible(boolean draw) {

View File

@ -153,26 +153,32 @@ public class Div implements ClickableElement,ContainerElement,DraggableElement,F
@Override
public void setPositionX(int positionX) {
// TODO Auto-generated method stub
int deltaX = this.positionX - positionX;
this.positionX = positionX;
for(Element child : childList){
child.setPositionX(child.getPositionX() + deltaX);
}
}
@Override
public void setPositionY(int positionY) {
// TODO Auto-generated method stub
int deltaY = this.positionY - positionY;
this.positionY = positionY;
for(Element child : childList){
child.setPositionY(child.getPositionY() + deltaY);
}
}
@Override
public void setParentWidth(int width) {
// TODO Auto-generated method stub
this.parentWidth = width;
}
@Override
public void setParentHeight(int height) {
// TODO Auto-generated method stub
this.parentHeight = height;
}

View File

@ -173,11 +173,19 @@ public class Label implements DrawableElement {
}
public void setPositionX(int positionX) {
int deltaX = this.positionX - positionX;
this.positionX = positionX;
for(Element child : childrenElements){
child.setPositionX(child.getPositionX() + deltaX);
}
}
public void setPositionY(int positionY) {
int deltaY = this.positionY - positionY;
this.positionY = positionY;
for(Element child : childrenElements){
child.setPositionY(child.getPositionY() + deltaY);
}
}
public void setVisible(boolean draw) {

View File

@ -0,0 +1,272 @@
package electrosphere.renderer.ui.elements;
import java.util.LinkedList;
import java.util.List;
import org.joml.Vector2f;
import org.joml.Vector3f;
import electrosphere.main.Globals;
import electrosphere.renderer.Material;
import electrosphere.renderer.Model;
import electrosphere.renderer.framebuffer.Framebuffer;
import electrosphere.renderer.framebuffer.FramebufferUtils;
import electrosphere.renderer.ui.ContainerElement;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.Element;
import electrosphere.renderer.ui.events.Event;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL30.*;
public class ScrollableContainer implements DrawableElement, ContainerElement {
boolean focused = false;
List<Element> childList = new LinkedList<Element>();
public int width = 1;
public int height = 1;
public int positionX = 0;
public int positionY = 0;
public int parentWidth = 1;
public int parentHeight = 1;
public boolean visible = false;
Framebuffer widgetBuffer;
Material customMat = new Material();
Vector3f boxPosition = new Vector3f();
Vector3f boxDimensions = new Vector3f();
Vector3f texPosition = new Vector3f(0,1,0);
Vector3f texScale = new Vector3f(1,-1,0);
public ScrollableContainer(int positionX, int positionY, int width, int height){
widgetBuffer = FramebufferUtils.generateTextureFramebuffer(width, height);
// widgetBuffer = FramebufferUtils.generateScreensizeTextureFramebuffer();
customMat.setTexturePointer(widgetBuffer.getTexturePointer());
// customMat.setTexturePointer(Globals.assetManager.fetchTexture("Textures/Testing1.png").getTexturePointer());
float ndcX = (float)positionX/Globals.WINDOW_WIDTH;
float ndcY = (float)positionY/Globals.WINDOW_HEIGHT;
float ndcWidth = (float)width/Globals.WINDOW_WIDTH;
float ndcHeight = (float)height/Globals.WINDOW_HEIGHT;
this.width = width;
this.height = height;
boxPosition = new Vector3f(ndcX,ndcY,0);
boxDimensions = new Vector3f(ndcWidth,ndcHeight,0);
}
@Override
public int getWidth() {
return width;
}
@Override
public int getHeight() {
return height;
}
@Override
public int getPositionX() {
return positionX;
}
@Override
public int getPositionY() {
return positionY;
}
@Override
public void setWidth(int width) {
// TODO Auto-generated method stub
this.width = width;
}
@Override
public void setHeight(int height) {
// TODO Auto-generated method stub
this.height = height;
}
@Override
public void setPositionX(int positionX) {
// TODO Auto-generated method stub
this.positionX = positionX;
}
@Override
public void setPositionY(int positionY) {
// TODO Auto-generated method stub
this.positionY = positionY;
}
@Override
public void setParentWidth(int width) {
// TODO Auto-generated method stub
parentWidth = width;
float ndcX = (float)positionX/parentWidth;
float ndcY = (float)positionY/parentHeight;
float ndcWidth = (float)width/parentWidth;
float ndcHeight = (float)height/parentHeight;
boxPosition = new Vector3f(ndcX,ndcY,0);
boxDimensions = new Vector3f(ndcWidth,ndcHeight,0);
}
@Override
public void setParentHeight(int height) {
// TODO Auto-generated method stub
parentHeight = height;
float ndcX = (float)positionX/parentWidth;
float ndcY = (float)positionY/parentHeight;
float ndcWidth = (float)width/parentWidth;
float ndcHeight = (float)height/parentHeight;
boxPosition = new Vector3f(ndcX,ndcY,0);
boxDimensions = new Vector3f(ndcWidth,ndcHeight,0);
}
@Override
public void addChild(Element child) {
childList.add(child);
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.setParentWidth(width);
drawableChild.setParentHeight(height);
drawableChild.setVisible(false);
}
}
@Override
public List<Element> getChildren() {
return childList;
}
@Override
public void removeChild(Element child) {
childList.remove(child);
}
@Override
public boolean handleEvent(Event event) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean getVisible() {
// TODO Auto-generated method stub
return visible;
}
@Override
public void setVisible(boolean visible) {
// TODO Auto-generated method stub
this.visible = visible;
}
//recursively check if focused element is child of input element or is input element
boolean containsFocusedElement(Element parent){
Element focusedElement = Globals.elementManager.getFocusedElement();
if(parent == focusedElement){
return true;
} else if(parent instanceof ContainerElement){
ContainerElement container = (ContainerElement)parent;
for(Element child : container.getChildren()){
if(containsFocusedElement(child)){
return true;
}
}
}
return false;
}
@Override
public void draw(int parentFramebufferPointer, int parentWidth, int parentHeight) {
//figure out if currently focused element is a child or subchild of this container
if(containsFocusedElement(this)){
//if it is, if it is offscreen, calculate offset to put it onscreen
Element focused = Globals.elementManager.getFocusedElement();
if(
focused.getPositionX() + focused.getWidth() > this.width ||
focused.getPositionY() + focused.getHeight() > this.height ||
focused.getPositionX() < 0 ||
focused.getPositionY() < 0
){
int neededOffsetX = 0;
int neededOffsetY = 0;
//basically if we're offscreen negative, pull to positive
//if we're offscreen positive and we're not as large as the screen, pull from the positive into focus
//if we are larger than the screen, set position to 0
if(focused.getPositionX() < 0){
neededOffsetX = -focused.getPositionX();
} else if(focused.getPositionX() + focused.getWidth() > this.width){
if(focused.getWidth() > this.width){
neededOffsetX = -focused.getPositionX();
} else {
neededOffsetX = -((focused.getPositionX() - this.width) + focused.getWidth());
}
}
if(focused.getPositionY() < 0){
neededOffsetY = -focused.getPositionY();
} else if(focused.getPositionY() + focused.getHeight() > this.height){
if(focused.getHeight() > this.height){
neededOffsetY = -focused.getPositionY();
} else {
neededOffsetY = -((focused.getPositionY() - this.height) + focused.getHeight());
System.out.println(focused.getPositionY() + " " + this.height + " " + focused.getHeight());
}
}
//apply offset to all children
System.out.println(focused);
for(Element child : childList){
int currentX = child.getPositionX();
int currentY = child.getPositionY();
child.setPositionX(currentX + neededOffsetX);
child.setPositionY(currentY + neededOffsetY);
System.out.println(currentX + " " + currentY);
}
}
}
widgetBuffer.bind();
// Globals.renderingEngine.setViewportSize(width, height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for(Element child : childList){
if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child;
drawableChild.draw(widgetBuffer.getFramebufferPointer(),width,height);
}
}
//this call binds the screen as the "texture" we're rendering to
//have to call before actually rendering
glBindFramebuffer(GL_FRAMEBUFFER, parentFramebufferPointer);
Globals.renderingEngine.setViewportSize(parentWidth, parentHeight);
Model planeModel = Globals.assetManager.fetchModel(Globals.planeModelID);
planeModel.pushUniformToMesh("plane", "mPosition", boxPosition);
planeModel.pushUniformToMesh("plane", "mDimension", boxDimensions);
planeModel.pushUniformToMesh("plane", "tPosition", texPosition);
planeModel.pushUniformToMesh("plane", "tDimension", texScale);
planeModel.meshes.get(0).setMaterial(customMat);
planeModel.drawUI();
}
}