shady icon indicating copy to clipboard operation
shady copied to clipboard

(QOL) Mapping shader as a sampler2D texture buffer not implemented for OnScreenEngine, does work on others

Open Tremeschin opened this issue 4 years ago • 4 comments

First of all,

  • [x] I have read on the README.md that NOTE: Buffer support is not very well tested, your mileage may vary.

.. however I really need this (sorta).

Context

I'm coding a sorta "video editor" / layers compositor for music visualization and having layers is essential to this task, not only I can separate the elements but apply effects on each and individually.

Issue / reproducing

I tried manually to set up two shaders with almost the same code called layer1.glsl and layer2.glsl:

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = fragCoord.xy / iResolution.xy;
    fragColor = vec4(0.0, 0.0, uv.y, 1);
}

The only difference was that layer2.glsl returns fragColor = vec4(uv.x, 0.0, 0.0, 1); so I could mix the two with some textureLod method and expect a purple at top right corder, black bottom left, red bottom right and blue top left by adding each other's vec4 pixel_color.

However either by defining on the layer2.glsl file the map buffer with:

#pragma map layer1=buffer:/path/to/layer1.glsl;1280x720

Or by giving to the CLI: ./shady -i layer2.glsl -g 1280x720 -map "layer1=buffer:/path/to/layer1.glsl;1280x720"

It just didn't work, outputting the following error:

Error reloading environment: failed to call eglCreateContext, edit: which ended up being a bug on the code where the GL version wasn't being passed properly to the OnScreenEngine render method.

What I tried

See next comments, edited this one for consistency

Tremeschin avatar Jan 04 '21 07:01 Tremeschin

Got some progress on this, the OnScreenEngine glVersion was zero in this line, looks like you forgot to initialize the engine's glVersion variable here :p, adding glVersion: glVersion, to the struct initialization fixes this gl versioning and creates the shader with the right glVersion, however getting pixels out of this back buffer is all black (not being rasterized?).. will report back eny extra progress


Edit: oof, is this really implemented? I found this on environment.go:

// SubBuffers contains the render output for each environment returned by
// SubEnvironments as a textureID.
SubBuffers map[string]uint32

But on renderer.go specifically on this line it is marked as TODO :(?

Tremeschin avatar Jan 04 '21 21:01 Tremeschin

That TODO is for the OnScreenEngine, if you render to stdout or files you will not encounter that.

polyfloyd avatar Jan 05 '21 20:01 polyfloyd

That TODO is for the OnScreenEngine, if you render to stdout or files you will not encounter that.

Oh I see, I was very distracted by getting instant feedback on code I was only rendering to files for showing a few friends some progress, didn't cross my mind trying that or peeking at the implementation for the non- on screen render methods. I think I'll use FFplay then to also have this instant feedback on the shaders for the time being.

Will edit the previous comments to make it more concise also. Any plans on implementing it for OnScreenEngine? I'm not in a hurry as my target are rendered videos anyways :p

Tremeschin avatar Jan 05 '21 22:01 Tremeschin

No, I have no plans to implement it. I would like to work on some new stuff so Shady is going to take a backseat

polyfloyd avatar Jan 05 '21 22:01 polyfloyd