Skip to content
Snippets Groups Projects
Verified Commit 2c07c792 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Use tone mapping module in projects reducing code, add normalizing

parent 2ac8270a
No related branches found
No related tags found
1 merge request!113Resolve "Tone mapping module"
Showing
with 48 additions and 41 deletions
...@@ -9,7 +9,7 @@ namespace vkcv::tone { ...@@ -9,7 +9,7 @@ namespace vkcv::tone {
void initToneMapping() override; void initToneMapping() override;
public: public:
explicit ACESToneMapping(Core& core); explicit ACESToneMapping(Core& core, bool normalize = false);
}; };
......
...@@ -9,7 +9,7 @@ namespace vkcv::tone { ...@@ -9,7 +9,7 @@ namespace vkcv::tone {
void initToneMapping() override; void initToneMapping() override;
public: public:
explicit FilmicToneMapping(Core& core); explicit FilmicToneMapping(Core& core, bool normalize = false);
}; };
......
...@@ -9,7 +9,7 @@ namespace vkcv::tone { ...@@ -9,7 +9,7 @@ namespace vkcv::tone {
void initToneMapping() override; void initToneMapping() override;
public: public:
explicit LottesToneMapping(Core& core); explicit LottesToneMapping(Core& core, bool normalize = false);
}; };
......
...@@ -9,7 +9,7 @@ namespace vkcv::tone { ...@@ -9,7 +9,7 @@ namespace vkcv::tone {
void initToneMapping() override; void initToneMapping() override;
public: public:
explicit Reinhard2ToneMapping(Core& core); explicit Reinhard2ToneMapping(Core& core, bool normalize = false);
}; };
......
...@@ -9,7 +9,7 @@ namespace vkcv::tone { ...@@ -9,7 +9,7 @@ namespace vkcv::tone {
void initToneMapping() override; void initToneMapping() override;
public: public:
explicit ReinhardToneMapping(Core& core); explicit ReinhardToneMapping(Core& core, bool normalize = false);
}; };
......
...@@ -12,6 +12,7 @@ namespace vkcv::tone { ...@@ -12,6 +12,7 @@ namespace vkcv::tone {
Core& m_core; Core& m_core;
std::string m_name; std::string m_name;
bool m_normalize;
ComputePipelineHandle m_pipeline; ComputePipelineHandle m_pipeline;
...@@ -40,8 +41,11 @@ namespace vkcv::tone { ...@@ -40,8 +41,11 @@ namespace vkcv::tone {
* *
* @param[in,out] core Reference to a Core instance * @param[in,out] core Reference to a Core instance
* @param[in] name Name of the tone mapping function * @param[in] name Name of the tone mapping function
* @param[in] normalize Normalize color values
*/ */
explicit ToneMapping(Core& core, const std::string& name); explicit ToneMapping(Core& core,
const std::string& name,
bool normalize = false);
~ToneMapping() = default; ~ToneMapping() = default;
......
...@@ -9,7 +9,7 @@ namespace vkcv::tone { ...@@ -9,7 +9,7 @@ namespace vkcv::tone {
void initToneMapping() override; void initToneMapping() override;
public: public:
explicit UchimuraToneMapping(Core& core); explicit UchimuraToneMapping(Core& core, bool normalize = false);
}; };
......
...@@ -9,7 +9,7 @@ namespace vkcv::tone { ...@@ -9,7 +9,7 @@ namespace vkcv::tone {
void initToneMapping() override; void initToneMapping() override;
public: public:
explicit Uncharted2ToneMapping(Core& core); explicit Uncharted2ToneMapping(Core& core, bool normalize = false);
}; };
......
...@@ -9,7 +9,7 @@ namespace vkcv::tone { ...@@ -9,7 +9,7 @@ namespace vkcv::tone {
void initToneMapping() override; void initToneMapping() override;
public: public:
explicit UnrealToneMapping(Core& core); explicit UnrealToneMapping(Core& core, bool normalize = false);
}; };
......
...@@ -9,7 +9,8 @@ namespace vkcv::tone { ...@@ -9,7 +9,8 @@ namespace vkcv::tone {
buildComputePipeline("aces", ACES_GLSL_SHADER); buildComputePipeline("aces", ACES_GLSL_SHADER);
} }
ACESToneMapping::ACESToneMapping(Core &core) : ToneMapping(core, "ACES Tone Mapping") { ACESToneMapping::ACESToneMapping(Core &core, bool normalize)
: ToneMapping(core, "ACES Tone Mapping", normalize) {
initToneMapping(); initToneMapping();
} }
......
...@@ -9,7 +9,8 @@ namespace vkcv::tone { ...@@ -9,7 +9,8 @@ namespace vkcv::tone {
buildComputePipeline("filmic", FILMIC_GLSL_SHADER); buildComputePipeline("filmic", FILMIC_GLSL_SHADER);
} }
FilmicToneMapping::FilmicToneMapping(Core &core) : ToneMapping(core, "Filmic Tone Mapping") { FilmicToneMapping::FilmicToneMapping(Core &core, bool normalize)
: ToneMapping(core, "Filmic Tone Mapping", normalize) {
initToneMapping(); initToneMapping();
} }
......
...@@ -9,7 +9,8 @@ namespace vkcv::tone { ...@@ -9,7 +9,8 @@ namespace vkcv::tone {
buildComputePipeline("lottes", LOTTES_GLSL_SHADER); buildComputePipeline("lottes", LOTTES_GLSL_SHADER);
} }
LottesToneMapping::LottesToneMapping(Core &core) : ToneMapping(core, "Lottes Tone Mapping") { LottesToneMapping::LottesToneMapping(Core &core, bool normalize)
: ToneMapping(core, "Lottes Tone Mapping", normalize) {
initToneMapping(); initToneMapping();
} }
......
...@@ -9,7 +9,8 @@ namespace vkcv::tone { ...@@ -9,7 +9,8 @@ namespace vkcv::tone {
buildComputePipeline("reinhard2", REINHARD2_GLSL_SHADER); buildComputePipeline("reinhard2", REINHARD2_GLSL_SHADER);
} }
Reinhard2ToneMapping::Reinhard2ToneMapping(Core &core) : ToneMapping(core, "Reinhard2 Tone Mapping") { Reinhard2ToneMapping::Reinhard2ToneMapping(Core &core, bool normalize)
: ToneMapping(core, "Reinhard2 Tone Mapping", normalize) {
initToneMapping(); initToneMapping();
} }
......
...@@ -9,7 +9,8 @@ namespace vkcv::tone { ...@@ -9,7 +9,8 @@ namespace vkcv::tone {
buildComputePipeline("reinhard", REINHARD_GLSL_SHADER); buildComputePipeline("reinhard", REINHARD_GLSL_SHADER);
} }
ReinhardToneMapping::ReinhardToneMapping(Core &core) : ToneMapping(core, "Reinhard Tone Mapping") { ReinhardToneMapping::ReinhardToneMapping(Core &core, bool normalize)
: ToneMapping(core, "Reinhard Tone Mapping", normalize) {
initToneMapping(); initToneMapping();
} }
......
...@@ -53,9 +53,14 @@ namespace vkcv::tone { ...@@ -53,9 +53,14 @@ namespace vkcv::tone {
stream << " return;" << std::endl; stream << " return;" << std::endl;
stream << " }" << std::endl; stream << " }" << std::endl;
stream << " ivec2 uv = ivec2(gl_GlobalInvocationID.xy);" << std::endl; stream << " ivec2 uv = ivec2(gl_GlobalInvocationID.xy);" << std::endl;
stream << " vec3 color = imageLoad(inImage, uv).xyz;" << std::endl; stream << " vec4 color = imageLoad(inImage, uv);" << std::endl;
stream << " color = " << functionName << "(color);" << std::endl;
stream << " imageStore(outImage, uv, vec4(color, 0.f));" << std::endl; if (m_normalize) {
stream << " color /= color.w;" << std::endl;
}
stream << " color = vec4(" << functionName << "(color.xyz), color.w);" << std::endl;
stream << " imageStore(outImage, uv, color);" << std::endl;
stream << "}" << std::endl; stream << "}" << std::endl;
compiler.compileSource( compiler.compileSource(
...@@ -88,8 +93,15 @@ namespace vkcv::tone { ...@@ -88,8 +93,15 @@ namespace vkcv::tone {
}); });
} }
ToneMapping::ToneMapping(Core &core, const std::string &name) ToneMapping::ToneMapping(Core &core,
: m_core(core), m_name(name), m_pipeline(), m_descriptorSetLayout(), m_descriptorSet() {} const std::string &name,
bool normalize)
: m_core(core),
m_name(name),
m_normalize(normalize),
m_pipeline(),
m_descriptorSetLayout(),
m_descriptorSet() {}
const std::string &ToneMapping::getName() const { const std::string &ToneMapping::getName() const {
return m_name; return m_name;
......
...@@ -9,7 +9,8 @@ namespace vkcv::tone { ...@@ -9,7 +9,8 @@ namespace vkcv::tone {
buildComputePipeline("uchimura", UCHIMURA_GLSL_SHADER); buildComputePipeline("uchimura", UCHIMURA_GLSL_SHADER);
} }
UchimuraToneMapping::UchimuraToneMapping(Core &core) : ToneMapping(core, "Uchimura Tone Mapping") { UchimuraToneMapping::UchimuraToneMapping(Core &core, bool normalize)
: ToneMapping(core, "Uchimura Tone Mapping", normalize) {
initToneMapping(); initToneMapping();
} }
......
...@@ -9,7 +9,8 @@ namespace vkcv::tone { ...@@ -9,7 +9,8 @@ namespace vkcv::tone {
buildComputePipeline("uncharted2", UNCHARTED2_GLSL_SHADER); buildComputePipeline("uncharted2", UNCHARTED2_GLSL_SHADER);
} }
Uncharted2ToneMapping::Uncharted2ToneMapping(Core &core) : ToneMapping(core, "Uncharted2 Tone Mapping") { Uncharted2ToneMapping::Uncharted2ToneMapping(Core &core, bool normalize)
: ToneMapping(core, "Uncharted2 Tone Mapping", normalize) {
initToneMapping(); initToneMapping();
} }
......
...@@ -9,7 +9,8 @@ namespace vkcv::tone { ...@@ -9,7 +9,8 @@ namespace vkcv::tone {
buildComputePipeline("unreal", UNREAL_GLSL_SHADER); buildComputePipeline("unreal", UNREAL_GLSL_SHADER);
} }
UnrealToneMapping::UnrealToneMapping(Core &core) : ToneMapping(core, "Unreal Tone Mapping") { UnrealToneMapping::UnrealToneMapping(Core &core, bool normalize)
: ToneMapping(core, "Unreal Tone Mapping", normalize) {
initToneMapping(); initToneMapping();
} }
......
...@@ -19,6 +19,7 @@ target_include_directories(particle_simulation SYSTEM BEFORE PRIVATE ...@@ -19,6 +19,7 @@ target_include_directories(particle_simulation SYSTEM BEFORE PRIVATE
${vkcv_includes} ${vkcv_includes}
${vkcv_camera_include} ${vkcv_camera_include}
${vkcv_shader_compiler_include} ${vkcv_shader_compiler_include}
${vkcv_tone_mapping_include}
${vkcv_effects_include}) ${vkcv_effects_include})
# linking with libraries from all dependencies and the VkCV framework # linking with libraries from all dependencies and the VkCV framework
...@@ -26,4 +27,5 @@ target_link_libraries(particle_simulation ...@@ -26,4 +27,5 @@ target_link_libraries(particle_simulation
vkcv vkcv
vkcv_camera vkcv_camera
vkcv_shader_compiler vkcv_shader_compiler
vkcv_tone_mapping
vkcv_effects) vkcv_effects)
#version 440
layout(set=0, binding=0, rgba16f) uniform image2D inImage;
layout(set=0, binding=1, rgba8) uniform image2D outImage;
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
void main(){
if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(inImage)))){
return;
}
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
vec3 linearColor = imageLoad(inImage, uv).rgb;
vec3 tonemapped = linearColor / (dot(linearColor, vec3(0.21, 0.71, 0.08)) + 1); // reinhard tonemapping
vec3 gammaCorrected = pow(tonemapped, vec3(1.f / 2.2f));
imageStore(outImage, uv, vec4(gammaCorrected, 0.f));
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment