6#include "graphics/shaders/mesh3d_toon_vert_spv.inc"
7#include "stylize/shaders/chromatic_post_frag_spv.inc"
8#include "stylize/shaders/dissolve_mesh_frag_spv.inc"
9#include "stylize/shaders/glitch_analog_post_frag_spv.inc"
10#include "stylize/shaders/glitch_block_post_frag_spv.inc"
11#include "stylize/shaders/glitch_wave_post_frag_spv.inc"
12#include "stylize/shaders/grain_post_frag_spv.inc"
13#include "stylize/shaders/kuwahara_post_frag_spv.inc"
14#include "stylize/shaders/kuwahara_aniso_post_frag_spv.inc"
15#include "stylize/shaders/dog_post_frag_spv.inc"
16#include "stylize/shaders/sharpen_post_frag_spv.inc"
17#include "stylize/shaders/neon_edge_post_frag_spv.inc"
18#include "stylize/shaders/hologram_mesh_frag_spv.inc"
19#include "stylize/shaders/slash_mesh_frag_spv.inc"
20#include "stylize/shaders/ember_mesh_frag_spv.inc"
21#include "stylize/shaders/aura_mesh_frag_spv.inc"
22#include "stylize/shaders/rim_mesh_frag_spv.inc"
23#include "stylize/shaders/snow_mesh_frag_spv.inc"
24#include "stylize/shaders/vignette_post_frag_spv.inc"
34const StyleDefinition kMeshEffects[] = {
45const StyleDefinition kPostEffects[] = {
60const StyleParameterDesc kRimParams[] = {
61 {
"colorR", 0.4f, 0.f, 2.f}, {
"colorG", 0.6f, 0.f, 2.f}, {
"colorB", 1.f, 0.f, 2.f},
62 {
"rimPower", 3.f, 0.1f, 16.f}, {
"rimIntensity", 1.f, 0.f, 4.f}, {
"rimMix", 1.f, 0.f, 1.f},
63 {
"ambientStrength", 0.15f, 0.f, 1.f}, {
"baseLight", 1.f, 0.f, 3.f},
66const StyleParameterDesc kDissolveParams[] = {
67 {
"amount", 0.5f, 0.f, 1.f}, {
"edgeWidth", 0.1f, 0.01f, 0.5f}, {
"edgeColorR", 1.f, 0.f, 2.f},
68 {
"edgeColorG", 0.5f, 0.f, 2.f}, {
"edgeColorB", 0.1f, 0.f, 2.f}, {
"edgeGlow", 2.f, 0.f, 6.f},
69 {
"noiseScale", 2.f, 0.1f, 16.f}, {
"hardness", 0.5f, 0.f, 1.f},
72const StyleParameterDesc kHologramParams[] = {
73 {
"colorR", 0.2f, 0.f, 2.f}, {
"colorG", 0.9f, 0.f, 2.f}, {
"colorB", 1.f, 0.f, 2.f},
74 {
"fresnelStrength", 1.f, 0.f, 4.f}, {
"scanDensity", 8.f, 1.f, 48.f}, {
"scanIntensity", 0.5f, 0.f, 1.f},
75 {
"flicker", 0.3f, 0.f, 1.f}, {
"alphaBase", 0.35f, 0.f, 1.f}, {
"glitchAmplitude", 0.15f, 0.f, 1.f},
78const StyleParameterDesc kSnowParams[] = {
79 {
"snowAmount", 0.9f, 0.f, 1.f}, {
"snowHardness", 0.5f, 0.f, 1.f}, {
"snowColorR", 0.93f, 0.f, 1.f},
80 {
"snowColorG", 0.95f, 0.f, 1.f}, {
"snowColorB", 0.98f, 0.f, 1.f}, {
"noiseScale", 3.f, 0.1f, 16.f},
81 {
"snowHeight", 0.f, -1000.f, 1000.f}, {
"heightFade", 4.f, 0.1f, 100.f},
84const StyleParameterDesc kSlashParams[] = {
85 {
"coreR", 0.85f, 0.f, 2.f}, {
"coreG", 0.95f, 0.f, 2.f}, {
"coreB", 1.0f, 0.f, 2.f},
86 {
"edgeR", 1.0f, 0.f, 2.f}, {
"edgeG", 0.4f, 0.f, 2.f}, {
"edgeB", 0.2f, 0.0f, 2.f},
87 {
"intensity", 1.6f, 0.f, 4.f}, {
"width", 0.06f, 0.005f, 0.3f}, {
"softness", 0.12f, 0.001f, 0.5f},
88 {
"noiseScale", 4.f, 0.1f, 20.f}, {
"time", 0.f, 0.f, 120.f}, {
"speed", 0.9f, 0.f, 3.f},
89 {
"flowWarp", 0.35f, 0.f, 2.f}, {
"edgeDistortion", 0.08f, 0.f, 0.5f},
90 {
"depthSoftness", 0.004f, 0.0001f, 0.1f}, {
"intersectionWidth", 0.006f, 0.0001f, 0.1f},
91 {
"intersectionGlow", 0.8f, 0.f, 4.f},
92 {
"refractionStrength", 0.f, 0.f, 1.f},
95const StyleParameterDesc kEmberParams[] = {
96 {
"coreR", 1.0f, 0.f, 2.f}, {
"coreG", 0.35f, 0.f, 2.f}, {
"coreB", 0.08f, 0.f, 2.f},
97 {
"flareR", 1.0f, 0.f, 2.f}, {
"flareG", 0.58f, 0.f, 2.f}, {
"flareB", 0.2f, 0.f, 2.f},
98 {
"burnAmount", 0.68f, 0.f, 1.f}, {
"flicker", 0.5f, 0.f, 1.f}, {
"noiseScale", 2.5f, 0.1f, 16.f},
99 {
"hardness", 0.6f, 0.f, 1.f}, {
"time", 0.f, 0.f, 120.f},
102const StyleParameterDesc kAuraParams[] = {
103 {
"auraR", 0.24f, 0.f, 2.f}, {
"auraG", 0.62f, 0.f, 2.f}, {
"auraB", 1.f, 0.f, 2.f},
104 {
"pulse", 1.1f, 0.f, 4.f}, {
"edge", 2.f, 0.1f, 8.f}, {
"radius", 0.65f, 0.1f, 2.f},
105 {
"noiseScale", 3.f, 0.1f, 16.f}, {
"time", 0.f, 0.f, 120.f}, {
"intensity", 1.1f, 0.f, 4.f},
108const StyleParameterDesc kVignetteParams[] = {
109 {
"strength", 0.5f, 0.f, 1.f}, {
"smoothness", 0.5f, 0.01f, 1.f}, {
"roundness", 0.5f, 0.f, 1.f},
110 {
"colorR", 0.f, 0.f, 1.f}, {
"colorG", 0.f, 0.f, 1.f}, {
"colorB", 0.f, 0.f, 1.f},
113const StyleParameterDesc kChromaticParams[] = {
114 {
"strength", 0.3f, 0.f, 1.f},
115 {
"radialMix", 1.f, 0.f, 1.f},
116 {
"rgbSplit", 0.5f, 0.f, 1.f},
119const StyleParameterDesc kGrainParams[] = {
120 {
"strength", 0.15f, 0.f, 1.f},
121 {
"grainSize", 4.f, 1.f, 32.f},
122 {
"lumaAmount", 0.7f, 0.f, 1.f},
123 {
"colorAmount", 0.1f, 0.f, 1.f},
128const StyleParameterDesc kGlitchAnalogParams[] = {
129 {
"strength", 1.f, 0.f, 1.f}, {
"scanLineJitter", 0.f, 0.f, 1.f},
130 {
"verticalJump", 0.f, 0.f, 1.f}, {
"horizontalShake", 0.f, 0.f, 1.f},
131 {
"colorDrift", 0.f, 0.f, 1.f}, {
"time", 0.f, 0.f, 120.f},
136const StyleParameterDesc kGlitchBlockParams[] = {
137 {
"strength", 1.f, 0.f, 1.f}, {
"intensity", 0.f, 0.f, 1.f}, {
"time", 0.f, 0.f, 120.f},
138 {
"cellCountX", 64.f, 4.f, 256.f}, {
"cellCountY", 32.f, 4.f, 256.f},
142const StyleParameterDesc kGlitchWaveParams[] = {
143 {
"strength", 1.f, 0.f, 1.f}, {
"amount", 0.f, 0.f, 2.f}, {
"frequency", 5.f, 0.f, 50.f},
144 {
"rgbSplit", 20.f, 0.f, 50.f}, {
"speed", 0.25f, 0.f, 1.f}, {
"direction", 0.f, 0.f, 1.f},
145 {
"infiniteFreq", 0.f, 0.f, 1.f}, {
"time", 0.f, 0.f, 120.f},
150const StyleParameterDesc kKuwaharaParams[] = {
151 {
"strength", 0.f, 0.f, 1.f},
152 {
"kernelSize", 3.f, 1.f, 8.f},
157const StyleParameterDesc kKuwaharaAnisoParams[] = {
158 {
"strength", 0.f, 0.f, 1.f}, {
"kernelSize", 4.f, 2.f, 8.f}, {
"sharpness", 8.f, 1.f, 18.f},
159 {
"hardness", 8.f, 1.f, 100.f}, {
"alpha", 1.f, 0.01f, 2.f}, {
"zeroCrossing", 0.58f, 0.01f, 2.f},
160 {
"zeta", 0.f, 0.f, 3.f},
165const StyleParameterDesc kDogParams[] = {
166 {
"strength", 0.f, 0.f, 1.f}, {
"kernelSize", 5.f, 1.f, 8.f}, {
"sigma", 2.f, 0.1f, 5.f},
167 {
"k", 1.6f, 0.1f, 5.f}, {
"tau", 1.f, 0.01f, 5.f}, {
"thresholding", 1.f, 0.f, 1.f},
168 {
"useTanh", 0.f, 0.f, 1.f}, {
"phi", 1.f, 0.01f, 100.f}, {
"threshold", 0.005f, -1.f, 1.f},
169 {
"invert", 0.f, 0.f, 1.f},
174const StyleParameterDesc kSharpenParams[] = {
175 {
"strength", 0.f, 0.f, 1.f},
176 {
"amount", 0.5f, 0.f, 1.f},
181const StyleParameterDesc kNeonEdgeParams[] = {
182 {
"strength", 0.f, 0.f, 1.f}, {
"edgeWidth", 1.f, 0.05f, 5.f}, {
"neonFade", 1.f, 0.1f, 1.f},
183 {
"brightness", 1.f, 0.2f, 2.f}, {
"backgroundFade", 0.f, 0.f, 1.f},
184 {
"bgR", 0.f, 0.f, 1.f}, {
"bgG", 0.f, 0.f, 1.f}, {
"bgB", 0.f, 0.f, 1.f},
187const StyleDefinition* findMesh(
const std::string& style) {
188 for (
const auto&
d : kMeshEffects)
189 if (style ==
d.
id) return &
d;
192const StyleDefinition* findPost(
const std::string& style) {
193 for (
const auto&
d : kPostEffects)
194 if (style ==
d.
id) return &
d;
199const StyleParameterDesc* paramAt(
const StyleParameterDesc (&arr)[N],
int index) {
200 return index < 0 || index >= int(N) ? nullptr : &arr[size_t(
index)];
203int meshParamCount(
const std::string& style) {
204 if (style ==
"rim")
return int(
sizeof(kRimParams) /
sizeof(kRimParams[0]));
205 if (style ==
"dissolve")
return int(
sizeof(kDissolveParams) /
sizeof(kDissolveParams[0]));
206 if (style ==
"hologram")
return int(
sizeof(kHologramParams) /
sizeof(kHologramParams[0]));
207 if (style ==
"snow")
return int(
sizeof(kSnowParams) /
sizeof(kSnowParams[0]));
208 if (style ==
"slash")
return int(
sizeof(kSlashParams) /
sizeof(kSlashParams[0]));
209 if (style ==
"ember")
return int(
sizeof(kEmberParams) /
sizeof(kEmberParams[0]));
210 if (style ==
"aura")
return int(
sizeof(kAuraParams) /
sizeof(kAuraParams[0]));
213const StyleParameterDesc* meshParamAt(
const std::string& style,
int index) {
214 if (style ==
"rim")
return paramAt(kRimParams,
index);
215 if (style ==
"dissolve")
return paramAt(kDissolveParams,
index);
216 if (style ==
"hologram")
return paramAt(kHologramParams,
index);
217 if (style ==
"snow")
return paramAt(kSnowParams,
index);
218 if (style ==
"slash")
return paramAt(kSlashParams,
index);
219 if (style ==
"ember")
return paramAt(kEmberParams,
index);
220 if (style ==
"aura")
return paramAt(kAuraParams,
index);
223int postParamCount(
const std::string& style) {
224 if (style ==
"vignette")
return int(
sizeof(kVignetteParams) /
sizeof(kVignetteParams[0]));
225 if (style ==
"chromatic")
return int(
sizeof(kChromaticParams) /
sizeof(kChromaticParams[0]));
226 if (style ==
"grain")
return int(
sizeof(kGrainParams) /
sizeof(kGrainParams[0]));
227 if (style ==
"glitchAnalog")
return int(
sizeof(kGlitchAnalogParams) /
sizeof(kGlitchAnalogParams[0]));
228 if (style ==
"glitchBlock")
return int(
sizeof(kGlitchBlockParams) /
sizeof(kGlitchBlockParams[0]));
229 if (style ==
"glitchWave")
return int(
sizeof(kGlitchWaveParams) /
sizeof(kGlitchWaveParams[0]));
230 if (style ==
"kuwahara")
return int(
sizeof(kKuwaharaParams) /
sizeof(kKuwaharaParams[0]));
231 if (style ==
"kuwaharaAniso")
return int(
sizeof(kKuwaharaAnisoParams) /
sizeof(kKuwaharaAnisoParams[0]));
232 if (style ==
"dog")
return int(
sizeof(kDogParams) /
sizeof(kDogParams[0]));
233 if (style ==
"sharpen")
return int(
sizeof(kSharpenParams) /
sizeof(kSharpenParams[0]));
234 if (style ==
"neonEdge")
return int(
sizeof(kNeonEdgeParams) /
sizeof(kNeonEdgeParams[0]));
237const StyleParameterDesc* postParamAt(
const std::string& style,
int index) {
238 if (style ==
"vignette")
return paramAt(kVignetteParams,
index);
239 if (style ==
"chromatic")
return paramAt(kChromaticParams,
index);
240 if (style ==
"grain")
return paramAt(kGrainParams,
index);
241 if (style ==
"glitchAnalog")
return paramAt(kGlitchAnalogParams,
index);
242 if (style ==
"glitchBlock")
return paramAt(kGlitchBlockParams,
index);
243 if (style ==
"glitchWave")
return paramAt(kGlitchWaveParams,
index);
244 if (style ==
"kuwahara")
return paramAt(kKuwaharaParams,
index);
245 if (style ==
"kuwaharaAniso")
return paramAt(kKuwaharaAnisoParams,
index);
246 if (style ==
"dog")
return paramAt(kDogParams,
index);
247 if (style ==
"sharpen")
return paramAt(kSharpenParams,
index);
248 if (style ==
"neonEdge")
return paramAt(kNeonEdgeParams,
index);
254void bindParamArray(graphics::Shader*
shader,
const std::string& style,
bool mesh) {
256 int n =
mesh ? meshParamCount(style) : postParamCount(style);
257 for (
int i = 0; i <
n; ++i) {
258 const StyleParameterDesc*
d =
mesh ? meshParamAt(style, i) : postParamAt(style, i);
261 shader->sendFloat(
d->id,
d->defaultValue);
265std::vector<uint32_t> copySpv(
const uint32_t* data,
size_t count) {
return std::vector<uint32_t>(data, data +
count); }
269bool isEffectStyle(
const std::string& style) {
return findMesh(style) !=
nullptr || findPost(style) !=
nullptr; }
273 return findPost(style);
277 return int(
sizeof(kMeshEffects) /
sizeof(kMeshEffects[0])) + int(
sizeof(kPostEffects) /
sizeof(kPostEffects[0]));
281 const int meshCount = int(
sizeof(kMeshEffects) /
sizeof(kMeshEffects[0]));
284 if (
index >= 0 &&
index <
int(
sizeof(kPostEffects) /
sizeof(kPostEffects[0])))
return kPostEffects[
index].id;
289 if (findMesh(style))
return meshParamCount(style);
290 return postParamCount(style);
295 return d ?
d->id : std::string{};
300 for (
int i = 0; i <
n; ++i) {
302 if (
d &&
name ==
d->id)
return d;
308 if (findMesh(style))
return meshParamAt(style,
index);
309 return postParamAt(style,
index);
313 bindParamArray(
shader, style,
false);
316 if (style ==
"chromatic" || style ==
"glitchWave" || style ==
"neonEdge") {
317 shader->declareFloat(
"screenW");
318 shader->declareFloat(
"screenH");
319 shader->sendFloat(
"screenW", 256.f);
320 shader->sendFloat(
"screenH", 256.f);
322 if (style ==
"kuwahara" || style ==
"kuwaharaAniso" || style ==
"dog" || style ==
"sharpen") {
323 shader->declareFloat(
"texelW");
324 shader->declareFloat(
"texelH");
325 shader->sendFloat(
"texelW", 1.f / 256.f);
326 shader->sendFloat(
"texelH", 1.f / 256.f);
331 bindParamArray(
shader, style,
true);
335 if (!gfx)
throw eve::Exception(
"createEffectPostShader: null graphics");
336 std::vector<uint32_t>
frag;
337 if (style ==
"vignette")
338 frag = copySpv(vignette_post_frag_spv, vignette_post_frag_spv_count);
339 else if (style ==
"chromatic")
340 frag = copySpv(chromatic_post_frag_spv, chromatic_post_frag_spv_count);
341 else if (style ==
"grain")
342 frag = copySpv(grain_post_frag_spv, grain_post_frag_spv_count);
343 else if (style ==
"glitchAnalog")
344 frag = copySpv(glitch_analog_post_frag_spv, glitch_analog_post_frag_spv_count);
345 else if (style ==
"glitchBlock")
346 frag = copySpv(glitch_block_post_frag_spv, glitch_block_post_frag_spv_count);
347 else if (style ==
"glitchWave")
348 frag = copySpv(glitch_wave_post_frag_spv, glitch_wave_post_frag_spv_count);
349 else if (style ==
"kuwahara")
350 frag = copySpv(kuwahara_post_frag_spv, kuwahara_post_frag_spv_count);
351 else if (style ==
"kuwaharaAniso")
352 frag = copySpv(kuwahara_aniso_post_frag_spv, kuwahara_aniso_post_frag_spv_count);
353 else if (style ==
"dog")
354 frag = copySpv(dog_post_frag_spv, dog_post_frag_spv_count);
355 else if (style ==
"sharpen")
356 frag = copySpv(sharpen_post_frag_spv, sharpen_post_frag_spv_count);
357 else if (style ==
"neonEdge")
358 frag = copySpv(neon_edge_post_frag_spv, neon_edge_post_frag_spv_count);
360 throw eve::Exception(
"createEffectPostShader: not an effect post style '%s'", style.c_str());
363 if (!sh || !sh->
gpuHandle)
throw eve::Exception(
"createEffectPostShader: failed to create '%s'", style.c_str());
369 if (!gfx)
throw eve::Exception(
"createEffectMeshShader: null graphics");
370 std::vector<uint32_t>
frag;
372 frag = copySpv(rim_mesh_frag_spv, rim_mesh_frag_spv_count);
373 else if (style ==
"dissolve")
374 frag = copySpv(dissolve_mesh_frag_spv, dissolve_mesh_frag_spv_count);
375 else if (style ==
"hologram")
376 frag = copySpv(hologram_mesh_frag_spv, hologram_mesh_frag_spv_count);
377 else if (style ==
"snow")
378 frag = copySpv(snow_mesh_frag_spv, snow_mesh_frag_spv_count);
379 else if (style ==
"slash")
380 frag = copySpv(slash_mesh_frag_spv, slash_mesh_frag_spv_count);
381 else if (style ==
"ember")
382 frag = copySpv(ember_mesh_frag_spv, ember_mesh_frag_spv_count);
383 else if (style ==
"aura")
384 frag = copySpv(aura_mesh_frag_spv, aura_mesh_frag_spv_count);
386 throw eve::Exception(
"createEffectMeshShader: not an effect mesh style '%s'", style.c_str());
388 auto vert = copySpv(mesh3d_toon_vert_spv, mesh3d_toon_vert_spv_count);
390 if (!sh || !sh->
gpuHandle)
throw eve::Exception(
"createEffectMeshShader: failed to create '%s'", style.c_str());
EVENGINE_API_FOUNDATION public API.
virtual Shader * newMeshShaderFromSpv(const std::vector< uint32_t > &vertSpv, const std::vector< uint32_t > &fragSpv)=0
Create a Mesh3D custom shader (MeshVertex + Frame UBO + albedo). Empty vert → default mesh3d....
virtual Shader * newShaderFromSpv(const std::vector< uint32_t > &vertSpv, const std::vector< uint32_t > &fragSpv)=0
Create a custom 2D shader from SPIR-V words (vert + frag). Owned by Graphics. Vertex stage may be emp...
void bindEffectMeshUniforms(graphics::Shader *shader, const std::string &style)
Binds effect mesh uniforms.
graphics::Shader * createEffectMeshShader(graphics::Graphics *gfx, const std::string &style)
Creates effect mesh shader.
std::string effectParamName(const std::string &style, int index)
Effect param name.
bool isEffectStyle(const std::string &style)
True when style names one of the ported effect shaders.
graphics::Shader * createEffectPostShader(graphics::Graphics *gfx, const std::string &style)
Creates effect post shader.
const StyleParameterDesc * findEffectParameter(const std::string &style, const std::string &name)
Finds effect parameter.
int effectStyleCount()
Effect style count.
void bindEffectPostUniforms(graphics::Shader *shader, const std::string &style)
Binds effect post uniforms.
std::string effectStyleIdAt(int index)
Effect style id at.
const StyleDefinition * findEffectDefinition(const std::string &style)
Effect-only StyleDefinition lookup, or nullptr when unknown.
int effectParamCount(const std::string &style)
Effect param count.
const StyleParameterDesc * effectParameterAt(const std::string &style, int index)
Effect parameter at.
Immutable capability metadata for one built-in stylization recipe.
Tooling metadata for one user-facing float parameter.