forked from MinecraftForge/MinecraftForge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow mods to specify shader import namespace (MinecraftForge#9021)
- Loading branch information
1 parent
6d233ac
commit 82026d1
Showing
8 changed files
with
156 additions
and
0 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
77 changes: 77 additions & 0 deletions
77
src/test/java/net/minecraftforge/debug/client/rendering/ShaderResourcesTest.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,77 @@ | ||
/* | ||
* Copyright (c) Forge Development LLC and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.minecraftforge.debug.client.rendering; | ||
|
||
import java.io.IOException; | ||
|
||
import org.slf4j.Logger; | ||
|
||
import com.mojang.blaze3d.vertex.DefaultVertexFormat; | ||
import com.mojang.logging.LogUtils; | ||
|
||
import net.minecraft.client.renderer.ShaderInstance; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.client.event.RegisterShadersEvent; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fml.DistExecutor; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; | ||
import net.minecraftforge.fml.loading.FMLEnvironment; | ||
|
||
@Mod(ShaderResourcesTest.MODID) | ||
public class ShaderResourcesTest | ||
{ | ||
private static Logger LOGGER; | ||
|
||
public static final String MODID = "shader_resources_test"; | ||
private static final boolean ENABLE = false; | ||
|
||
public ShaderResourcesTest() | ||
{ | ||
if (ENABLE) | ||
{ | ||
LOGGER = LogUtils.getLogger(); | ||
|
||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT,() -> ClientInit::new); | ||
} | ||
} | ||
|
||
private class ClientInit | ||
{ | ||
public ClientInit() | ||
{ | ||
final var modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); | ||
|
||
modEventBus.addListener(ClientInit::registerShaders); | ||
} | ||
|
||
public static void registerShaders(final RegisterShadersEvent event) | ||
{ | ||
if (!ENABLE) | ||
return; | ||
|
||
try | ||
{ | ||
event.registerShader( | ||
new ShaderInstance( | ||
event.getResourceManager(), | ||
new ResourceLocation(MODID, "vertex_cubemap"), | ||
DefaultVertexFormat.POSITION), | ||
shader -> | ||
{ | ||
LOGGER.info("Completely loaded shader {} with no issues", shader.getName()); | ||
}); | ||
|
||
LOGGER.info("Loaded registered shaders with no exceptions"); | ||
} | ||
catch (IOException e) | ||
{ | ||
LOGGER.error("Failed to load shaders with exception", e); | ||
} | ||
} | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
src/test/resources/assets/shader_resources_test/shaders/core/vertex_cubemap.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,8 @@ | ||
#version 150 | ||
|
||
#moj_import <fog.glsl> | ||
#moj_import <shader_resources_test:cubemap_includes.glsl> | ||
|
||
void main() { | ||
fragColor = vec4(vertexPos, 0); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/test/resources/assets/shader_resources_test/shaders/core/vertex_cubemap.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,17 @@ | ||
{ | ||
"blend": { | ||
"func": "add", | ||
"srcrgb": "srcalpha", | ||
"dstrgb": "1-srcalpha" | ||
}, | ||
"vertex": "shader_resources_test:vertex_cubemap", | ||
"fragment": "shader_resources_test:vertex_cubemap", | ||
"attributes": [ | ||
], | ||
"samplers": [ | ||
], | ||
"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 ] } | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
src/test/resources/assets/shader_resources_test/shaders/core/vertex_cubemap.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,13 @@ | ||
#version 150 | ||
|
||
in vec3 Position; | ||
|
||
uniform mat4 ProjMat; | ||
uniform mat4 ModelViewMat; | ||
|
||
out vec3 vertexPos; | ||
|
||
void main() { | ||
gl_Position = ProjMat * ModelViewMat * vec4(Position, 1.0); | ||
vertexPos = Position; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/resources/assets/shader_resources_test/shaders/include/cubemap_includes.glsl
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,5 @@ | ||
#version 150 | ||
|
||
in vec3 vertexPos; | ||
|
||
out vec4 fragColor; |