Changeset View
Standalone View
source/blender/draw/engines/eevee_next/shaders/eevee_film_cryptomatte_post_comp.glsl
| #pragma BLENDER_REQUIRE(common_math_lib.glsl) | #pragma BLENDER_REQUIRE(common_math_lib.glsl) | ||||
| #define CRYPTOMATTE_LEVELS_MAX 16 | #define CRYPTOMATTE_LEVELS_MAX 16 | ||||
| void cryptomatte_load_samples(ivec2 texel, int layer, out vec2 samples[CRYPTOMATTE_LEVELS_MAX]) | void cryptomatte_load_samples(ivec2 texel, int layer, out vec2 samples[CRYPTOMATTE_LEVELS_MAX]) | ||||
| { | { | ||||
| int pass_len = divide_ceil(cryptomatte_samples_per_layer, 2); | int pass_len = divide_ceil(cryptomatte_samples_per_layer, 2); | ||||
| int layer_id = layer * pass_len; | int layer_id = layer * pass_len; | ||||
fclem: Would using a struct instead fix the issue of the reference syntax ?
```
struct… | |||||
Not Done Inline Actionsyes, using struct syntax would allow the conventional out type name syntax replacement to work. Pass by reference detection and replacement for array types is a little more expensive and increases the cost of GLSL -> MSL translation. I can potentially add this, though the existing replacement is able to just perform character replacement, which is cheap. Given the syntax requirements for pass by reference of arrays, it may be a little more complex. replace_outvars in mtl_shader_generator handles this and https://developer.blender.org/D17033 optimizes a number of these functions, so the overhead may not be as significant with the optimizations to the original replacement function. Could possibly get the replacement code to replace the following: out vec2 samples[CRYPTOMATTE_LEVELS_MAX] with: #define OUT(type, name, array) thread type(&name)[array] OUT(vec2,samples,CRYPTOMATTE_LEVELS_MAX) or THD(vec2,samples, CRYPTOMATTE_LEVELS_MAX) That should still allow for character replacement (without resizing the string), and should be fairly straightforward to implement. So long as there is no risk of Macro reuse. MichaelPW: yes, using struct syntax would allow the conventional `out type name` syntax replacement to… | |||||
| /* Read all samples from the cryptomatte layer. */ | /* Read all samples from the cryptomatte layer. */ | ||||
| for (int p = 0; p < pass_len; p++) { | for (int p = 0; p < pass_len; p++) { | ||||
| vec4 pass_sample = imageLoad(cryptomatte_img, ivec3(texel, p + layer_id)); | vec4 pass_sample = imageLoad(cryptomatte_img, ivec3(texel, p + layer_id)); | ||||
| samples[p * 2] = pass_sample.xy; | samples[p * 2] = pass_sample.xy; | ||||
| samples[p * 2 + 1] = pass_sample.zw; | samples[p * 2 + 1] = pass_sample.zw; | ||||
| } | } | ||||
| for (int i = pass_len * 2; i < CRYPTOMATTE_LEVELS_MAX; i++) { | for (int i = pass_len * 2; i < CRYPTOMATTE_LEVELS_MAX; i++) { | ||||
| samples[i] = vec2(0.0); | samples[i] = vec2(0.0); | ||||
| Show All 22 Lines | |||||
| } | } | ||||
| void cryptomatte_normalize_weight(float total_weight, inout vec2 samples[CRYPTOMATTE_LEVELS_MAX]) | void cryptomatte_normalize_weight(float total_weight, inout vec2 samples[CRYPTOMATTE_LEVELS_MAX]) | ||||
| { | { | ||||
| for (int i = 0; i < CRYPTOMATTE_LEVELS_MAX; i++) { | for (int i = 0; i < CRYPTOMATTE_LEVELS_MAX; i++) { | ||||
| samples[i].y /= total_weight; | samples[i].y /= total_weight; | ||||
| } | } | ||||
| } | } | ||||
| void cryptomatte_store_samples(ivec2 texel, int layer, in vec2 samples[CRYPTOMATTE_LEVELS_MAX]) | void cryptomatte_store_samples(ivec2 texel, int layer, vec2 samples[CRYPTOMATTE_LEVELS_MAX]) | ||||
| { | { | ||||
| int pass_len = divide_ceil(cryptomatte_samples_per_layer, 2); | int pass_len = divide_ceil(cryptomatte_samples_per_layer, 2); | ||||
| int layer_id = layer * pass_len; | int layer_id = layer * pass_len; | ||||
| /* Store samples back to the cryptomatte layer. */ | /* Store samples back to the cryptomatte layer. */ | ||||
| for (int p = 0; p < pass_len; p++) { | for (int p = 0; p < pass_len; p++) { | ||||
| vec4 pass_sample; | vec4 pass_sample; | ||||
| pass_sample.xy = samples[p * 2]; | pass_sample.xy = samples[p * 2]; | ||||
| Show All 21 Lines | |||||
Would using a struct instead fix the issue of the reference syntax ?
struct CryptoMatteSamples { vec2 samples[CRYPTOMATTE_LEVELS_MAX] };