Is it possible to augment "jit.gl.render to_texture" precision from "char" to "float32"?


    May 11 2018 | 10:29 am
    Hi everybody, I want to render the frame buffer into a texture using the "to_texture" message of jit.gl.render. However I need a precision of float32 or float16, but I'm getting only a texture of type "char" out of the render. Is it possible to augment that precision? Thanks!

    • May 11 2018 | 2:19 pm
      nope, to_texture is old technology. the recommended approach is capture with jit.gl.node (or jit.world). any reason why that won't work for you?
    • May 12 2018 | 10:49 am
      Thanks for your answer Rob. Yes, that won't work for me because I need to render the depth of some objects into a texture and in the same frame access that texture from a shader attached to another object. I've experimented and discovered that I cannot do that, the texture will be always relative to the past frame. Here's an image of the setup I wish to accomplice:
      And here is an example patch. Thank you for any help! 
      https://www.dropbox.com/s/0y0m7bzsnobekwx/depth_comparison_example.zip?dl=0 
    • May 14 2018 | 7:00 pm
      can you delay everything by one frame, and copy the depth texture into a slab that you use in the next frame pass?
    • May 15 2018 | 5:48 pm
      This looks like the right approach Rob, but how can I delay everything by one frame in the context of jit.gl.node?
    • May 15 2018 | 7:46 pm
      hey federico, before we go much further, i want to make sure you've seen the "pass.rebuild.depth" example file (and mrt.depth.jxs shader). this might be some functionality you are looking for. here's a more basic example:
      in any case, your patch doesn't run for me due to shader errors that I assume are the result of lack of driver support for certain glsl language features. can you explain what you need using the patch below. here the depth values of objects in a node are used as the diffuse values for another objects's shading.
    • May 15 2018 | 11:04 pm
      Thanks so much Rob! I've seen the pass.rebuild, and it's really super cool. I'm not sure it can help me with this particular issue but I'll definitely use it in the future. But maybe I'm wrong, maybe I can use it also now, have to experiment with it. The second patch indeed seems to work as expected, using the depth from the same frame. In my patch however I'm accessing the depth from a texture inside the "depth_comparison" shader, and this seems to give me the texture from the previous frame. If you tell me which errors you get I can strip the shader and keep only the bare bone example. Thank you again
    • May 16 2018 | 1:36 am
      errors below, not sure if it's worth sorting through. I imagine the main culprit is the "no available implicit conversion" error.
      if i understand correctly the problem, you want to pass the depth texture from a group of objects in rendering another object, but both objects are in the same node.
      i guess my suggestion is to bind the "renders-depth" objects and the "needs-depth" objects to separate nodes.
      node A (@layer 1) draws the "renders-depth" objects and outputs the depth texture. node B (@layer 2) draws "needs-depth" with the depth values from node A.
      AFAIK, that should work without a delayed frame. the layer attribute will ensure that A draws first, and that B's depth texture is up to date.
      jit.gl.shader: -- START GLSL INFO LOG: vp -- ERROR: 0:13: Left-hand-side of assignment must not be read-only jit.gl.shader: -- END GLSL INFO LOG: vp -- jit.gl.shader: GLSL program failed to compile. jit.gl.shader: -- START GLSL INFO LOG: fp -- ERROR: 0:85: Incompatible types in initialization (and no available implicit conversion) ERROR: 0:88: Use of undeclared identifier 'intersect' ERROR: 0:94: Incompatible types in initialization (and no available implicit conversion) ERROR: 0:96: Incompatible types in initialization (and no available implicit conversion) ERROR: 0:101: Use of undeclared identifier 'lightDir' ERROR: 0:104: Use of undeclared identifier 'intensity' ERROR: 0:106: Use of undeclared identifier 'lightDir' ERROR: 0:106: Use of undeclared identifier 'eye' ERROR: 0:108: Use of undeclared identifier 'h' ERROR: 0:109: Use of undeclared identifier 'intSpec' ERROR: 0:112: Use of undeclared identifier 'intensity' ERROR: 0:114: Use of undeclared identifier 'lightColor' ERROR: 0:114: Use of undeclared identifier 'intersect' ERROR: 0:116: Use of undeclared identifier 'niceColor' jit.gl.shader: -- END GLSL INFO LOG: fp -- jit.gl.shader: GLSL program failed to compile. jit.gl.shader: -- START GLSL INFO LOG: fp -- ERROR: 0:80: Incompatible types in initialization (and no available implicit conversion) ERROR: 0:82: Incompatible types in initialization (and no available implicit conversion) ERROR: 0:87: Use of undeclared identifier 'lightDir' ERROR: 0:90: Use of undeclared identifier 'intensity' ERROR: 0:92: Use of undeclared identifier 'lightDir' ERROR: 0:92: Use of undeclared identifier 'eye' ERROR: 0:94: Use of undeclared identifier 'h' ERROR: 0:95: Use of undeclared identifier 'intSpec' ERROR: 0:98: Use of undeclared identifier 'intensity' jit.gl.shader: -- END GLSL INFO LOG: fp -- jit.gl.shader: GLSL program failed to compile. jit.gl.gridshape: -- START GLSL INFO LOG: fp -- ERROR: 0:80: Incompatible types in initialization (and no available implicit conversion) ERROR: 0:82: Incompatible types in initialization (and no available implicit conversion) ERROR: 0:87: Use of undeclared identifier 'lightDir' ERROR: 0:90: Use of undeclared identifier 'intensity' ERROR: 0:92: Use of undeclared identifier 'lightDir' ERROR: 0:92: Use of undeclared identifier 'eye' ERROR: 0:94: Use of undeclared identifier 'h' ERROR: 0:95: Use of undeclared identifier 'intSpec' ERROR: 0:98: Use of undeclared identifier 'intensity' jit.gl.gridshape: -- END GLSL INFO LOG: fp -- jit.gl.gridshape: jit.gl.shader: GLSL program failed to compile. jit.gl.gridshape: -- START GLSL INFO LOG: fp -- ERROR: 0:85: Incompatible types in initialization (and no available implicit conversion) ERROR: 0:88: Use of undeclared identifier 'intersect' ERROR: 0:94: Incompatible types in initialization (and no available implicit conversion) ERROR: 0:96: Incompatible types in initialization (and no available implicit conversion) ERROR: 0:101: Use of undeclared identifier 'lightDir' ERROR: 0:104: Use of undeclared identifier 'intensity' ERROR: 0:106: Use of undeclared identifier 'lightDir' ERROR: 0:106: Use of undeclared identifier 'eye' ERROR: 0:108: Use of undeclared identifier 'h' ERROR: 0:109: Use of undeclared identifier 'intSpec' ERROR: 0:112: Use of undeclared identifier 'intensity' ERROR: 0:114: Use of undeclared identifier 'lightColor' ERROR: 0:114: Use of undeclared identifier 'intersect' ERROR: 0:116: Use of undeclared identifier 'niceColor' jit.gl.gridshape: -- END GLSL INFO LOG: fp -- jit.gl.gridshape: jit.gl.shader: GLSL program failed to compile.
    • May 16 2018 | 10:22 am
      Thanks a lot Rob! Indeed the method of using two nodes gives me no frame delay. The only problem now is that the depth doesn't get sorted in the right way. Could this be because of how I'm writing the depth in the shaders? And how does it work with blending modes in the case the objects are drawn by two different nodes? Thanks again!
      Here's a picture of what I get now
    • May 16 2018 | 9:18 pm
      i would set each node's erase_color to 0 0 0 0 and then you can use the default alpha blending.
    • May 16 2018 | 9:58 pm
      The only thing is that I would like the sphere still not to be rendered on top of other objects.
    • May 17 2018 | 12:09 am
      well that's what the depth rebuilder is supposed to take care of. might take some tweaking to get it to work in your particular system, but I believe the functionality is there.
    • May 31 2018 | 10:53 am
      After a bit of time I'm back on this patch, that I still couldn't solve in the right way. It looks like that when capturing objects on a node with the @capture attribute, they are not going to be rendered inside the jit.gl.pass @depth videoplane. Is this correct?
    • May 31 2018 | 3:56 pm
      not sure what you're referring to exactly.
      when a jit.gl.pass subpass tag has a depth ouput attribute (e.g. as in the @fxname depth builtin effect), the pass is drawn to its gl.node's parent context framebuffer and depthbuffer, rather than output as a texture. if you check out the source code of mrt.depth.jxs, you see it writes to the gl_FragColor and gl_FragDepth locations. so it is effectively redrawing the geometry, but also allows you to perform post-processing effects on it. note that the jit.gl.node itself is still outputting the captured textures (color and normals+depth) that you can do whatever you want with.
      you can tweak both the depth.jxp pass file and the mrt.depth.jxs shader file to your needs. if you specify <subpass file="yourfile.jxs" output="DEPTH"> in the jxp, then the output is written to the parent context framebuffer/depthbuffer, as opposed to it's own textures as is the case with non-depth-output-enabled pass effects. i tried to reorganize the patch to better illustrate the technique. hope this makes it clearer.
    • May 31 2018 | 5:07 pm
      You are the best Rob! I solved it with jit.gl.pass @fxname depth. However I get a slightly worst framerate. Is this because the objects are being redrawn by jit.gl.pass?
    • May 31 2018 | 10:59 pm
      ¯\_(ツ)_/¯
    • Jun 01 2018 | 9:14 am
      Or jit.gl.pass simply reorganizes them all before getting drawn? I'm sorry for all these questions, but you are the only person that can answer this : /
    • Jun 04 2018 | 7:13 pm
      the depth pass effect has one sub-pass, each pass effect sub-pass is full drawing pass of the node's scene objects using the specified sub-pass shader. can't really speculate further without seeing the exact patches that you are comparing.