DoF ported to new shader management

This commit is contained in:
Emmanuel BENOîT 2017-10-04 17:37:55 +02:00
parent 61d6027a42
commit 2bd15c41ab
7 changed files with 40 additions and 45 deletions

48
dof.cc
View file

@ -15,8 +15,6 @@ T_DoFPass::T_DoFPass(
__rw__ T_Texture& imageInput ,
__rw__ T_Texture& depthInput )
: imageInput_( imageInput ) , depthInput_( depthInput ) ,
spPass1_( GL_FRAGMENT_SHADER ) ,
spPass2_( GL_FRAGMENT_SHADER ) ,
txPass1_( imageInput.width( ) , imageInput.height( ) ,
E_TexType::RGB16F ) ,
txOutput_( imageInput.width( ) , imageInput.height( ) ,
@ -28,13 +26,10 @@ T_DoFPass::T_DoFPass(
{
txPass1_.wrap( E_TexWrap::CLAMP_EDGE );
spPass1_.addFile( "dof-common.glsl" );
spPass1_.addFile( "dof-pass1.glsl" );
spPass1_.load( );
spPass2_.addFile( "dof-common.glsl" );
spPass2_.addFile( "dof-pass2.glsl" );
spPass2_.load( );
spPass1_ = Globals::Shaders( ).pipeline({
"fullscreen.v.glsl" , "dof-pass1.f.glsl" });
spPass2_ = Globals::Shaders( ).pipeline({
"fullscreen.v.glsl" , "dof-pass2.f.glsl" });
}
void T_DoFPass::render( )
@ -49,32 +44,39 @@ void T_DoFPass::render( )
};
auto& tm( Globals::Textures( ) );
if ( spPass1_.activate( ) && rtPass1_.activate( ) ) {
glUniform1i( U_INPUT , 0 );
glUniform1i( U_DEPTH , 1 );
glUniform4fv( U_PARAMS , 1 , filterParams_ );
glUniform1f( U_SAMPLES , nSamples_ );
glUniform3f( U_RES_TIME , imageInput_.width( ) ,
rtPass1_.activate( );
if ( spPass1_.valid( ) ) {
const auto id( spPass1_.program( E_ShaderType::FRAGMENT ) );
spPass1_.enable( );
glProgramUniform1i( id , U_INPUT , 0 );
glProgramUniform1i( id , U_DEPTH , 1 );
glProgramUniform4fv( id , U_PARAMS , 1 , filterParams_ );
glProgramUniform1f( id , U_SAMPLES , nSamples_ );
glProgramUniform3f( id , U_RES_TIME , imageInput_.width( ) ,
imageInput_.height( ) ,
0 );
tm.bind( 0 , imageInput_ , *tm.sampler( "linear-edge" ) );
tm.bind( 1 , depthInput_ , *tm.sampler( "linear-edge" ) );
glRectf( -1 , -1 , 1 , 1 );
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
}
if ( spPass2_.activate( ) && rtPass2_.activate( ) ) {
glUniform1i( U_INPUT , 0 );
glUniform1i( U_DEPTH , 1 );
glUniform4fv( U_PARAMS , 1 , filterParams_ );
glUniform1f( U_SAMPLES , nSamples_ );
glUniform3f( U_RES_TIME , imageInput_.width( ) ,
rtPass2_.activate( );
if ( spPass2_.valid( ) ) {
const auto id( spPass2_.program( E_ShaderType::FRAGMENT ) );
spPass2_.enable( );
glProgramUniform1i( id , U_INPUT , 0 );
glProgramUniform1i( id , U_DEPTH , 1 );
glProgramUniform4fv( id , U_PARAMS , 1 , filterParams_ );
glProgramUniform1f( id , U_SAMPLES , nSamples_ );
glProgramUniform3f( id , U_RES_TIME ,
imageInput_.width( ) ,
imageInput_.height( ) ,
0 );
tm.bind( 0 , txPass1_ , *tm.sampler( "linear-edge" ) );
glRectf( -1 , -1 , 1 , 1 );
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
}
PEND( );
}

6
dof.hh
View file

@ -1,6 +1,6 @@
#pragma once
#include "rendertarget.hh"
#include "programs.hh"
#include "shaders.hh"
struct T_DoFPass
@ -21,8 +21,8 @@ struct T_DoFPass
T_Texture& imageInput_;
T_Texture& depthInput_;
T_ShaderProgram spPass1_;
T_ShaderProgram spPass2_;
T_ShaderPipeline spPass1_;
T_ShaderPipeline spPass2_;
T_Texture txPass1_ , txOutput_;
T_Rendertarget rtPass1_ , rtPass2_;

View file

@ -183,6 +183,7 @@ void T_Main::render( )
glFinish( ); Globals::Profiler( ).end( "Render" );
}
glUseProgram( 0 );
glBindProgramPipeline( 0 );
Globals::Textures( ).reset( );
ImGui::Render( );
}

View file

@ -52,7 +52,6 @@ void T_Raymarcher::render( )
U_RAYMARCHER = 7 ,
};
#if 1
const auto id( program_.program( E_ShaderType::FRAGMENT ) );
glProgramUniform1f( id , U_TIME , 0 );
glProgramUniform2f( id , U_RESOLUTION , rtOutput_.width( ) , rtOutput_.height( ) );
@ -68,22 +67,6 @@ void T_Raymarcher::render( )
rmEpsilon , rmMaxDist );
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
glBindProgramPipeline( 0 );
#else
glUniform1f( U_TIME , 0 );
glUniform2f( U_RESOLUTION , rtOutput_.width( ) , rtOutput_.height( ) );
glUniform3fv( U_CAM_POS , 1 , &camera_.pos.x );
glUniform3fv( U_LOOK_AT , 1 , &camera_.lookAt.x );
glUniform3fv( U_CAM_UP , 1 , &camera_.up.x );
glUniform1f( U_NEAR_PLANE , camera_.np );
glUniform3f( U_LIGHT_DIR , 0 , 1 , -1 );
glUniform4f( U_RAYMARCHER , rmIterations , rmStep , rmEpsilon , rmMaxDist );
glRectf( -1 , -1 , 1 , 1 );
#endif
PEND( );
}

View file

@ -1,5 +1,4 @@
#version 450 core
//! type chunk
//#define USE_RANDOM
layout( location = 0 ) uniform sampler2D u_Input;

View file

@ -1,3 +1,8 @@
#version 450 core
//! type fragment
//! include dof-common.l.glsl
void main()
{
vec2 uv = gl_FragCoord.xy / uResolution;

View file

@ -1,3 +1,8 @@
#version 450 core
//! type fragment
//! include dof-common.l.glsl
void main()
{
vec2 uv = gl_FragCoord.xy / uResolution;