EEVEE Next: Subsurface Scattering #107407
|
@ -365,7 +365,6 @@ void DeferredLayer::begin_sync()
|
|||
|
||||
void DeferredLayer::end_sync()
|
||||
{
|
||||
|
||||
if (closure_bits_ & (CLOSURE_DIFFUSE | CLOSURE_REFLECTION)) {
|
||||
const bool is_last_eval_pass = !(closure_bits_ & CLOSURE_SSS);
|
||||
|
||||
|
@ -393,24 +392,6 @@ void DeferredLayer::end_sync()
|
|||
eval_light_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH | GPU_BARRIER_SHADER_IMAGE_ACCESS);
|
||||
eval_light_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
|
||||
}
|
||||
|
||||
if (closure_bits_ & CLOSURE_SSS) {
|
||||
inst_.subsurface.end_sync();
|
||||
|
||||
subsurface_ps_.init();
|
||||
subsurface_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_STENCIL_EQUAL |
|
||||
DRW_STATE_BLEND_ADD_FULL);
|
||||
subsurface_ps_.state_stencil(0x00u, 0xFFu, CLOSURE_SSS);
|
||||
subsurface_ps_.shader_set(inst_.shaders.static_shader_get(SUBSURFACE_EVAL));
|
||||
inst_.subsurface.bind_resources(&subsurface_ps_);
|
||||
inst_.hiz_buffer.bind_resources(&subsurface_ps_);
|
||||
subsurface_ps_.bind_texture("radiance_tx", &diffuse_light_tx_);
|
||||
subsurface_ps_.bind_texture("gbuffer_closure_tx", &inst_.gbuffer.closure_tx);
|
||||
subsurface_ps_.bind_texture("gbuffer_color_tx", &inst_.gbuffer.color_tx);
|
||||
|
||||
subsurface_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH);
|
||||
subsurface_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
|
||||
}
|
||||
}
|
||||
|
||||
PassMain::Sub *DeferredLayer::prepass_add(::Material *blender_mat,
|
||||
|
@ -464,7 +445,7 @@ void DeferredLayer::render(View &view,
|
|||
inst_.manager->submit(eval_light_ps_, view);
|
||||
|
||||
if (closure_bits_ & CLOSURE_SSS) {
|
||||
inst_.manager->submit(subsurface_ps_, view);
|
||||
inst_.subsurface.render(view, combined_fb, diffuse_light_tx_);
|
||||
}
|
||||
|
||||
diffuse_light_tx_.release();
|
||||
|
|
|
@ -132,7 +132,6 @@ class DeferredLayer {
|
|||
PassMain::Sub *gbuffer_double_sided_ps_ = nullptr;
|
||||
|
||||
PassSimple eval_light_ps_ = {"EvalLights"};
|
||||
PassSimple subsurface_ps_ = {"Subsurface"};
|
||||
|
||||
/* Closures bits from the materials in this pass. */
|
||||
eClosureBits closure_bits_;
|
||||
|
|
|
@ -38,6 +38,27 @@ void SubsurfaceModule::end_sync()
|
|||
precompute_samples_location();
|
||||
|
||||
data_.push_update();
|
||||
|
||||
subsurface_ps_.init();
|
||||
subsurface_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_STENCIL_EQUAL |
|
||||
DRW_STATE_BLEND_ADD_FULL);
|
||||
subsurface_ps_.state_stencil(0x00u, 0xFFu, CLOSURE_SSS);
|
||||
subsurface_ps_.shader_set(inst_.shaders.static_shader_get(SUBSURFACE_EVAL));
|
||||
inst_.subsurface.bind_resources(&subsurface_ps_);
|
||||
inst_.hiz_buffer.bind_resources(&subsurface_ps_);
|
||||
subsurface_ps_.bind_texture("radiance_tx", &diffuse_light_tx_);
|
||||
subsurface_ps_.bind_texture("gbuffer_closure_tx", &inst_.gbuffer.closure_tx);
|
||||
subsurface_ps_.bind_texture("gbuffer_color_tx", &inst_.gbuffer.color_tx);
|
||||
|
||||
subsurface_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH);
|
||||
pragma37 marked this conversation as resolved
|
||||
subsurface_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
|
||||
}
|
||||
|
||||
void SubsurfaceModule::render(View &view, Framebuffer &fb, Texture &diffuse_light_tx)
|
||||
{
|
||||
fb.bind();
|
||||
diffuse_light_tx_ = *&diffuse_light_tx;
|
||||
inst_.manager->submit(subsurface_ps_, view);
|
||||
}
|
||||
|
||||
void SubsurfaceModule::precompute_samples_location()
|
||||
|
|
|
@ -37,6 +37,10 @@ struct SubsurfaceModule {
|
|||
SubsurfaceDataBuf data_;
|
||||
/** Contains translucence profile for a single color channel. */
|
||||
Texture transmittance_tx_;
|
||||
/** Scene diffuse irradiance. Pointer binded at sync time, set at render time. */
|
||||
GPUTexture *diffuse_light_tx_;
|
||||
/** Subsurface eval pass. Runs after the deferred pass. */
|
||||
PassSimple subsurface_ps_ = {"Subsurface"};
|
||||
|
||||
public:
|
||||
SubsurfaceModule(Instance &inst) : inst_(inst)
|
||||
|
@ -49,6 +53,8 @@ struct SubsurfaceModule {
|
|||
|
||||
void end_sync();
|
||||
|
||||
void render(View &view, Framebuffer &fb, Texture &diffuse_light_tx);
|
||||
|
||||
template<typename T> void bind_resources(draw::detail::PassBase<T> *pass)
|
||||
{
|
||||
pass->bind_ubo("sss_buf", data_);
|
||||
|
|
Loading…
Reference in New Issue
Also bind
RBUFS_VALUE_SLOT
otherwise it will trigger a warning / validation error.