Skip to content

Instantly share code, notes, and snippets.

@Thinkofname
Created June 26, 2017 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thinkofname/6bfdf7d613f42d71eda2e0b4496d6ad5 to your computer and use it in GitHub Desktop.
Save Thinkofname/6bfdf7d613f42d71eda2e0b4496d6ad5 to your computer and use it in GitHub Desktop.
let mut pipeline = Pipeline::<PassFlag>::new(asset_manager.clone())
.program("merge", |_, p| p
.vertex("fullscreen_vert")
.fragment("merge"))
.program("ssao", |_, p| p
.vertex("fullscreen_vert")
.fragment("ssao"))
.program("blur_ssao", |_, p| p
.vertex("fullscreen_vert")
.fragment("blur_ssao"))
.program("ui", |_, p| p
.vertex("ui_vert")
.fragment("ui_frag"))
.program("cursor", |_, p| p
.vertex("cursor_vert")
.fragment("cursor_frag"))
.program("placement", |_, p| p
.vertex("placement_vert")
.fragment("placement_frag"))
.program("icon", |_, p| p
.vertex("icon_vert")
.fragment("icon_frag"))
.program("terrain", |_, p| p
.vertex("terrain_vert")
.fragment("terrain_frag"))
.program("terrain_selection", |c, p| {
let base = c.program("terrain");
p
.vertex("terrain_vert")
.vertex_defines(sstr!["selection"])
.fragment("terrain_frag")
.fragment_defines(sstr!["selection"])
.attribute_binds(&[
("attrib_position", base.attribute("attrib_position").unwrap().index()),
("attrib_normal", base.attribute("attrib_normal").unwrap().index()),
("attrib_texture", base.attribute("attrib_texture").unwrap().index()),
])
})
.program("terrain_shadow", |c, p| {
let base = c.program("terrain");
p
.vertex("terrain_vert")
.vertex_defines(sstr!["shadow_pass"])
.fragment("terrain_frag")
.fragment_defines(sstr!["shadow_pass"])
.attribute_binds(&[
("attrib_position", base.attribute("attrib_position").unwrap().index()),
("attrib_normal", base.attribute("attrib_normal").unwrap().index()),
("attrib_texture", base.attribute("attrib_texture").unwrap().index()),
])
})
.program("static", |_, p| p
.vertex("static_vert")
.fragment("static_frag"))
.program("static_shadow", |c, p| {
let base = c.program("static");
p
.vertex("static_vert")
.vertex_defines(sstr!["shadow_pass"])
.fragment("static_frag")
.fragment_defines(sstr!["shadow_pass"])
.attribute_binds(&[
("attrib_position", base.attribute("attrib_position").unwrap().index()),
("attrib_normal", base.attribute("attrib_normal").unwrap().index()),
("attrib_uv", base.attribute("attrib_uv").unwrap().index()),
("attrib_matrix", base.attribute("attrib_matrix").unwrap().index()),
("attrib_tint", base.attribute("attrib_tint").unwrap().index()),
])
})
.program("animated", |_, p| p
.vertex("animated_vert")
.fragment("animated_frag"))
.program("animated_shadow", |c, p| {
let base = c.program("animated");
p
.vertex("animated_vert")
.vertex_defines(sstr!["shadow_pass"])
.fragment("animated_frag")
.fragment_defines(sstr!["shadow_pass"])
.attribute_binds(&[
("attrib_position", base.attribute("attrib_position").unwrap().index()),
("attrib_normal", base.attribute("attrib_normal").unwrap().index()),
("attrib_uv", base.attribute("attrib_uv").unwrap().index()),
("attrib_bones", base.attribute("attrib_bones").unwrap().index()),
("attrib_bone_weights", base.attribute("attrib_bone_weights").unwrap().index()),
("attrib_matrix", base.attribute("attrib_matrix").unwrap().index()),
("attrib_tint", base.attribute("attrib_tint").unwrap().index()),
("attrib_bone_offset", base.attribute("attrib_bone_offset").unwrap().index()),
("attrib_tint_offset", base.attribute("attrib_tint_offset").unwrap().index()),
])
})
.pass("shadow", |_c, p| p
.size(2048, 2048)
.program_replace("terrain", "terrain_shadow")
.program_replace("terrain_selection", "terrain_shadow")
.program_replace("static", "static_shadow")
.program_replace("animated", "animated_shadow")
.attachment("depth", |a| a
.ty(pipeline::Type::Float)
.components(pipeline::Components::Depth24)
.target(pipeline::AttachTarget::Depth)
.border_color([1.0, 1.0, 1.0, 1.0])
.clear_value([1.0, 0.0, 0.0, 0.0])
.compare_ref()
.linear())
.flag(PASS_NO_ICONS | PASS_NO_CURSOR))
.pass("base", |_c, p| p
.bind_texture("shadow", "depth", SHADOW_MAP_LOCATION)
.attachment("color", |a| a
.ty(pipeline::Type::HalfFloat)
.components(pipeline::Components::RGB)
.target(pipeline::AttachTarget::Color)
.clear_value([0.0, 0.0, 0.0, 1.0]))
.attachment("normal", |a| a
.ty(pipeline::Type::HalfFloat)
.components(pipeline::Components::RGB)
.target(pipeline::AttachTarget::Color)
.clear_value([0.0, 0.0, 0.0, 0.0]))
.attachment("position", |a| a
.ty(pipeline::Type::Float)
.components(pipeline::Components::RGBA)
.target(pipeline::AttachTarget::Color)
.clear_value([0.0, 0.0, 0.0, 0.0]))
.attachment("depth", |a| a
.ty(pipeline::Type::Float)
.components(pipeline::Components::Depth24)
.target(pipeline::AttachTarget::Depth)
.clear_value([1.0, 0.0, 0.0, 0.0]))
.clear_flags(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT)
.flag(PassFlag::empty()))
.pass("ssao", |_, p| p
.scale(2)
.attachment("ssao", |a| a
.ty(pipeline::Type::U8)
.components(pipeline::Components::R)
.target(pipeline::AttachTarget::Color)
.scale(2)
.linear()
.clear_value([0.0, 0.0, 0.0, 1.0]))
.fullscreen(|f| f
.shader("ssao")
.input("g_position", "base", "position")
.input("g_normal", "base", "normal")
.pre(move |ctx| {
let projection = *ctx.var::<Matrix4<f32>>("projection").unwrap();
let p = ctx.program("ssao");
gl::active_texture(1);
noise_tex.bind(gl::TextureTarget::Texture2D);
p.uniform("noise").map(|v| v.set_int(1));
gl::active_texture(0);
p.uniform("samples[0]").map(|v| v.set_vec3_array(&ssao_kernel));
p.uniform("projection").map(|v| v.set_matrix4(&projection));
}))
.clear_flags(gl::COLOR_BUFFER_BIT)
.flag(PassFlag::empty()))
.pass("blur_ssao", |_, p| p
.scale(2)
.attachment("blur_ssao", |a| a
.ty(pipeline::Type::U8)
.components(pipeline::Components::R)
.target(pipeline::AttachTarget::Color)
.scale(2)
.clear_value([0.0, 0.0, 0.0, 1.0]))
.fullscreen(|f| f
.shader("blur_ssao")
.input("g_ssao", "ssao", "ssao"))
.clear_flags(gl::COLOR_BUFFER_BIT)
.flag(PassFlag::empty()))
.pass("merge", |_, p| p
.fullscreen(|f| f
.shader("merge")
.input("g_color", "base", "color")
.input("g_normal", "base", "normal")
.input("g_ssao", "blur_ssao", "blur_ssao"))
.clear_flags(gl::COLOR_BUFFER_BIT)
.flag(PassFlag::empty()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment