mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-14 14:34:16 +01:00
Step towards arbitrary shader contexts
This commit is contained in:
parent
15f4cd305e
commit
35768b5ade
@ -46,6 +46,7 @@ public class ShaderLoader {
|
||||
|
||||
// #flwinclude <"valid_namespace:valid/path_to_file.glsl">
|
||||
private static final Pattern includePattern = Pattern.compile("#flwinclude <\"([\\w\\d_]+:[\\w\\d_./]+)\">");
|
||||
private static boolean debugDumpFile = false;
|
||||
|
||||
final Map<ResourceLocation, String> shaderSource = new HashMap<>();
|
||||
|
||||
@ -162,6 +163,13 @@ public class ShaderLoader {
|
||||
if (defines != null)
|
||||
source = defines.process(source);
|
||||
|
||||
if (debugDumpFile) {
|
||||
Backend.log.debug("Finished processing '" + name + "':");
|
||||
int i = 1;
|
||||
for (String s : source.split("\n")) {
|
||||
Backend.log.debug(String.format("%1$4s: ", i++) + s);
|
||||
}
|
||||
}
|
||||
|
||||
return new GlShader(type, name, source);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class AllProgramSpecs {
|
||||
.addAttributes(BasicAttributes.class)
|
||||
.addAttributes(TransformAttributes.class)
|
||||
.setVert(Locations.MODEL_VERT)
|
||||
.setFrag(Locations.MODEL_FRAG)
|
||||
.setFrag(Locations.BLOCK)
|
||||
.createProgramSpec());
|
||||
|
||||
public static final ProgramSpec<BasicProgram> ORIENTED = register(ProgramSpec.builder("oriented", new FogSensitiveProgram.SpecLoader<>(BasicProgram::new))
|
||||
@ -49,7 +49,7 @@ public class AllProgramSpecs {
|
||||
.addAttributes(BasicAttributes.class)
|
||||
.addAttributes(OrientedAttributes.class)
|
||||
.setVert(Locations.ORIENTED)
|
||||
.setFrag(Locations.MODEL_FRAG)
|
||||
.setFrag(Locations.BLOCK)
|
||||
.createProgramSpec());
|
||||
|
||||
public static final ProgramSpec<BasicProgram> ROTATING = register(ProgramSpec.builder("rotating", new FogSensitiveProgram.SpecLoader<>(BasicProgram::new))
|
||||
@ -58,7 +58,7 @@ public class AllProgramSpecs {
|
||||
.addAttributes(KineticAttributes.class)
|
||||
.addAttributes(RotatingAttributes.class)
|
||||
.setVert(Locations.ROTATING)
|
||||
.setFrag(Locations.MODEL_FRAG)
|
||||
.setFrag(Locations.BLOCK)
|
||||
.createProgramSpec());
|
||||
|
||||
public static final ProgramSpec<BasicProgram> BELT = register(ProgramSpec.builder("belt", new FogSensitiveProgram.SpecLoader<>(BasicProgram::new))
|
||||
@ -67,26 +67,27 @@ public class AllProgramSpecs {
|
||||
.addAttributes(KineticAttributes.class)
|
||||
.addAttributes(BeltAttributes.class)
|
||||
.setVert(Locations.BELT)
|
||||
.setFrag(Locations.MODEL_FRAG)
|
||||
.setFrag(Locations.BLOCK)
|
||||
.createProgramSpec());
|
||||
|
||||
public static final ProgramSpec<BasicProgram> FLAPS = register(ProgramSpec.builder("flap", new FogSensitiveProgram.SpecLoader<>(BasicProgram::new))
|
||||
.addAttributes(ModelAttributes.class)
|
||||
.addAttributes(FlapAttributes.class)
|
||||
.setVert(Locations.FLAP)
|
||||
.setFrag(Locations.MODEL_FRAG)
|
||||
.setFrag(Locations.BLOCK)
|
||||
.createProgramSpec());
|
||||
public static final ProgramSpec<ContraptionProgram> C_STRUCTURE = register(ProgramSpec.builder("contraption_structure", new FogSensitiveProgram.SpecLoader<>(ContraptionProgram::new))
|
||||
.addAttributes(ContraptionAttributes.class)
|
||||
.setVert(Locations.CONTRAPTION_STRUCTURE)
|
||||
.setFrag(Locations.CONTRAPTION)
|
||||
.setFrag(Locations.BLOCK)
|
||||
.setDefines(ShaderConstants.define("CONTRAPTION"))
|
||||
.createProgramSpec());
|
||||
public static final ProgramSpec<ContraptionProgram> C_MODEL = register(ProgramSpec.builder("contraption_model", new FogSensitiveProgram.SpecLoader<>(ContraptionProgram::new))
|
||||
.addAttributes(ModelAttributes.class)
|
||||
.addAttributes(BasicAttributes.class)
|
||||
.addAttributes(TransformAttributes.class)
|
||||
.setVert(Locations.MODEL_VERT)
|
||||
.setFrag(Locations.CONTRAPTION)
|
||||
.setFrag(Locations.BLOCK)
|
||||
.setDefines(ShaderConstants.define("CONTRAPTION"))
|
||||
.createProgramSpec());
|
||||
public static final ProgramSpec<ContraptionProgram> C_ORIENTED = register(ProgramSpec.builder("contraption_oriented", new FogSensitiveProgram.SpecLoader<>(ContraptionProgram::new))
|
||||
@ -94,7 +95,7 @@ public class AllProgramSpecs {
|
||||
.addAttributes(BasicAttributes.class)
|
||||
.addAttributes(OrientedAttributes.class)
|
||||
.setVert(Locations.ORIENTED)
|
||||
.setFrag(Locations.CONTRAPTION)
|
||||
.setFrag(Locations.BLOCK)
|
||||
.setDefines(ShaderConstants.define("CONTRAPTION"))
|
||||
.createProgramSpec());
|
||||
public static final ProgramSpec<ContraptionProgram> C_ROTATING = register(ProgramSpec.builder("contraption_rotating", new FogSensitiveProgram.SpecLoader<>(ContraptionProgram::new))
|
||||
@ -103,7 +104,7 @@ public class AllProgramSpecs {
|
||||
.addAttributes(KineticAttributes.class)
|
||||
.addAttributes(RotatingAttributes.class)
|
||||
.setVert(Locations.ROTATING)
|
||||
.setFrag(Locations.CONTRAPTION)
|
||||
.setFrag(Locations.BLOCK)
|
||||
.setDefines(ShaderConstants.define("CONTRAPTION"))
|
||||
.createProgramSpec());
|
||||
public static final ProgramSpec<ContraptionProgram> C_BELT = register(ProgramSpec.builder("contraption_belt", new FogSensitiveProgram.SpecLoader<>(ContraptionProgram::new))
|
||||
@ -112,31 +113,30 @@ public class AllProgramSpecs {
|
||||
.addAttributes(KineticAttributes.class)
|
||||
.addAttributes(BeltAttributes.class)
|
||||
.setVert(Locations.BELT)
|
||||
.setFrag(Locations.CONTRAPTION)
|
||||
.setFrag(Locations.BLOCK)
|
||||
.setDefines(ShaderConstants.define("CONTRAPTION"))
|
||||
.createProgramSpec());
|
||||
public static final ProgramSpec<ContraptionProgram> C_FLAPS = register(ProgramSpec.builder("contraption_flap", new FogSensitiveProgram.SpecLoader<>(ContraptionProgram::new))
|
||||
.addAttributes(ModelAttributes.class)
|
||||
.addAttributes(FlapAttributes.class)
|
||||
.setVert(Locations.FLAP)
|
||||
.setFrag(Locations.CONTRAPTION)
|
||||
.setFrag(Locations.BLOCK)
|
||||
.setDefines(ShaderConstants.define("CONTRAPTION"))
|
||||
.createProgramSpec());
|
||||
public static final ProgramSpec<ContraptionProgram> C_ACTOR = register(ProgramSpec.builder("contraption_actor", new FogSensitiveProgram.SpecLoader<>(ContraptionProgram::new))
|
||||
.addAttributes(ModelAttributes.class)
|
||||
.addAttributes(ActorVertexAttributes.class)
|
||||
.setVert(Locations.CONTRAPTION_ACTOR)
|
||||
.setFrag(Locations.CONTRAPTION)
|
||||
.setFrag(Locations.BLOCK)
|
||||
.setDefines(ShaderConstants.define("CONTRAPTION"))
|
||||
.createProgramSpec());
|
||||
|
||||
|
||||
public static class Locations {
|
||||
public static final ResourceLocation EFFECT_VERT = loc("area_effect.vert");
|
||||
public static final ResourceLocation EFFECT_FRAG = loc("area_effect.frag");
|
||||
public static final ResourceLocation MODEL_FRAG = loc("model.frag");
|
||||
public static final ResourceLocation BLOCK = loc("block.frag");
|
||||
|
||||
public static final ResourceLocation MODEL_VERT = loc("model.vert");
|
||||
public static final ResourceLocation ORIENTED = loc("oriented.vert");
|
||||
public static final ResourceLocation CONTRAPTION = loc("contraption.frag");
|
||||
|
||||
public static final ResourceLocation ROTATING = loc("rotating.vert");
|
||||
public static final ResourceLocation BELT = loc("belt.vert");
|
||||
@ -144,6 +144,8 @@ public class AllProgramSpecs {
|
||||
public static final ResourceLocation CONTRAPTION_STRUCTURE = loc("contraption_structure.vert");
|
||||
public static final ResourceLocation CONTRAPTION_ACTOR = loc("contraption_actor.vert");
|
||||
|
||||
public static final ResourceLocation EFFECT_VERT = loc("area_effect.vert");
|
||||
public static final ResourceLocation EFFECT_FRAG = loc("area_effect.frag");
|
||||
|
||||
private static ResourceLocation loc(String name) {
|
||||
return new ResourceLocation(Create.ID, name);
|
||||
|
@ -35,9 +35,9 @@ varying float FragDistance;
|
||||
#endif
|
||||
|
||||
#ifdef CONTRAPTION
|
||||
#flwinclude <"create:contraption/finalize.glsl">
|
||||
#flwinclude <"create:contraption/builtin.vert">
|
||||
#else
|
||||
#flwinclude <"create:std/finalize.glsl">
|
||||
#flwinclude <"create:std/builtin.vert">
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
|
@ -28,19 +28,20 @@ float fogFactor() {
|
||||
float dist = FragDistance * uFogDensity;
|
||||
return 1. / exp2(dist * dist);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
vec4 light() {
|
||||
vec2 lm = Light * 0.9375 + 0.03125;
|
||||
return texture2D(uLightMap, lm);
|
||||
}
|
||||
#ifdef CONTRAPTION
|
||||
#flwinclude <"create:contraption/builtin.frag">
|
||||
#else
|
||||
#flwinclude <"create:std/builtin.frag">
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
vec4 tex = texture2D(uBlockAtlas, TexCoords);
|
||||
|
||||
vec4 color = vec4(tex.rgb * light().rgb * Diffuse, tex.a) * Color;
|
||||
vec4 color = vec4(tex.rgb * FLWLight(Light, uLightMap).rgb * Diffuse, tex.a) * Color;
|
||||
|
||||
#if defined(USE_FOG)
|
||||
#if defined(USE_FOG)
|
||||
float fog = clamp(fogFactor(), 0., 1.);
|
||||
|
||||
gl_FragColor = mix(uFogColor, color, fog);
|
@ -1,54 +0,0 @@
|
||||
#version 110
|
||||
|
||||
varying vec2 TexCoords;
|
||||
varying vec4 Color;
|
||||
varying float Diffuse;
|
||||
varying vec2 Light;
|
||||
|
||||
varying vec3 BoxCoord;
|
||||
|
||||
uniform sampler2D uBlockAtlas;
|
||||
uniform sampler2D uLightMap;
|
||||
uniform sampler3D uLightVolume;
|
||||
|
||||
#if defined(USE_FOG)
|
||||
varying float FragDistance;
|
||||
uniform vec4 uFogColor;
|
||||
#endif
|
||||
|
||||
#if defined(USE_FOG_LINEAR)
|
||||
uniform vec2 uFogRange;
|
||||
|
||||
float fogFactor() {
|
||||
return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_FOG_EXP2
|
||||
uniform float uFogDensity;
|
||||
|
||||
float fogFactor() {
|
||||
float dist = FragDistance * uFogDensity;
|
||||
return 1. / exp2(dist * dist);
|
||||
}
|
||||
#endif
|
||||
|
||||
vec4 light() {
|
||||
vec2 lm = texture3D(uLightVolume, BoxCoord).rg * 0.9375 + 0.03125;
|
||||
return texture2D(uLightMap, max(lm, Light));
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 tex = texture2D(uBlockAtlas, TexCoords);
|
||||
|
||||
vec4 color = vec4(tex.rgb * light().rgb * Diffuse * Color.rgb, tex.a);
|
||||
|
||||
#if defined(USE_FOG)
|
||||
float fog = clamp(fogFactor(), 0., 1.);
|
||||
|
||||
gl_FragColor = mix(uFogColor, color, fog);
|
||||
gl_FragColor.a = color.a;
|
||||
#else
|
||||
gl_FragColor = color;
|
||||
#endif
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
varying vec3 BoxCoord;
|
||||
uniform sampler3D uLightVolume;
|
||||
|
||||
vec4 FLWLight(vec2 lightCoords, sampler2D lightMap) {
|
||||
vec2 lm = max(lightCoords, texture3D(uLightVolume, BoxCoord).rg);
|
||||
return texture2D(lightMap, lm * 0.9375 + 0.03125);
|
||||
}
|
@ -37,9 +37,9 @@ varying float FragDistance;
|
||||
#endif
|
||||
|
||||
#ifdef CONTRAPTION
|
||||
#flwinclude <"create:contraption/finalize.glsl">
|
||||
#flwinclude <"create:contraption/builtin.vert">
|
||||
#else
|
||||
#flwinclude <"create:std/finalize.glsl">
|
||||
#flwinclude <"create:std/builtin.vert">
|
||||
#endif
|
||||
|
||||
float toRad(float degrees) {
|
||||
|
@ -28,9 +28,9 @@ varying float FragDistance;
|
||||
#endif
|
||||
|
||||
#ifdef CONTRAPTION
|
||||
#flwinclude <"create:contraption/finalize.glsl">
|
||||
#flwinclude <"create:contraption/builtin.vert">
|
||||
#else
|
||||
#flwinclude <"create:std/finalize.glsl">
|
||||
#flwinclude <"create:std/builtin.vert">
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -30,9 +30,9 @@ varying float FragDistance;
|
||||
#endif
|
||||
|
||||
#ifdef CONTRAPTION
|
||||
#flwinclude <"create:contraption/finalize.glsl">
|
||||
#flwinclude <"create:contraption/builtin.vert">
|
||||
#else
|
||||
#flwinclude <"create:std/finalize.glsl">
|
||||
#flwinclude <"create:std/builtin.vert">
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
|
@ -32,9 +32,9 @@ varying float FragDistance;
|
||||
#endif
|
||||
|
||||
#ifdef CONTRAPTION
|
||||
#flwinclude <"create:contraption/finalize.glsl">
|
||||
#flwinclude <"create:contraption/builtin.vert">
|
||||
#else
|
||||
#flwinclude <"create:std/finalize.glsl">
|
||||
#flwinclude <"create:std/builtin.vert">
|
||||
#endif
|
||||
|
||||
mat4 kineticRotation() {
|
||||
|
@ -0,0 +1,4 @@
|
||||
vec4 FLWLight(vec2 lightCoords, sampler2D lightMap) {
|
||||
vec2 lm = lightCoords * 0.9375 + 0.03125;
|
||||
return texture2D(lightMap, lm);
|
||||
}
|
Loading…
Reference in New Issue
Block a user