1717import java .nio .file .Files ;
1818import java .nio .file .Path ;
1919import java .nio .file .Paths ;
20- import java .util .HashSet ;
21- import java .util .Map ;
2220import java .util .Set ;
2321
2422public abstract class ShaderLoadUtil {
2523
26- private static final String RESOURCES_PATH = SPIRVUtils .class .getResource ("/assets/vulkanmod" ).toExternalForm ();
24+ public static final String RESOURCES_PATH = SPIRVUtils .class .getResource ("/assets/vulkanmod" ).toExternalForm ();
25+ public static final String SHADERS_PATH = "%s/shaders/" .formatted (RESOURCES_PATH );
2726
2827 public static final Set <String > REMAPPED_SHADERS = Sets .newHashSet ("core/screenquad.vsh" ,"core/rendertype_item_entity_translucent_cull.vsh" );
2928
29+ public static String resolveShaderPath (String path ) {
30+ return resolveShaderPath (SHADERS_PATH , path );
31+ }
32+
33+ public static String resolveShaderPath (String shaderPath , String path ) {
34+ return "%s%s" .formatted (shaderPath , path );
35+ }
36+
3037 public static void loadShaders (Pipeline .Builder pipelineBuilder , JsonObject config , String configName , String path ) {
3138 String vertexShader = config .has ("vertex" ) ? config .get ("vertex" ).getAsString () : configName ;
3239 String fragmentShader = config .has ("fragment" ) ? config .get ("fragment" ).getAsString () : configName ;
3340
41+ if (vertexShader == null ) {
42+ vertexShader = configName ;
43+ }
44+ if (fragmentShader == null ) {
45+ fragmentShader = configName ;
46+ }
47+
3448 vertexShader = removeNameSpace (vertexShader );
3549 fragmentShader = removeNameSpace (fragmentShader );
3650
@@ -50,9 +64,7 @@ public static void loadShader(Pipeline.Builder pipelineBuilder, String configNam
5064 }
5165
5266 public static void loadShader (Pipeline .Builder pipelineBuilder , String configName , String path , String shaderName , SPIRVUtils .ShaderKind type ) {
53- String basePath = "%s/shaders/%s" .formatted (RESOURCES_PATH , path );
54-
55- String source = getShaderSource (basePath , configName , shaderName , type );
67+ String source = getShaderSource (path , configName , shaderName , type );
5668
5769 SPIRVUtils .SPIRV spirv = SPIRVUtils .compileShader (shaderName , source , type );
5870
@@ -91,7 +103,7 @@ public static JsonObject getJsonConfig(String path, String rendertype) {
91103 return null ;
92104 }
93105
94- String basePath = "%s/shaders/%s" . formatted ( RESOURCES_PATH , path ) ;
106+ String basePath = path ;
95107 String configPath = "%s/%s/%s.json" .formatted (basePath , rendertype , rendertype );
96108
97109 InputStream stream ;
@@ -168,22 +180,31 @@ public static String getShaderSource(String path, ShaderType type) {
168180 }
169181 }
170182
171- public static String getShaderSource (String basePath , String rendertype , String shaderName , SPIRVUtils .ShaderKind type ) {
183+ public static String getShaderSource (String path , String configName , String shaderName , SPIRVUtils .ShaderKind type ) {
172184 String shaderExtension = switch (type ) {
173185 case VERTEX_SHADER -> ".vsh" ;
174186 case FRAGMENT_SHADER -> ".fsh" ;
187+ case COMPUTE_SHADER -> ".comp" ;
175188 default -> throw new UnsupportedOperationException ("shader type %s unsupported" );
176189 };
177190
178- String shaderPath = "/%s/%s" .formatted (rendertype , rendertype );
191+ String basePath = path ;
192+
193+ String shaderPath = "/%s/%s" .formatted (configName , configName );
179194 String shaderFile = "%s%s%s" .formatted (basePath , shaderPath , shaderExtension );
180195
181196 InputStream stream ;
182197 try {
183198 stream = getInputStream (shaderFile );
184199
185200 if (stream == null ) {
186- shaderPath = "/%s/%s" .formatted (rendertype , shaderName );
201+ shaderPath = "/%s" .formatted (shaderName );
202+ shaderFile = "%s%s%s" .formatted (basePath , shaderPath , shaderExtension );
203+ stream = getInputStream (shaderFile );
204+ }
205+
206+ if (stream == null ) {
207+ shaderPath = "/%s/%s" .formatted (configName , shaderName );
187208 shaderFile = "%s%s%s" .formatted (basePath , shaderPath , shaderExtension );
188209 stream = getInputStream (shaderFile );
189210 }
0 commit comments