Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev-ndy
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Dacquay committed Jan 3, 2024
2 parents d2a82c7 + 41dca19 commit 8f9fa26
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 23 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# VTX - High performance molecular visualization software
[![Gitter](https://badges.gitter.im/VTX_mol/VTX.svg)](https://gitter.im/VTX_mol/VTX?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

![VTX Image](https://vtx.drugdesign.fr/assets/snapshots/2.png)

## USER GUIDE
Expand Down
34 changes: 24 additions & 10 deletions lib/renderer/bench/src/input_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ namespace VTX::Bench
class InputManager
{
public:
using CallbackClose = std::function<void()>;
using CallbackResize = std::function<void( const size_t, const size_t )>;
using CallbackTranslate = std::function<void( const Vec3i & )>;
using CallbackRotate = std::function<void( const Vec2i & )>;
using CallbackZoom = std::function<void( const int )>;
using CallbackClose = std::function<void()>;
using CallbackResize = std::function<void( const size_t, const size_t )>;
using CallbackTranslate = std::function<void( const Vec3i & )>;
using CallbackRotate = std::function<void( const Vec2i & )>;
using CallbackZoom = std::function<void( const int )>;
using CallbackMouseMotion = std::function<void( const Vec2i & )>;

inline void setCallbackClose( const CallbackClose & p_cb ) { _callbackClose = p_cb; }
inline void setCallbackResize( const CallbackResize & p_cb ) { _callbackResize = p_cb; }
inline void setCallbackTranslate( const CallbackTranslate & p_cb ) { _callbackTranslate = p_cb; }
inline void setCallbackRotate( const CallbackRotate & p_cb ) { _callbackRotate = p_cb; }
inline void setCallbackZoom( const CallbackZoom & p_cb ) { _callbackZoom = p_cb; }
inline void setCallbackMouseMotion( const CallbackMouseMotion & p_cb ) { _callbackMouseMotion = p_cb; }

inline bool isKeyPressed( const SDL_Scancode p_key ) const { return _keys[ p_key ]; }
inline bool isMouseButtonPressed( const size_t p_button ) const { return _mouseButtons[ p_button ]; }
Expand All @@ -41,6 +43,9 @@ namespace VTX::Bench
_deltaMouse.x += p_event.motion.xrel;
_deltaMouse.y += p_event.motion.yrel;
}
int x, y;
SDL_GetMouseState( &x, &y );
_onMouseMotion( x, y );
break;
case SDL_MOUSEWHEEL: _deltaWheel += p_event.wheel.y; break;
case SDL_WINDOWEVENT:
Expand Down Expand Up @@ -116,11 +121,12 @@ namespace VTX::Bench
Vec2i _deltaMouse = { 0, 0 };
int _deltaWheel = 0;

CallbackClose _callbackClose;
CallbackResize _callbackResize;
CallbackTranslate _callbackTranslate;
CallbackRotate _callbackRotate;
CallbackZoom _callbackZoom;
CallbackClose _callbackClose;
CallbackResize _callbackResize;
CallbackTranslate _callbackTranslate;
CallbackRotate _callbackRotate;
CallbackZoom _callbackZoom;
CallbackMouseMotion _callbackMouseMotion;

inline void _onClose()
{
Expand All @@ -137,6 +143,14 @@ namespace VTX::Bench
_callbackResize( p_w, p_h );
}
}

inline void _onMouseMotion( const size_t p_x, const size_t p_y )
{
if ( _callbackMouseMotion )
{
_callbackMouseMotion( { p_x, p_y } );
}
}
};
} // namespace VTX::Bench

Expand Down
2 changes: 2 additions & 0 deletions lib/renderer/bench/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ int main( int, char ** )
camera.resize( p_width, p_height );
}
);
inputManager.setCallbackMouseMotion( [ &renderer ]( const Vec2i & p_position )
{ renderer.setMousePosition( p_position ); } );
renderer.setCallbackClean(
[ &camera, &inputManager ]()
{
Expand Down
19 changes: 15 additions & 4 deletions lib/renderer/include/renderer/passes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ namespace VTX::Renderer
Uniforms { { "Color", E_TYPE::COLOR4, StructUniformValue<Util::Color::Rgba> { COLOR_WHITE } },
{ "Sensitivity",
E_TYPE::FLOAT,
StructUniformValue<float> { 0.f, StructUniformValue<float>::MinMax { 0.01f, 1.f } } },
StructUniformValue<float> { 0.f, StructUniformValue<float>::MinMax { 0.f, 1.f } } },
{ "Thickness",
E_TYPE::UINT,
StructUniformValue<uint> { 1, StructUniformValue<uint>::MinMax { 1, 5 } } } } } }
Expand Down Expand Up @@ -218,11 +218,11 @@ namespace VTX::Renderer

// Chromatic aberration.
static const Pass descPassChromaticAberration {
"Chromatic Aberration",
"Chromatic aberration",
Inputs { { E_CHANNEL_INPUT::_0, { "", imageRGBA16F } } },
Outputs { { E_CHANNEL_OUTPUT::COLOR_0, { "", imageRGBA16F } } },
Programs {
{ "Chromatic Aberration",
{ "Chromatic aberration",
std::vector<FilePath> { "default.vert", "chromatic_aberration.frag" },
Uniforms {
{ "Red",
Expand All @@ -236,6 +236,17 @@ namespace VTX::Renderer
StructUniformValue<float> { -0.006f, StructUniformValue<float>::MinMax { -0.05f, 0.05f } } } } } }
};

// Colorize.
static const Pass descPassColorize {
"Colorize",
Inputs { { E_CHANNEL_INPUT::_0, { "", imageRGBA16F } } },
Outputs { { E_CHANNEL_OUTPUT::COLOR_0, { "", imageRGBA16F } } },
Programs {
{ "Colorize",
std::vector<FilePath> { "default.vert", "colorize.frag" },
Uniforms { { "Color", E_TYPE::COLOR4, StructUniformValue<Util::Color::Rgba> { COLOR_YELLOW } } } } }
};

// Debug.
static const Pass descPassDebug {
"Debug",
Expand All @@ -255,7 +266,7 @@ namespace VTX::Renderer
static const std::vector<Pass> availablePasses {
descPassGeometric, descPassDepth, descPassSSAO, descPassBlur, descPassShading,
descPassOutline, desPassFXAA, descPassPixelize, descPassCRT, descPassChromaticAberration,
descPassDebug
descPassColorize, descPassDebug
};
} // namespace VTX::Renderer

Expand Down
9 changes: 6 additions & 3 deletions lib/renderer/include/renderer/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace VTX::Renderer
{ "Matrix projection", E_TYPE::MAT4F, StructUniformValue<Mat4f> { MAT4F_ID } },
// { _near * _far, _far, _far - _near, _near }
{ "Camera clip infos", E_TYPE::VEC4F, StructUniformValue<Vec4f> { VEC4F_ZERO } },
// TODO: check why not compiling with bool.
{ "Mouse position", E_TYPE::VEC2I, StructUniformValue<Vec2i> { { 0, 0 } } },
{ "Is perspective", E_TYPE::BOOL, StructUniformValue<bool> { true } } }
);
}
Expand Down Expand Up @@ -185,6 +185,11 @@ namespace VTX::Renderer
setUniform( Vec4f( p_near * p_far, p_far, p_far - p_near, p_near ), "Camera clip infos" );
}

inline void setMousePosition( const Vec2i & p_position )
{
setUniform( Vec2i { p_position.x, _height - p_position.y }, "Mouse position" );
}

inline void addMolecule( const StructProxyMolecule & p_proxy )
{
_molecules.push_back( p_proxy );
Expand Down Expand Up @@ -231,8 +236,6 @@ namespace VTX::Renderer
size_t _sizeAtoms = 0;
size_t _sizeBonds = 0;

std::vector<Vec3f> _noise;

void _setData( const StructProxyMolecule & p_proxy )
{
_renderGraph->setData( *p_proxy.atomPositions, "MoleculesPositions" );
Expand Down
6 changes: 2 additions & 4 deletions lib/renderer/shaders/chromatic_aberration.frag
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450 core

#include "struct_data_packed.glsl"
#include "layout_uniforms_camera.glsl";

// In.
layout( binding = 0 ) uniform sampler2D inTextureColor;
Expand All @@ -20,9 +20,7 @@ void main()
const ivec2 texCoord = ivec2( gl_FragCoord.xy );
const vec2 texSize = textureSize( inTextureColor, 0 );
const vec2 uv = texCoord / texSize;

const ivec2 focusPoint = ivec2( 0, 0 );
const vec2 direction = uv - focusPoint;
const vec2 direction = uv - uniformsCamera.mousePosition / texSize;

outFragColor.r = texture( inTextureColor, uv + ( direction * vec2( uniforms.offsetRed ) ) ).r;
outFragColor.g = texture( inTextureColor, uv + ( direction * vec2( uniforms.offsetGreen ) ) ).g;
Expand Down
24 changes: 24 additions & 0 deletions lib/renderer/shaders/colorize.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#version 450 core

// In.
layout( binding = 0 ) uniform sampler2D inTextureColor;

layout ( std140, binding = 1 ) uniform Uniforms
{
vec4 color;
} uniforms;

// Out.
layout( location = 0 ) out vec4 outFragColor;

void main()
{
const ivec2 texCoord = ivec2( gl_FragCoord.xy );
const vec2 texSize = textureSize( inTextureColor, 0 );
const vec2 uv = texCoord / texSize;

vec4 fragColor = texture( inTextureColor, texCoord / texSize );
float greyscale = max( fragColor.r, max( fragColor.g, fragColor.b ) );

outFragColor = vec4( greyscale, greyscale, greyscale, 1.f ) * uniforms.color;
}
1 change: 1 addition & 0 deletions lib/renderer/shaders/layout_uniforms_camera.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ layout ( std140, binding = 15 ) uniform UniformsCamera
mat4 matrixView;
mat4 matrixProjection;
vec4 cameraClipInfos; // _near * _far, _far, _far - _near, _near
ivec2 mousePosition;
bool isCameraPerspective;
} uniformsCamera;

0 comments on commit 8f9fa26

Please sign in to comment.