Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
ShaderEditor.hpp
1#pragma once
2
3#include "Application.hpp"
4#include "resources/Texture.hpp"
5#include "graphics/Program.hpp"
6
7#include "Common.hpp"
8
13class ShaderEditor final : public CameraApp {
14
15public:
20 explicit ShaderEditor(RenderingConfig & config, Window & window);
21
23 void draw() override;
24
27 void update() override;
28
31 void resize() override;
32
34 ~ShaderEditor() override;
35
39 void loadShader(const std::string& path);
40
41private:
42
44 void handleShortcuts();
45
49 void displayUniforms(uint columnsCount);
50
56 std::string reload(const std::string & shaderPath, bool syncUniforms);
57
59 void restoreUniforms();
60
66 std::string generateParametersString(const std::string & prefix, bool exportValues);
67
68
70 struct BoolOption {
71 std::string name;
72 bool value = false;
73 };
74
76 struct IntOption {
77 std::string name;
78 int value = 0;
79 };
80
82 struct FloatOption {
83 std::string name;
84 float value = 0.0f;
85 float min = 0.0f;
86 float max = 1.0f;
87 };
88
90 struct VecOption {
91 std::string name;
92 glm::vec4 value = glm::vec4(0.0f);
93 };
94
96 struct ColorOption {
97 std::string name;
98 glm::vec3 value = glm::vec3(1.0f, 0.0f, 0.0f);
99 };
100
102 enum class LayoutMode : int {
103 HORIZONTAL,
104 VERTICAL,
105 FREEFORM
106 };
107
112
113 std::string _shaderPath;
114 std::string _shaderName;
115 std::unique_ptr<Program> _currProgram;
118
119 std::vector<const Texture *> _textures;
125 const Texture * _fallbackTex = nullptr;
126
127 std::vector<BoolOption> _flags;
128 std::vector<IntOption> _integers;
129 std::vector<FloatOption> _floats;
130 std::vector<VecOption> _vectors;
131 std::vector<ColorOption> _colors;
132
133 uint _frame = 0;
134 double _currentTime = 0.0;
135 double _startTime = 0.0;
136 bool _paused = false;
137 bool _showGUI = true;
138 bool _windowed = false;
140 std::string _compilationLog;
141};
Window & window()
Definition: Application.cpp:95
Application with an interactive camera.
Definition: Application.hpp:89
Represent a GPU query, automatically buffered and retrieved.
Definition: GPUTypes.hpp:412
@ TIME_ELAPSED
Time taken by GPU operations between the beginning and end of the query.
Represents a group of shaders used for rendering.
Definition: Program.hpp:31
Configuration containing parameters for windows and renderers.
Definition: Config.hpp:113
Shader editor that can be used to tweak shaders on the fly, reloading them and exposing parameters fo...
Definition: ShaderEditor.hpp:13
std::vector< BoolOption > _flags
Predefined boolean parameters.
Definition: ShaderEditor.hpp:127
Texture _frame0
Content texture.
Definition: ShaderEditor.hpp:108
Texture _perlin3D
Random 3D RGBA periodic Perlin noise in [0,1].
Definition: ShaderEditor.hpp:124
Texture _directions
Random 3D directions on the sphere.
Definition: ShaderEditor.hpp:122
std::vector< ColorOption > _colors
Predefined color parameters.
Definition: ShaderEditor.hpp:131
double _startTime
Time at which the shader began to play.
Definition: ShaderEditor.hpp:135
bool _showGUI
Show the GUI parameters panel.
Definition: ShaderEditor.hpp:137
GPUQuery _timer
Timer for the user shader pass.
Definition: ShaderEditor.hpp:117
Texture _frame1
Content texture.
Definition: ShaderEditor.hpp:109
Texture _noise
Random 2D RGBA uniform noise in [0,1].
Definition: ShaderEditor.hpp:120
std::vector< FloatOption > _floats
Predefined float parameters.
Definition: ShaderEditor.hpp:129
uint _frame
Current frame ID.
Definition: ShaderEditor.hpp:133
void restoreUniforms()
Definition: ShaderEditor.cpp:704
Texture * _currFrame
Content texture indirection.
Definition: ShaderEditor.hpp:110
void draw() override
Definition: ShaderEditor.cpp:184
~ShaderEditor() override
Definition: ShaderEditor.cpp:677
Texture _perlin
Random 2D RGBA periodic Perlin noise in [0,1].
Definition: ShaderEditor.hpp:121
void loadShader(const std::string &path)
Definition: ShaderEditor.cpp:687
void update() override
Definition: ShaderEditor.cpp:295
Texture * _prevFrame
Content texture indirection.
Definition: ShaderEditor.hpp:111
Program * _passthrough
Passthrough program.
Definition: ShaderEditor.hpp:116
std::vector< VecOption > _vectors
Predefined vector parameters.
Definition: ShaderEditor.hpp:130
std::string reload(const std::string &shaderPath, bool syncUniforms)
Definition: ShaderEditor.cpp:657
std::string _compilationLog
Compilation log, will be displayed in a fixed panel if not empty.
Definition: ShaderEditor.hpp:140
std::string _shaderName
Name of the current shader (for display).
Definition: ShaderEditor.hpp:114
void displayUniforms(uint columnsCount)
Definition: ShaderEditor.cpp:550
const Texture * _fallbackTex
Display texture for non-2D inputs.
Definition: ShaderEditor.hpp:125
LayoutMode
GUI layout options.
Definition: ShaderEditor.hpp:102
@ VERTICAL
Panel at the bottom, result at the top.
@ FREEFORM
Panels can be freely moved around.
@ HORIZONTAL
Panel to the left, result to the right.
LayoutMode _layout
The GUI panel layout.
Definition: ShaderEditor.hpp:139
void resize() override
Definition: ShaderEditor.cpp:694
std::vector< const Texture * > _textures
List of all predefined textures.
Definition: ShaderEditor.hpp:119
void handleShortcuts()
Definition: ShaderEditor.cpp:509
std::string _shaderPath
Path of the current shader on disk.
Definition: ShaderEditor.hpp:113
bool _paused
Should time/frame count flow.
Definition: ShaderEditor.hpp:136
std::vector< IntOption > _integers
Predefined integer parameters.
Definition: ShaderEditor.hpp:128
double _currentTime
Current time.
Definition: ShaderEditor.hpp:134
std::unique_ptr< Program > _currProgram
Current shader program.
Definition: ShaderEditor.hpp:115
std::string generateParametersString(const std::string &prefix, bool exportValues)
Definition: ShaderEditor.cpp:771
Texture _noise3D
Random 3D RGBA uniform noise in [0,1].
Definition: ShaderEditor.hpp:123
bool _windowed
Should the result be displayed in a subwindow.
Definition: ShaderEditor.hpp:138
Represents a texture containing one or more images, stored on the CPU and/or GPU.
Definition: Texture.hpp:12
Represent an OS window and its associated rendering context.
Definition: Window.hpp:14
Boolean flag parameter.
Definition: ShaderEditor.hpp:70
bool value
Uniform value.
Definition: ShaderEditor.hpp:72
std::string name
Uniform name.
Definition: ShaderEditor.hpp:71
RGB Color parameter.
Definition: ShaderEditor.hpp:96
glm::vec3 value
Uniform value.
Definition: ShaderEditor.hpp:98
std::string name
Uniform name.
Definition: ShaderEditor.hpp:97
Float parameter.
Definition: ShaderEditor.hpp:82
float value
Uniform value.
Definition: ShaderEditor.hpp:84
std::string name
Uniform name.
Definition: ShaderEditor.hpp:83
float min
Minimum possible value.
Definition: ShaderEditor.hpp:85
float max
Maximum possible value.
Definition: ShaderEditor.hpp:86
Integer parameter.
Definition: ShaderEditor.hpp:76
std::string name
Uniform name.
Definition: ShaderEditor.hpp:77
int value
Uniform value.
Definition: ShaderEditor.hpp:78
4D Vector parameter.
Definition: ShaderEditor.hpp:90
glm::vec4 value
Uniform value.
Definition: ShaderEditor.hpp:92
std::string name
Uniform name.
Definition: ShaderEditor.hpp:91