-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
185 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/client/java/org/ladysnake/effective/core/render/particle/SoftParticleRenderType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//package org.ladysnake.effective.core.render.particle; | ||
// | ||
//import com.mojang.blaze3d.systems.RenderSystem; | ||
//import net.minecraft.client.MinecraftClient; | ||
//import net.minecraft.client.particle.ParticleTextureSheet; | ||
//import net.minecraft.client.render.BufferBuilder; | ||
//import net.minecraft.client.render.Tessellator; | ||
//import net.minecraft.client.texture.SpriteAtlasTexture; | ||
//import net.minecraft.client.texture.TextureManager; | ||
//import org.jetbrains.annotations.NotNull; | ||
//import org.jetbrains.annotations.Nullable; | ||
// | ||
//public class SoftParticleRenderType implements ParticleTextureSheet { | ||
// @NotNull | ||
// public static final SoftParticleRenderType SOFT_PARTICLE = new SoftParticleRenderType(); | ||
// | ||
// @Override | ||
// public @Nullable BufferBuilder begin(Tessellator tessellator, TextureManager textureManager) { | ||
// final MinecraftClient minecraft = MinecraftClient.getInstance(); | ||
// | ||
// RenderSystem.setShader(() -> softParticle); | ||
// | ||
// // Disallow soft particles from writing to the depth buffer | ||
// RenderSystem.depthMask(false); | ||
// | ||
// // Set `Sampler0` to the particle atlas | ||
// // noinspection deprecation | ||
// RenderSystem.setShaderTexture(0, SpriteAtlasTexture.PARTICLE_ATLAS_TEXTURE); | ||
// | ||
// RenderSystem.enableBlend(); | ||
// RenderSystem.defaultBlendFunc(); | ||
// | ||
// // Set the sampler for the depth texture | ||
// softParticle.setSampler("DiffuseDepthSampler", minecraft.getMainRenderTarget().getDepthTextureId()); | ||
// | ||
// return tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE); | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/client/resources/assets/effective/shaders/core/soft_particle.fsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#version 150 | ||
|
||
#moj_import <fog.glsl> | ||
|
||
uniform sampler2D Sampler0; | ||
uniform sampler2D Sampler2; | ||
uniform sampler2D DiffuseDepthSampler; | ||
|
||
uniform mat4 ProjMat; | ||
uniform vec4 ColorModulator; | ||
uniform float FogStart; | ||
uniform float FogEnd; | ||
uniform vec4 FogColor; | ||
uniform vec2 ScreenSize; | ||
|
||
in float vertexDistance; | ||
in vec2 texCoord0; | ||
in vec4 vertexColor; | ||
|
||
out vec4 fragColor; | ||
|
||
const vec3 normal = vec3(0.0, 0.0, 1.0); | ||
|
||
float linearizeDepth(float depthSample) { | ||
// Same calculation mojang does, to linearize depths using the projection matrix values | ||
return -ProjMat[3].z / (depthSample * -2.0 + 1.0 - ProjMat[2].z); | ||
} | ||
|
||
void main() { | ||
vec4 color = texture(Sampler0, texCoord0) * vertexColor * ColorModulator; | ||
if (color.a < 0.001) { | ||
discard; | ||
} | ||
|
||
// Depth only occupies the red channel, we don't care about the other two | ||
float depthSample = texture(DiffuseDepthSampler, gl_FragCoord.xy / ScreenSize).r; | ||
|
||
float depth = linearizeDepth(depthSample); | ||
float particleDepth = linearizeDepth(gl_FragCoord.z); | ||
|
||
// Linearly blends from 1x to 0x opacity at 1+ meter depth difference to 0 depth difference | ||
float opacity = color.a * min(depth - particleDepth, 1.0); | ||
|
||
fragColor = linear_fog(vec4(color.rgb, opacity), vertexDistance, FogStart, FogEnd, FogColor); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/client/resources/assets/effective/shaders/core/soft_particle.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"vertex": "particle", | ||
"fragment": "effective:soft_particle", | ||
"samplers": [ | ||
{ "name": "Sampler0" }, | ||
{ "name": "Sampler2" }, | ||
{ "name": "DiffuseDepthSampler" } | ||
], | ||
"uniforms": [ | ||
{ "name": "ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] }, | ||
{ "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] }, | ||
{ "name": "ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] }, | ||
{ "name": "FogStart", "type": "float", "count": 1, "values": [ 0.0 ] }, | ||
{ "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] }, | ||
{ "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] }, | ||
{ "name": "FogShape", "type": "int", "count": 1, "values": [ 0 ] }, | ||
{ "name": "ScreenSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] } | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters