Skip to content

Commit ece96e3

Browse files
committed
And now fogubo...yea I'm just knocking these easy stuff for now.
1 parent 1ebf84a commit ece96e3

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

src/main/java/gg/generations/rarecandy/tools/gui/GuiPipelines.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ public class GuiPipelines {
8484
})
8585
.supplyUniform("Light0_Direction", uniformUploadContext -> uniformUploadContext.uniform().uploadVec3f(light0))
8686
.supplyUniform("Light1_Direction", uniformUploadContext -> uniformUploadContext.uniform().uploadVec3f(light1))
87-
.supplyUniform("dynamicVertexColor", ctx -> ctx.uniform().uploadBoolean(true))
88-
.supplyUniform("FogShape", ctx -> ctx.uniform().uploadInt(0)) //TODO: Make enum for fog shape. I think 0 is spherical and 1 cylinderical
89-
.supplyUniform("FogColor", ctx -> ctx.uniform().uploadVec4f(fogColor))
90-
.supplyUniform("FogStart", ctx -> ctx.uniform().uploadFloat(20.0f))
91-
.supplyUniform("FogEnd", ctx -> ctx.uniform().uploadFloat(20.0f))
9287
.supplyUniform("tera", ctx -> ctx.uniform().uploadBoolean(true))
9388
.supplyUniform("light", ctx -> {
9489
var light = (int) (RareCandyCanvas.getLightLevel() * 15);

src/main/java/gg/generations/rarecandy/tools/gui/RareCandyCanvas.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import gg.generations.rarecandy.renderer.model.GLModel;
1414
import gg.generations.rarecandy.renderer.rendering.*;
1515
import gg.generations.rarecandy.renderer.storage.AnimatedObjectInstance;
16+
import gg.generations.rarecandy.renderer.ubo.UniformBlockUploader;
1617
import gg.generations.rarecandy.tools.TextureLoader;
1718
import org.jetbrains.annotations.NotNull;
1819
import org.joml.Matrix4f;
@@ -21,6 +22,7 @@
2122
import org.lwjgl.opengl.GL11C;
2223
import org.lwjgl.opengl.awt.AWTGLCanvas;
2324
import org.lwjgl.opengl.awt.GLData;
25+
import org.lwjgl.system.MemoryUtil;
2426
import org.lwjgl.util.nfd.NativeFileDialog;
2527

2628
import javax.swing.*;
@@ -69,6 +71,7 @@ public class RareCandyCanvas extends AWTGLCanvas {
6971
public static boolean renderingFrame;
7072
private MultiRenderObject<MeshObject> cube;
7173
private ObjectInstance[] cubeInstances;
74+
private Fog fog;
7275

7376
public static void setLightLevel(float lightLevel) {
7477
previousLightLevel = RareCandyCanvas.lightLevel;
@@ -173,6 +176,9 @@ public void initGL() {
173176
GuiPipelines.onInitialize();
174177
this.renderer = new RareCandy();
175178

179+
fog = new Fog();
180+
fog.bind();
181+
176182
GL11C.glClearColor(0, 0, 0, 0);
177183
GL11C.glEnable(GL11C.GL_DEPTH_TEST);
178184

@@ -399,3 +405,18 @@ public <V extends RenderObject> void render(ObjectInstance instance) {
399405
}
400406
}
401407

408+
class Fog extends UniformBlockUploader {
409+
private final long pointer;
410+
public Fog() {
411+
super(Integer.BYTES + 5 * Float.BYTES, 2);
412+
this.pointer = MemoryUtil.nmemAlloc(Integer.BYTES + 5 * Float.BYTES);
413+
414+
GuiPipelines.fogColor.getToAddress(pointer);
415+
MemoryUtil.memPutFloat(pointer + 16, 0.0f);
416+
MemoryUtil.memPutFloat(pointer + 20, 5.0f);
417+
MemoryUtil.memPutInt(pointer + 24, 0);
418+
419+
upload(0, 24, pointer);
420+
}
421+
}
422+

src/main/resources/shaders/experimental/animated.fs.glsl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ out vec4 outColor;
99
uniform vec4 ColorModulator;
1010

1111
//fog
12-
uniform float FogStart;
13-
uniform float FogEnd;
14-
uniform vec4 FogColor;
12+
layout(std140, binding = 2) uniform Fog {
13+
vec4 FogColor;
14+
float FogStart;
15+
float FogEnd;
16+
int FogShape;
17+
};
18+
1519

1620
uniform sampler2D diffuse;
1721
uniform sampler2D mask;

src/main/resources/shaders/experimental/animated.vs.glsl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ out vec3 worldPos;
1818

1919
uniform bool dynamicVertexColor;
2020

21-
uniform int FogShape;
22-
2321
uniform mat4 viewMatrix;
2422
uniform mat4 projectionMatrix;
2523

@@ -29,6 +27,13 @@ uniform vec3 Light1_Direction;
2927
uniform vec2 uvOffset;
3028
uniform vec2 uvScale;
3129

30+
layout(std140, binding = 2) uniform Fog {
31+
vec4 FogColor;
32+
float FogStart;
33+
float FogEnd;
34+
int FogShape;
35+
};
36+
3237
layout(std140, binding = 1) uniform Instance {
3338
mat4 modelMatrix;
3439
mat4 boneTransforms[MAX_BONES];
@@ -54,8 +59,6 @@ float fog_distance(mat4 modelViewMat, vec3 pos, int shape) {
5459
}
5560

5661
vec4 getVertexColor() {
57-
if(dynamicVertexColor) return vec4(1);
58-
5962
vec3 lightDir0 = normalize(Light0_Direction);
6063
vec3 lightDir1 = normalize(Light1_Direction);
6164
float light0 = max(0.0, dot(Light0_Direction, inNormal));

0 commit comments

Comments
 (0)