In my processing sketch I am passing textures between two shaders by first drawing into a PGraphics and than passing the PGraphics with the .set function of the shader.
This works fine,but the PGraphics clamps all the texture values between 0 and 255. Is there a way to pass textures between shader without the clamping? So I can also pass negative values?
Hi Welcome to the forum! To be able to use negative values the buffers should be of type floating point, but by default Processing does not provide them. Maybe @kosowski or @neilcsmith know if it’s doable?
I was using some example from shadertoy on fluid simulation. Thanks for the tips, my next idea was indeed to remap things for 0.5/127, lets see if that works :).
float rawget(int x, int y) {
color c=pixel(x, y);
float f=(blue(c)+green(c)/255.0);
if (inverted) f=255-f;
return f;
}
Pretty naive, but works for me, somewhere I also have functions for a 3byte float encoding (good for RGB only pictures), I will dig them up if interested.
Or you could encode them as 32bit native IEEE floats…if you find a worKing way to do that (on Android!) I’d like to know.
There is this modification to Processing’s source for enabling floating point texture, but it breaks some other functionalities.
Besides, I think the PixelFlow library uses floating point textures as well. Although the simplest method would be packing your values into the RGBA channels as @uheinema suggested (note you can use all 4 channels, thus 32 bits available)
For the people that have the same problem with accesing the 32bit buffer texture of a loaded shader.
For me the easiest was to use the Shadertoy class of PixelFlow.
When you render your Shader not to the PGraphics but only apply the shader with toyA.apply(width, height); Than with the toyA.tex.getFloatTextureData() you can get the 32bit floats.
If you render your shader to PGraphics, it doesnt store that 32bit in the texture of the ShaderToy, so nothing comes out of it when you get Texture data.