More tweaking

- FLWFinalizeColor takes care of assigning gl_FragColor
 - Multiply crumbling alpha with diffuse alpha
This commit is contained in:
JozsefA 2021-05-08 23:29:02 -07:00
parent 4111680755
commit 70401e4ac4
13 changed files with 42 additions and 17 deletions

View File

@ -1,9 +1,10 @@
package com.jozufozu.flywheel.backend;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL11.glBindTexture;
import static org.lwjgl.opengl.GL13.GL_TEXTURE0;
import static org.lwjgl.opengl.GL13.glActiveTexture;
import static org.lwjgl.opengl.GL20.GL_TEXTURE0;
import static org.lwjgl.opengl.GL20.GL_TEXTURE4;
import static org.lwjgl.opengl.GL20.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL20.glActiveTexture;
import static org.lwjgl.opengl.GL20.glBindTexture;
import java.util.BitSet;
import java.util.Collection;
@ -44,6 +45,7 @@ import net.minecraft.client.renderer.texture.Texture;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.inventory.container.PlayerContainer;
import net.minecraft.resources.IReloadableResourceManager;
import net.minecraft.resources.IResourceManager;
import net.minecraft.tileentity.TileEntity;
@ -246,6 +248,9 @@ public class Backend {
ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureManager.getTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE).getGlTextureId());
glActiveTexture(GL_TEXTURE4);
CRUMBLING.startDrawing();
bitSet.stream().forEach(i -> {
@ -261,6 +266,11 @@ public class Backend {
renderer.invalidate();
});
CRUMBLING.endDrawing();
glActiveTexture(GL_TEXTURE0);
Texture breaking = textureManager.getTexture(ModelBakery.BLOCK_DESTRUCTION_STAGE_TEXTURES.get(0));
if (breaking != null)
glBindTexture(GL_TEXTURE_2D, breaking.getGlTextureId());
}
public static void enqueueUpdate(TileEntity te) {

View File

@ -12,7 +12,7 @@ public class ContraptionContext extends WorldContext<ContraptionProgram> {
public static final ContraptionContext INSTANCE = new ContraptionContext();
public ContraptionContext() {
super(new ResourceLocation("create", "contraption"), new FogSensitiveProgram.SpecLoader<>(ContraptionProgram::new));
super(new ResourceLocation("create", "context/contraption"), new FogSensitiveProgram.SpecLoader<>(ContraptionProgram::new));
}
@Override

View File

@ -8,6 +8,7 @@ import net.minecraft.util.ResourceLocation;
public class CrumblingProgram extends BasicProgram {
protected final int uTextureScale;
protected int uCrumbling;
public CrumblingProgram(ResourceLocation name, int handle, ProgramFogMode.Factory fogFactory) {
super(name, handle, fogFactory);
@ -15,6 +16,12 @@ public class CrumblingProgram extends BasicProgram {
uTextureScale = getUniformLocation("uTextureScale");
}
@Override
protected void registerSamplers() {
super.registerSamplers();
uCrumbling = setSamplerBinding("uCrumbling", 4);
}
public void setTextureScale(float x, float y) {
glUniform2f(uTextureScale, x, y);
}

View File

@ -22,8 +22,8 @@ public class WorldContext<P extends BasicProgram> extends ShaderContext<P> {
private static final String declaration = "#flwbuiltins";
private static final Pattern builtinPattern = Pattern.compile(declaration);
public static final WorldContext<BasicProgram> INSTANCE = new WorldContext<>(new ResourceLocation("create", "std"), new FogSensitiveProgram.SpecLoader<>(BasicProgram::new));
public static final WorldContext<CrumblingProgram> CRUMBLING = new WorldContext<>(new ResourceLocation("create", "crumbling"), new FogSensitiveProgram.SpecLoader<>(CrumblingProgram::new));
public static final WorldContext<BasicProgram> INSTANCE = new WorldContext<>(new ResourceLocation("create", "context/std"), new FogSensitiveProgram.SpecLoader<>(BasicProgram::new));
public static final WorldContext<CrumblingProgram> CRUMBLING = new WorldContext<>(new ResourceLocation("create", "context/crumbling"), new FogSensitiveProgram.SpecLoader<>(CrumblingProgram::new));
private final ShaderSpecLoader<P> loader;

View File

@ -13,6 +13,4 @@ void main() {
vec4 color = vec4(tex.rgb * FLWLight(Light).rgb * Diffuse, tex.a) * Color;
FLWFinalizeColor(color);
gl_FragColor = color;
}

View File

@ -1,4 +1,4 @@
#flwinclude <"create:std/fog.glsl">
#flwinclude <"create:context/std/fog.glsl">
varying vec3 BoxCoord;
uniform sampler3D uLightVolume;
@ -10,7 +10,7 @@ vec4 FLWBlockTexture(vec2 texCoords) {
return texture2D(uBlockAtlas, texCoords);
}
void FLWFinalizeColor(inout vec4 color) {
void FLWFinalizeColor(vec4 color) {
#if defined(USE_FOG)
float a = color.a;
float fog = clamp(FLWFogFactor(), 0., 1.);
@ -18,6 +18,8 @@ void FLWFinalizeColor(inout vec4 color) {
color = mix(uFogColor, color, fog);
color.a = a;
#endif
gl_FragColor = color;
}
vec4 FLWLight(vec2 lightCoords) {

View File

@ -1,14 +1,18 @@
#flwinclude <"create:std/fog.glsl">
#flwinclude <"create:context/std/fog.glsl">
uniform vec2 uTextureScale;
uniform sampler2D uBlockAtlas;
uniform sampler2D uLightMap;
uniform sampler2D uCrumbling;
vec4 FLWBlockTexture(vec2 texCoords) {
return texture2D(uBlockAtlas, texCoords * uTextureScale);
vec4 cr = texture2D(uCrumbling, texCoords * uTextureScale);
float diffuseAlpha = texture2D(uBlockAtlas, texCoords).a;
cr.a = cr.a * diffuseAlpha;
return cr;
}
void FLWFinalizeColor(inout vec4 color) {
void FLWFinalizeColor(vec4 color) {
#if defined(USE_FOG)
float a = color.a;
float fog = clamp(FLWFogFactor(), 0., 1.);
@ -16,6 +20,8 @@ void FLWFinalizeColor(inout vec4 color) {
color = mix(uFogColor, color, fog);
color.a = a;
#endif
gl_FragColor = color;
}
vec4 FLWLight(vec2 lightCoords) {

View File

@ -0,0 +1 @@
#flwinclude <"create:context/std/builtin.vert">

View File

@ -1,4 +1,4 @@
#flwinclude <"create:std/fog.glsl">
#flwinclude <"create:context/std/fog.glsl">
uniform sampler2D uBlockAtlas;
uniform sampler2D uLightMap;
@ -7,7 +7,7 @@ vec4 FLWBlockTexture(vec2 texCoords) {
return texture2D(uBlockAtlas, texCoords);
}
void FLWFinalizeColor(inout vec4 color) {
void FLWFinalizeColor(vec4 color) {
#if defined(USE_FOG)
float a = color.a;
float fog = clamp(FLWFogFactor(), 0., 1.);
@ -15,6 +15,8 @@ void FLWFinalizeColor(inout vec4 color) {
color = mix(uFogColor, color, fog);
color.a = a;
#endif
gl_FragColor = color;
}
vec4 FLWLight(vec2 lightCoords) {

View File

@ -1 +0,0 @@
#flwinclude <"create:std/builtin.vert">