Weird alpha values while capturing a node in float32

TFL's icon

Hey,
Here is the context: I want to capture a view of a gridshape textured with transparency.
The issue I'm facing is: the alpha output of a [jit.gl.node @capture 1 @type float32] gives values between 0. and 3. while I expect values between 0. and 1. Why that?
In char mode, values goes from 0 to 255 as expected.

Also, if you move the gridshape around +0. - +2. on the z axis, the maximum alpha value start to decrease slowly, while it stays at 255 in char mode. I don't get how the position of a gridshape can alter transparency of its texture, given that in this example, the texture's transparency is either full or null, without intermediary value.

I came to this problem because I use [jit.gl.node @capture 2 @type float32] on a bigger patch, and float32 is necessary in order to get enough precision on the depth channel, but it completely messed up what I want to display as I first built the patch with a char node output. Adding a [clamp 0 1] before any operation on the resulting alpha channel solved the issue but I don't get why I'm getting such difference at the first place.
Any thought?

I guess it's related to blending and/or lighting, but I'm limited with my OpenGL knowledge I think.

Max Patch
Copy patch and select New From Clipboard in Max.

Rob Ramirez's icon

You are analyzing the color texture instead of the normals+depth texture. Simply take the third outlet of the unpack rather than the second:

TFL's icon

I know, sorry if my explanations or the example are not clear.
My issue is about the alpha channel of the color texture, not the normals+depth texture.
"@capture 2", [unpack s s s] and [prepend jit_gl_texture] are remains of the main patch I forgot to clean with the copy-past.
So the example patch is correct and illustrates (not so well, I admit) the issue, which basically is: why is there a difference on the alpha channel of the color texture output from a [jit.gl.node @capture 1] if I set @type char or float32.

Rob Ramirez's icon

aha, apologies. you explained things fine, I just mis-interpreted.

jit.gl.material is simply summing up component color values, including alpha values. Maybe we should do something different here but we don't currently. I believe if you zero out the mat_ambient alpha, you will get something more expected in the final alpha output.

TFL's icon

Thanks for the answer!
I does, but it also alters the alpha relatively to the light direction: shaded parts are made transparent, which I don't want.

Is it possible to customize the shader created by jit.gl.material? I tried to save the shader given when sending "get_gl3_shader" to the gridshape, then specifiying the file with @shader custom_shader.jxs on the jit.gl.gridshape, then deleted the jit.gl.material, but modifying the file does nothing, and when I resend "get_gl3_shader" I just get the default shader.

Max Patch
Copy patch and select New From Clipboard in Max.

TFL's icon

Is it possible to customize the shader created by jit.gl.material?

I just found that I need to instantiate the shader with jit.gl.shader first. However I don't get the same result as with jit.gl.material without tsome tweaking inside of the shader, but I think I can manage it, and it's another topic.