Skip to content

Instantly share code, notes, and snippets.

@Hugobros3
Created March 6, 2018 10:48
Show Gist options
  • Save Hugobros3/2b7591bf886631982dabc094d71bc195 to your computer and use it in GitHub Desktop.
Save Hugobros3/2b7591bf886631982dabc094d71bc195 to your computer and use it in GitHub Desktop.
interface RenderingInterface {
}
... in chunkstories-api, implemented in 'chunkstories'
interface RenderingPipeline {
registerRenderPass(String name, RenderPass pass);
RenderPass getRenderPass(String name);
}
abstract class RenderPass {
RenderPass(String[] requires, String[] exports) {
this.requires = requires;
this.exports = exports;
}
public List<String> requires; //contains the input buffers you want to be given in the form renderPassRequired.bufferRequired and end with an ! to ask to be able to write to that texture
public List<String> exports; //Contains the output buffers you expose to the other passes. you can also pass inputs
/** Called when all the required render passes have been initialized, gives you the inputs you asked */
public abstract void resolvedInputs(Map<String, Texture> inputs);
public Map<String, Texture> outputs) resolvedOutputs = new HashMap<>();
public void render(RenderingInterface renderer);
public void onScreenResize();
}
... (in core)
somewhere in initialization:
void onRenderingPipelineInitialization(RenderingPipelineInitEvent event) {
RenderingPipeline pipeline = event.getPipeline();
SkyPass sky = new SkyPass( {} /* requires nothing */, {"shadedBuffer"} );
pipeline.registerRenderPass("sky", sky);
FarTerrainPass farTerrain = new FarTerrainPass( {"sky.shadedBuffer!"}, {"shadedBuffer", "zBuffer"} ); // far terrain needs the shaded buffer from sky and outputs it, as well with a zbuffer
pipeline.registerRenderPass("farTerrain", farTerrain);
GBuffersPass gBuffers = new GBuffersPass( {"zBuffer!"}, {"albedo", "normals", "materials", "zBuffer" } ); // gbuffer uses the zBuffer and outputs albedo/normal/materials
pipeline.registerRenderPass("gBuffers", gBuffers);
ShadowMapPass sunShadowMap = new ShadowMapPass( {}, {"shadowmap"} ); // a shadowmap pass requires no previous buffer and just outputs a shadowmap
// note we could generalize the shadowmappass to not onyl the sun but also the moon, point and spotlights
pipeline.registerRenderPass("sunShadowMap", sunShadowMap);
// aka shadows_apply in the current code, it takes the gbuffers and applies the shadowmapping to them, then outputs to the shaded pixels buffers already filled with the far terrain pixels
ApplySunlightPass applySunlight = new ApplySunlightPass( {"gBuffers.albedo", "gBuffers.normals", "gBuffers.materials", "gBuffers.zBuffer", "sunShadowMap.shadowmap", "farTerrain.shadedBuffer!"}, {"shadedbuffer"});
pipeline.registerRenderPass("applySunlight", applySunlight);
pipeline.registerRenderPass("final", new FinalRenderPass("applySunlight.shadedBuffer"); // final render pass just takes one buffer and outputs it to screen
}
// if some mod wants to add in GI support
void onRenderingPipelineInitialization(RenderingPipelineInitEvent event) {
RenderingPipeline pipeline = event.getPipeline();
GiVoxelPass giPass = new GiVoxelPass({}, {"giBuffer"});
pipleline.registerRenderPass("giPass", giPass);
pipeline.getRenderPass("applySunLight").requires.add("giPass.giBuffer"); //and modify the applySunlight shader to use the extra sampler input
}
class SkyPass extends RenderPass {
Texture2DRenderBuffer shadedBuffer = new Texture2DRenderBuffer(TextureFormat.RGB_HDR, screenSize.x, screenSize.y);
SkyPass(List requires, List exports) {
super(require, exports);
resolvedOutputs.put("shadedBuffer", shadedBuffer);
}
public void render(RenderingInterface renderer) {
Shader skyShader = renderer.useShader("sky");
renderer.getCamera().setupShader(skyShader);
}
}
yeah so 3g ate my reply, @realz#2761 , it's raytraced and accululated single bounce gi against a 128³ voxel grid ( generated straight from the classic chunks in ram and uploaded )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment