Skip to content

Commit

Permalink
Antimatter Amd fix (GTNewHorizons#3375)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Robertz <dream-master@gmx.net>
  • Loading branch information
CookieBrigade and Dream-Master authored Oct 15, 2024
1 parent 1d89408 commit cef96f0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
55 changes: 34 additions & 21 deletions src/main/java/goodgenerator/client/render/AntimatterRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import cpw.mods.fml.client.registry.ClientRegistry;
import goodgenerator.blocks.tileEntity.render.TileAntimatter;
import gregtech.GTMod;

public class AntimatterRenderer extends TileEntitySpecialRenderer {

Expand Down Expand Up @@ -48,6 +49,7 @@ public class AntimatterRenderer extends TileEntitySpecialRenderer {
private static final int beamVertexCount = particleCount * 6 * 6;

private boolean initialized = false;
private boolean hasFailed = false;

// Glowy Ring
private static ShaderProgram glowProgram;
Expand Down Expand Up @@ -85,26 +87,26 @@ public void loadModels() {
}

private void init() {
antimatterProgram = new ShaderProgram(
GoodGenerator.resourceDomain,
"shaders/antimatter.vert.glsl",
"shaders/antimatter.frag.glsl");

antimatterProgram.use();

try {
antimatterProgram = new ShaderProgram(
GoodGenerator.resourceDomain,
"shaders/antimatter.vert.glsl",
"shaders/antimatter.frag.glsl");

uScale = antimatterProgram.getUniformLocation("u_Scale");
uScaleSnapshot = antimatterProgram.getUniformLocation("u_ScaleSnapshot");
uTime = antimatterProgram.getUniformLocation("u_Time");
uTimeSnapshot = antimatterProgram.getUniformLocation("u_TimeSnapshot");
uOpacity = antimatterProgram.getUniformLocation("u_Opacity");
uColorCore = antimatterProgram.getUniformLocation("u_ColorCore");
uColorSpike = antimatterProgram.getUniformLocation("u_ColorSpike");
} catch (NullPointerException e) {
System.out.println(e.getMessage());
} catch (Exception e) {
GTMod.GT_FML_LOGGER.error(e.getMessage());
return;
}

antimatterProgram.use();

GL20.glUniform3f(uColorCore, TileAntimatter.coreR, TileAntimatter.coreG, TileAntimatter.coreB);
GL20.glUniform3f(uColorSpike, TileAntimatter.spikeR, TileAntimatter.spikeG, TileAntimatter.spikeB);
GL20.glUniform1f(uOpacity, 1);
Expand All @@ -113,25 +115,27 @@ private void init() {

loadModels();

protomatterProgram = new ShaderProgram(
GoodGenerator.resourceDomain,
"shaders/protomatter.vert.glsl",
"shaders/protomatter.frag.glsl");
int uCubeCount = -1;
int uProtomatterVertices = -1;

int uCubeCount;
int uProtomatterVertices;
try {
protomatterProgram = new ShaderProgram(
GoodGenerator.resourceDomain,
"shaders/protomatter.vert.glsl",
"shaders/protomatter.frag.glsl");

uProtomatterVertices = protomatterProgram.getUniformLocation("u_Vertices");
uCubeCount = protomatterProgram.getUniformLocation("u_CubeCount");
uProtomatterTime = protomatterProgram.getUniformLocation("u_Time");
uProtomatterScale = protomatterProgram.getUniformLocation("u_Scale");
uProtomatterColor = protomatterProgram.getUniformLocation("u_Color");
uProtomatterSpiralRadius = protomatterProgram.getUniformLocation("u_SpiralRadius");
} catch (NullPointerException e) {
return;
} catch (Exception e) {
GTMod.GT_FML_LOGGER.error(e.getMessage());
}

protomatterProgram.use();

FloatBuffer bufferBeamVertexID = BufferUtils.createFloatBuffer(beamVertexCount * 3);
for (int i = 0; i < beamVertexCount; i++) {
bufferBeamVertexID.put(i * 3, i);
Expand All @@ -146,6 +150,7 @@ private void init() {
.flip();
GL20.glUniform3(uProtomatterVertices, bufferBeamVertex);
GL20.glUniform1f(uCubeCount, particleCount);

ShaderProgram.clear();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

Expand All @@ -154,13 +159,16 @@ private void init() {
GoodGenerator.resourceDomain,
"shaders/glow.vert.glsl",
"shaders/glow.frag.glsl");
uGlowColor = glowProgram.getUniformLocation("u_Color");
glowProgram.use();
GL20.glUniform3f(uGlowColor, 0, 1f, 1f);

} catch (NullPointerException e) {
uGlowColor = glowProgram.getUniformLocation("u_Color");
} catch (Exception e) {
GTMod.GT_FML_LOGGER.error(e.getMessage());
return;
}

glowProgram.use();
GL20.glUniform3f(uGlowColor, 0, 1f, 1f);

ShaderProgram.clear();

initialized = true;
Expand Down Expand Up @@ -260,12 +268,17 @@ public void renderTileEntityAt(TileEntity tile, double x, double y, double z, fl

if (!Antimatter.shouldRender) return;

if (hasFailed) return;

if (!initialized) {
init();
if (!initialized) {
GTMod.GT_FML_LOGGER.error("Failed to properly initialize antimatter forge render");
hasFailed = true;
return;
}
}

float tx = (float) x + 0.5f;
float ty = (float) y + 0.5f;
float tz = (float) z + 0.5f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ float wave ( vec3 input){
const float PI = 3.14159265358979323846;


float lazyHash(vec3 input){
vec3 v = fract(input*1.23456 + 3.1456);
float lazyHash(vec3 toHash){
vec3 v = fract(toHash*1.23456 + 3.1456);
v*=7;
return fract(v.y + v.x*(v.z+1));
}
Expand Down

0 comments on commit cef96f0

Please sign in to comment.