Messing with shader.
This commit is contained in:
@@ -1,17 +1,13 @@
|
||||
package nl.requios.effortlessbuilding.helper;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDirt;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.renderer.*;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@@ -48,7 +44,6 @@ import org.lwjgl.util.Color;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -307,7 +302,9 @@ public class RenderHelper implements IWorldEventListener {
|
||||
SurvivalHelper.mayPlace(player.world, Block.getBlockFromItem(itemstack.getItem()), blockState, blockPos, true, EnumFacing.UP, player) &&
|
||||
SurvivalHelper.canReplace(player.world, player, blockPos)) {
|
||||
|
||||
ShaderHelper.useShader(ShaderHelper.psiBar, generateCallback(percentile, new Vec3d(blockPos), /*blockPos == firstPos ||*/ blockPos == secondPos));
|
||||
ShaderHelper.useShader(ShaderHelper.dissolve, generateShaderCallback(percentile,
|
||||
new Vec3d(blockPos), new Vec3d(firstPos), new Vec3d(secondPos),
|
||||
/*blockPos == firstPos ||*/ blockPos == secondPos));
|
||||
renderBlockPreview(dispatcher, blockPos, blockState);
|
||||
}
|
||||
}
|
||||
@@ -428,12 +425,14 @@ public class RenderHelper implements IWorldEventListener {
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
private static Consumer<Integer> generateCallback(final float percentile, final Vec3d blockpos, final boolean highlight) {
|
||||
private static Consumer<Integer> generateShaderCallback(final float percentile, final Vec3d blockpos, final Vec3d firstpos, final Vec3d secondpos, final boolean highlight) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
return (Integer shader) -> {
|
||||
int percentileUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "percentile");
|
||||
int highlightUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "highlight");
|
||||
int blockposUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "blockpos");
|
||||
int firstposUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "firstpos");
|
||||
int secondposUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "secondpos");
|
||||
int imageUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "image");
|
||||
int maskUniform = ARBShaderObjects.glGetUniformLocationARB(shader, "mask");
|
||||
|
||||
@@ -454,6 +453,8 @@ public class RenderHelper implements IWorldEventListener {
|
||||
|
||||
//blockpos
|
||||
ARBShaderObjects.glUniform3fARB(blockposUniform, (float) blockpos.x, (float) blockpos.y, (float) blockpos.z);
|
||||
ARBShaderObjects.glUniform3fARB(firstposUniform, (float) firstpos.x, (float) firstpos.y, (float) firstpos.z);
|
||||
ARBShaderObjects.glUniform3fARB(secondposUniform, (float) secondpos.x, (float) secondpos.y, (float) secondpos.z);
|
||||
|
||||
//percentile
|
||||
ARBShaderObjects.glUniform1fARB(percentileUniform, percentile);
|
||||
|
||||
@@ -12,19 +12,21 @@
|
||||
*/
|
||||
package nl.requios.effortlessbuilding.helper;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GLAllocation;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import nl.requios.effortlessbuilding.BuildConfig;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.proxy.ClientProxy;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.lwjgl.opengl.ARBFragmentShader;
|
||||
import org.lwjgl.opengl.ARBShaderObjects;
|
||||
import org.lwjgl.opengl.ARBVertexShader;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.*;
|
||||
import org.lwjgl.util.vector.Matrix4f;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -39,15 +41,18 @@ public final class ShaderHelper {
|
||||
private static final String VERT_EXTENSION = ".vert";
|
||||
private static final String FRAG_EXTENSION = ".frag";
|
||||
|
||||
// public static final FloatBuffer projection = GLAllocation.createDirectFloatBuffer(16);
|
||||
// public static final FloatBuffer modelview = GLAllocation.createDirectFloatBuffer(16);
|
||||
|
||||
public static int rawColor;
|
||||
public static int psiBar;
|
||||
public static int dissolve;
|
||||
|
||||
public static void init() {
|
||||
if(!doUseShaders())
|
||||
return;
|
||||
|
||||
rawColor = createProgram("/assets/effortlessbuilding/shaders/raw_color", FRAG);
|
||||
psiBar = createProgram("/assets/effortlessbuilding/shaders/dissolve", FRAG);
|
||||
dissolve = createProgram("/assets/effortlessbuilding/shaders/dissolve", FRAG);
|
||||
}
|
||||
|
||||
public static void useShader(int shader, Consumer<Integer> callback) {
|
||||
@@ -60,6 +65,17 @@ public final class ShaderHelper {
|
||||
int time = ARBShaderObjects.glGetUniformLocationARB(shader, "time");
|
||||
ARBShaderObjects.glUniform1iARB(time, ClientProxy.ticksInGame);
|
||||
|
||||
// GlStateManager.getFloat(GL11.GL_PROJECTION_MATRIX, projection);
|
||||
// GlStateManager.getFloat(GL11.GL_MODELVIEW_MATRIX, modelview);
|
||||
|
||||
// int inverse_view_proj = ARBShaderObjects.glGetUniformLocationARB(shader, "inverse_view_proj");
|
||||
int screen_width = ARBShaderObjects.glGetUniformLocationARB(shader, "screen_width");
|
||||
int screen_height = ARBShaderObjects.glGetUniformLocationARB(shader, "screen_height");
|
||||
|
||||
// ARBShaderObjects.glUniformMatrix4ARB(inverse_view_proj, true, modelview);
|
||||
ARBShaderObjects.glUniform1fARB(screen_width, Minecraft.getMinecraft().displayWidth);
|
||||
ARBShaderObjects.glUniform1fARB(screen_height, Minecraft.getMinecraft().displayHeight);
|
||||
|
||||
if(callback != null)
|
||||
callback.accept(shader);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,24 @@
|
||||
#version 120
|
||||
|
||||
uniform mat4 gl_ProjectionMatrix;
|
||||
uniform mat4 gl_ModelViewMatrix;
|
||||
|
||||
//uniform mat4 inverse_view_proj;
|
||||
uniform float screen_width;
|
||||
uniform float screen_height;
|
||||
|
||||
uniform int time; // Passed in, see ShaderHelper.java
|
||||
|
||||
uniform float percentile; // Passed in via Callback
|
||||
uniform int highlight;
|
||||
uniform vec3 blockpos;
|
||||
uniform vec3 firstpos;
|
||||
uniform vec3 secondpos;
|
||||
uniform sampler2D image;
|
||||
uniform sampler2D mask;
|
||||
|
||||
varying vec4 position;
|
||||
|
||||
// Simplex 3D Noise
|
||||
// by Ian McEwan, Ashima Arts
|
||||
//
|
||||
@@ -82,7 +94,26 @@ float snoise(vec3 v){
|
||||
dot(p2,x2), dot(p3,x3) ) );
|
||||
}
|
||||
|
||||
vec3 getWorldPosition() {
|
||||
// Convert screen coordinates to normalized device coordinates (NDC)
|
||||
vec4 ndc = vec4(
|
||||
(gl_FragCoord.x / screen_width - 0.5) * 2.0,
|
||||
(gl_FragCoord.y / screen_height - 0.5) * 2.0,
|
||||
(gl_FragCoord.z - 0.5) * 2.0,
|
||||
1.0);
|
||||
|
||||
// Convert NDC throuch inverse clip coordinates to view coordinates
|
||||
vec4 clip = transpose(gl_ModelViewMatrix) * ndc;
|
||||
vec3 vertex = (clip / clip.w).xyz;
|
||||
return vertex;
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
vec3 worldpos = getWorldPosition();
|
||||
|
||||
float noise = worldpos.x / 300.0;//snoise(worldpos);
|
||||
|
||||
vec2 texcoord = vec2(gl_TexCoord[0]);
|
||||
vec4 color = texture2D(image, texcoord);
|
||||
|
||||
@@ -90,44 +121,34 @@ void main() {
|
||||
vec2 maskcoord = texcoord + vec2(relBlockPos.x + relBlockPos.y, relBlockPos.z + relBlockPos.y);
|
||||
vec4 maskColor = texture2D(mask, maskcoord);
|
||||
float maskgs = maskColor.r;
|
||||
//maskgs = snoise(blockpos / 32.0 + );
|
||||
maskgs = noise;
|
||||
|
||||
float r = color.r * gl_Color.r;
|
||||
float g = color.g * gl_Color.g;
|
||||
float b = color.b * gl_Color.b;
|
||||
float a = color.a; // Ignore gl_Color.a as we don't want to make use of that for the dissolve effect
|
||||
|
||||
r -= 0.1;
|
||||
g += 0.0;
|
||||
b += 0.1;
|
||||
r = noise;
|
||||
g = noise;
|
||||
b = noise;
|
||||
|
||||
float pulse = (sin(time / 5.0) + 1.0) / 2.0;
|
||||
pulse = 1.0;//pulse / 2.0 + 0.5;
|
||||
vec4 pulseColor = texture2D(mask, maskcoord + time / 400.0);
|
||||
vec4 pulseColor2 = texture2D(mask, vec2(maskcoord.x - time / 400.0, maskcoord.y - time / 400.0));
|
||||
float pulseGreyScale = pulseColor.r + pulseColor2.r / 2.0;
|
||||
|
||||
r -= r * pulseColor.r * pulse * 0.2;
|
||||
g += (1.0 - g) * pulseColor.r * pulse * 0.2;
|
||||
b += (1.0 - b) * pulseColor.r * pulse * 0.8;
|
||||
|
||||
r -= r * pulseColor2.r * pulse * 0.4;
|
||||
g += (1.0 - g) * pulseColor2.r * pulse * 0.2;
|
||||
b += (1.0 - b) * pulseColor2.r * pulse;
|
||||
|
||||
// float exr1 = sin(texcoord.x * 2 + texcoord.y * 10 + time * 0.035);
|
||||
// float exr2 = sin(texcoord.x * 20 + texcoord.y * 2 + time * 0.15);
|
||||
// float exr3 = sin(texcoord.x * 1 + texcoord.y * 90 + time * 0.75);
|
||||
|
||||
// float w1 = (cos(time * 0.1) + 1) * 0.5;
|
||||
// float w2 = (sin(time * 0.08) + 1) * 0.5;
|
||||
// float w3 = (cos(time * 0.001) + 1) * 0.5;
|
||||
|
||||
// float w = w1 + w2 + w3;
|
||||
// float exr = (exr1 * w1 + exr2 * w2 + exr3 * w3) / w * 0.1;
|
||||
|
||||
// r += exr;
|
||||
// g -= exr;
|
||||
// r -= 0.1;
|
||||
// g += 0.0;
|
||||
// b += 0.1;
|
||||
//
|
||||
// float pulse = (sin(time / 5.0) + 1.0) / 2.0;
|
||||
// pulse = 1.0;//pulse / 2.0 + 0.5;
|
||||
// vec4 pulseColor = texture2D(mask, maskcoord + time / 700.0);
|
||||
// vec4 pulseColor2 = texture2D(mask, vec2(maskcoord.x + time / 600.0, maskcoord.y - time / 600.0));
|
||||
// float pulseGreyScale = pulseColor.r + pulseColor2.r / 2.0;
|
||||
//
|
||||
// r -= r * pulseColor.r * pulse * 0.2;
|
||||
// g += (1.0 - g) * pulseColor.r * pulse * 0.2;
|
||||
// b += (1.0 - b) * pulseColor.r * pulse * 0.8;
|
||||
//
|
||||
// r -= r * pulseColor2.r * pulse * 0.4;
|
||||
// g += (1.0 - g) * pulseColor2.r * pulse * 0.2;
|
||||
// b += (1.0 - b) * pulseColor2.r * pulse;
|
||||
|
||||
if(highlight == 1) {
|
||||
r += 0.0;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#version 120
|
||||
|
||||
uniform int time; // Passed in, see ShaderHelper.java
|
||||
|
||||
uniform float percentile; // Passed in via Callback
|
||||
uniform int highlight;
|
||||
uniform vec3 blockpos;
|
||||
uniform vec3 firstpos;
|
||||
uniform vec3 secondpos;
|
||||
uniform sampler2D image;
|
||||
uniform sampler2D mask;
|
||||
|
||||
varying vec4 position;
|
||||
|
||||
void main() {
|
||||
gl_Position = ftransform();//gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0 + 0.01;
|
||||
|
||||
position = gl_Vertex;
|
||||
}
|
||||
Reference in New Issue
Block a user