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

6
dof.hh
View file

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

View file

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

View file

@ -52,7 +52,6 @@ void T_Raymarcher::render( )
U_RAYMARCHER = 7 , U_RAYMARCHER = 7 ,
}; };
#if 1
const auto id( program_.program( E_ShaderType::FRAGMENT ) ); const auto id( program_.program( E_ShaderType::FRAGMENT ) );
glProgramUniform1f( id , U_TIME , 0 ); glProgramUniform1f( id , U_TIME , 0 );
glProgramUniform2f( id , U_RESOLUTION , rtOutput_.width( ) , rtOutput_.height( ) ); glProgramUniform2f( id , U_RESOLUTION , rtOutput_.width( ) , rtOutput_.height( ) );
@ -68,22 +67,6 @@ void T_Raymarcher::render( )
rmEpsilon , rmMaxDist ); rmEpsilon , rmMaxDist );
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 ); 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( ); PEND( );
} }

View file

@ -1,5 +1,4 @@
#version 450 core //! type chunk
//#define USE_RANDOM //#define USE_RANDOM
layout( location = 0 ) uniform sampler2D u_Input; 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() void main()
{ {
vec2 uv = gl_FragCoord.xy / uResolution; vec2 uv = gl_FragCoord.xy / uResolution;

View file

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