Force reload shaders debug option

This commit is contained in:
austin 2022-03-18 19:07:55 -04:00
parent 2f0af2f096
commit 413f9c8b8c
5 changed files with 106 additions and 32 deletions

View File

@ -2,7 +2,7 @@
layout (triangles) in;
layout (triangle_strip, max_vertices = 150) out;
layout (triangle_strip, max_vertices = 200) out;
uniform mat4 model;
uniform mat4 view;
@ -14,18 +14,36 @@ 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.5, 0.0 + yPos, 0.0)).xyz;
gl_Position = projection * view * model * (triangle1Pos + vec4( 0.0 + xPos, 0.0, 0.0 + yPos, 0.0));
//
//Each new vertex is a new triangle using the previous two
//
float bladeHeight = 0.2;
for(float x = 0; x < 4; x++){
for(float y = 0; y < 4; y++){
float xPos = x / 20.0;
float yPos = y / 20.0;
origCoord = (triangle1Pos + vec4( 0.0 + xPos, 0.45, 0.0 + yPos, 0.0)).xyz;
gl_Position = projection * view * model * (triangle1Pos + vec4( 0.0 + xPos, 0.45, 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));
origCoord = (triangle1Pos + vec4( 0.05 + xPos, 0.45, 0.0 + yPos, 0.0)).xyz;
gl_Position = projection * view * model * (triangle1Pos + vec4( 0.05 + xPos, 0.45, 0.0 + yPos, 0.0));
EmitVertex();
origCoord = (triangle1Pos + vec4( 0.05 + 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));
origCoord = (triangle1Pos + vec4( 0.025 + xPos, 0.95, 0.025 + yPos, 0.0)).xyz;
gl_Position = projection * view * model * (triangle1Pos + vec4( 0.025 + xPos, 0.45 + bladeHeight, 0.025 + yPos, 0.0));
EmitVertex();
origCoord = (triangle1Pos + vec4( 0.05 + xPos, 0.45, 0.05 + yPos, 0.0)).xyz;
gl_Position = projection * view * model * (triangle1Pos + vec4( 0.05 + xPos, 0.45, 0.05 + yPos, 0.0));
EmitVertex();
origCoord = (triangle1Pos + vec4( 0.0 + xPos, 0.45, 0.05 + yPos, 0.0)).xyz;
gl_Position = projection * view * model * (triangle1Pos + vec4( 0.0 + xPos, 0.45, 0.05 + yPos, 0.0));
EmitVertex();
origCoord = (triangle1Pos + vec4( 0.025 + xPos, 0.95, 0.025 + yPos, 0.0)).xyz;
gl_Position = projection * view * model * (triangle1Pos + vec4( 0.025 + xPos, 0.45 + bladeHeight, 0.025 + yPos, 0.0));
EmitVertex();
origCoord = (triangle1Pos + vec4( 0.0 + xPos, 0.45, 0.0 + yPos, 0.0)).xyz;
gl_Position = projection * view * model * (triangle1Pos + vec4( 0.0 + xPos, 0.45, 0.0 + yPos, 0.0));
EmitVertex();
EndPrimitive();
}

View File

@ -547,8 +547,8 @@ public class LoadingThread extends Thread {
Skybox
*/
Model skyboxModel = Globals.assetManager.fetchModel(AssetDataStrings.ASSET_STRING_SKYBOX_BASIC);
Globals.skybox = EntityUtils.spawnDrawableEntity(AssetDataStrings.ASSET_STRING_SKYBOX_BASIC);
// Model skyboxModel = Globals.assetManager.fetchModel(AssetDataStrings.ASSET_STRING_SKYBOX_BASIC);
// Globals.skybox = EntityUtils.spawnDrawableEntity(AssetDataStrings.ASSET_STRING_SKYBOX_BASIC);
/*
@ -709,18 +709,22 @@ public class LoadingThread extends Thread {
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(3 + x / 2.0f,0.0,1 + y / 2.0f);
// }
// }
// EntityUtils.getPosition(grass).set(3,0,1);
//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(3 + x / 5.0f,0.0,1 + y / 5.0f);
}
}
//water cube

View File

@ -242,6 +242,20 @@ public class AssetManager {
return vertexPath + "-" + geometryPath + "-" + fragmentPath;
}
/**
* Nuclear function, reloads all shaders loaded into memory
*/
public void forceReloadAllShaders(){
for(String shaderKey : shadersLoadedIntoMemory.keySet()){
String shaderPaths[] = shaderKey.split("-");
if(shaderPaths[1].equals("null")){
shaderPaths[1] = null;
}
shadersInQueue.add(new ActorShaderMask("","",shaderPaths[0],shaderPaths[1],shaderPaths[2]));
}
shadersLoadedIntoMemory.clear();
}

View File

@ -550,13 +550,13 @@ public class MenuGenerators {
return false;
}});
//label 2 (quit)
Button quitButton = new Button();
Label quitLabel = new Label(100,250,fontSize);
quitLabel.setText("Print Model Debug Info");
quitButton.addChild(quitLabel);
scrollable.addChild(quitButton);
quitButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
//label 3 (load model and debug)
Button debugModelButton = new Button();
Label debugModelLabel = new Label(100,250,fontSize);
debugModelLabel.setText("Print Model Debug Info");
debugModelButton.addChild(debugModelLabel);
scrollable.addChild(debugModelButton);
debugModelButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
// Main.running = false;
Model targetModel = null;
if((targetModel = Globals.assetManager.fetchModel(modelDebugInput.getText())) != null){
@ -571,9 +571,21 @@ public class MenuGenerators {
return false;
}});
//label 4 (reload all shaders)
Button reloadShaderButton = new Button();
Label reloadShaderLabel = new Label(100,350,fontSize);
reloadShaderLabel.setText("Reload all shaders");
reloadShaderButton.addChild(reloadShaderLabel);
scrollable.addChild(reloadShaderButton);
reloadShaderButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
// Main.running = false;
Globals.assetManager.forceReloadAllShaders();
return false;
}});
for(int i = 0; i < 9; i++){
Button someButton = new Button();
Label someLabel = new Label(100,350 + i * 100,fontSize);
Label someLabel = new Label(100,450 + i * 100,fontSize);
someLabel.setText("aaaaaa" + i);
someButton.addChild(someLabel);
scrollable.addChild(someButton);

View File

@ -952,6 +952,32 @@ public class RenderingEngine {
}
}
//
//Draw front faces of all non-volumetrics
//
cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera);
for(Entity currentEntity : Globals.entityManager.getDrawable()){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) &&
drawPoint(cameraPos,new Vector3f((float)position.x,(float)position.y,(float)position.z)) &&
!currentEntity.getDataKeys().contains(EntityDataStrings.DRAW_VOLUMETRIC)
){
//fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity);
//calculate camera-modified vector3f
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
//set projection matrix
glUniformMatrix4fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "projection"), false, nearVolumeProjectionMatrix.get(new float[16]));
modelTransformMatrix = modelTransformMatrix.identity();
modelTransformMatrix.translate(cameraModifiedPosition);
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
modelTransformMatrix.scale(EntityUtils.getScale(currentEntity));
currentActor.applyModelMatrix(modelTransformMatrix);
currentActor.drawForDepthBuffer();
}
}
//stop rendering front faces