-
Notifications
You must be signed in to change notification settings - Fork 27
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
1 parent
36923ce
commit bb57066
Showing
6 changed files
with
111 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package codechicken.multipart.client; | ||
|
||
import codechicken.lib.render.shader.CCShaderInstance; | ||
import com.mojang.blaze3d.vertex.DefaultVertexFormat; | ||
import net.covers1624.quack.util.CrashLock; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraftforge.client.event.RegisterShadersEvent; | ||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Objects; | ||
|
||
import static codechicken.multipart.CBMultipart.MOD_ID; | ||
|
||
/** | ||
* Created by covers1624 on 23/1/24. | ||
*/ | ||
public class Shaders { | ||
|
||
public static final CrashLock LOCK = new CrashLock("Already Initialised"); | ||
|
||
private static @Nullable CCShaderInstance highlightShader; | ||
|
||
public static void init() { | ||
LOCK.lock(); | ||
FMLJavaModLoadingContext.get().getModEventBus().addListener(Shaders::onRegisterShaders); | ||
} | ||
|
||
private static void onRegisterShaders(RegisterShadersEvent event) { | ||
event.registerShader( | ||
CCShaderInstance.create(event.getResourceProvider(), new ResourceLocation(MOD_ID, "highlight"), DefaultVertexFormat.BLOCK), | ||
e -> highlightShader = (CCShaderInstance) e | ||
); | ||
} | ||
|
||
public static CCShaderInstance highlightShader() { | ||
return Objects.requireNonNull(highlightShader, "Highlight shader not loaded yet."); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/main/resources/assets/cb_multipart/shaders/core/highlight.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,17 @@ | ||
#version 150 | ||
|
||
uniform sampler2D Sampler0; | ||
|
||
uniform vec4 ColorModulator; | ||
|
||
in vec4 vertexColor; | ||
in vec2 texCoord0; | ||
in vec2 texCoord2; | ||
in vec4 normal; | ||
|
||
out vec4 fragColor; | ||
|
||
void main() { | ||
vec4 color = texture(Sampler0, texCoord0) * vertexColor; | ||
fragColor = color * ColorModulator; | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/resources/assets/cb_multipart/shaders/core/highlight.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,24 @@ | ||
{ | ||
"blend": { | ||
"func": "add", | ||
"srcrgb": "srcalpha", | ||
"dstrgb": "1-srcalpha" | ||
}, | ||
"vertex": "cb_multipart:highlight", | ||
"fragment": "cb_multipart:highlight", | ||
"attributes": [ | ||
"Position", | ||
"Color", | ||
"UV0", | ||
"UV2", | ||
"Normal" | ||
], | ||
"samplers": [ | ||
{ "name": "Sampler0" } | ||
], | ||
"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 ] } | ||
] | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/resources/assets/cb_multipart/shaders/core/highlight.vsh
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,24 @@ | ||
#version 150 | ||
|
||
in vec3 Position; | ||
in vec4 Color; | ||
in vec2 UV0; | ||
in vec2 UV2; | ||
in vec3 Normal; | ||
|
||
uniform mat4 ModelViewMat; | ||
uniform mat4 ProjMat; | ||
|
||
out vec4 vertexColor; | ||
out vec2 texCoord0; | ||
out vec2 texCoord2; | ||
out vec4 normal; | ||
|
||
void main() { | ||
gl_Position = ProjMat * ModelViewMat * vec4(Position, 1.0); | ||
|
||
vertexColor = Color; | ||
texCoord0 = UV0; | ||
texCoord2 = UV2; | ||
normal = ProjMat * ModelViewMat * vec4(Normal, 0.0); | ||
} |