[vtkusers] [vtk-developers] Passing arbitrary float data to a shader

Pato Sandana patricio.sandana at synopsys.com
Wed Feb 20 12:11:29 EST 2019


Hi Patrick,

What you ask is more a GLSL topic than VTK I guess. What you need is the texelFetch() method instead the texture() one. texture() clamps the values to 0-1 extent. texelFetch returns the actual value stored and with floatBitsToInt you can even "encode/decode" integer values if needed.

Hope that helps.

Cheers,
Pato

----------------------------------------------------------------------

Message: 1
Date: Tue, 19 Feb 2019 17:42:04 +0000
From: Patrick Bergeron <pbergeron at spiria.com>
To: Ken Martin <ken.martin at kitware.com>
Cc: "vtk-developers at vtk.org" <vtk-developers at vtk.org>,
	"vtkusers at vtk.org" <vtkusers at vtk.org>
Subject: Re: [vtkusers] [vtk-developers] Passing arbitrary float data
	to a shader through a vtkTexture
Message-ID: <DE6801C0-0DCD-4757-B6B7-6EC26929C194 at spiria.com>
Content-Type: text/plain; charset="utf-8"

Hi Ken

I believe float data in the texture is the full range as long as the underlying VTK data type is float.


I would have assumed so too!  But as per my follow up note I sent just a little while ago, the floats are unfortunately not the full range as they get converted to rgba 8 bit per channel in the vtkOpenGLTexture::Load() function ?- for which I submitted a simple fix to indeed keep the full range.

Just to be clear, I need to pass data to a shader in order to shade a triangle mesh in a particular way. I don?t need to write to a float framebuffer.

The data I need is not pixels and it?s not colors. It?s a float array used for some arbitrary shader computation.

I used to pass these floats as uniform data to the shader but I ran out of uniforms and had to encode this data elsewhere, eg: in an image buffer instead. In my shader I access this data with the glsl function texelFetch() instead of reading a uniform.

Patrick Bergeron

On Feb 19, 2019, at 08:30, Ken Martin <ken.martin at kitware.com<mailto:ken.martin at kitware.com>> wrote:


Two different things here I think

I believe float data in the texture is the full range as long as the underlying VTK data type is float.

The image buffer (pixels that get drawn to) by default is unsigned char normalized 0 to 1. To use float you need a float backed image buffer. Something like

https://urldefense.proofpoint.com/v2/url?u=https-3A__gitlab.kitware.com_vtk_vtk_blob_master_Rendering_OpenGL2_Testing_Cxx_TestFramebufferHDR.cxx&d=DwICAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=RTHchWjhlQtHtkpaYSjNSag78sFhFdYa6LnDJBrNgcw&m=eJsgUc3SPtxFawzKQAvC2axRmCBvC5XtisU7BG-b01Q&s=OXsDLuWRk0bqurZ8S1YpkBj9pIW3dnVnEw8dFtKIEx8&e=

But even with that example in the end the framebuffer will be blitted to screen which is typically an 8bit buffer. But at least in that example you can accumulate etc in floating point all you want prior to that final blit to the screen.




On Mon, Feb 18, 2019 at 7:07 PM Patrick Bergeron <pbergeron at spiria.com<mailto:pbergeron at spiria.com>> wrote:

Hi.


I am trying to pass custom float data to my shader in the form of a vtkTexture which contains VTK_FLOAT data (4 components).


As per the documentation, it appears that float data in the image buffer gets clamped in the 0-1 range, which is a huge problem for me as I'm only getting 0-1 data in the shader: I need the pixel data to be the actual float data (which can be anything, not restricted to any particular range).


How can I do this in VTK ?


Patrick.


_______________________________________________
Powered by https://urldefense.proofpoint.com/v2/url?u=http-3A__www.kitware.com&d=DwICAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=RTHchWjhlQtHtkpaYSjNSag78sFhFdYa6LnDJBrNgcw&m=eJsgUc3SPtxFawzKQAvC2axRmCBvC5XtisU7BG-b01Q&s=2hV0T4ypSq-ERHhId-3ZBxUR0z8CA8opMwr3WW7kyMg&e=<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.kitware.com&d=DwICAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=RTHchWjhlQtHtkpaYSjNSag78sFhFdYa6LnDJBrNgcw&m=eJsgUc3SPtxFawzKQAvC2axRmCBvC5XtisU7BG-b01Q&s=2hV0T4ypSq-ERHhId-3ZBxUR0z8CA8opMwr3WW7kyMg&e=>

Visit other Kitware open-source projects at https://urldefense.proofpoint.com/v2/url?u=http-3A__www.kitware.com_opensource_opensource.html&d=DwICAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=RTHchWjhlQtHtkpaYSjNSag78sFhFdYa6LnDJBrNgcw&m=eJsgUc3SPtxFawzKQAvC2axRmCBvC5XtisU7BG-b01Q&s=bwwTiiU3rScC-V9yRd5uQWuZPIPNOOde4Xfa0Bw_Q6k&e=

Search the list archives at: https://urldefense.proofpoint.com/v2/url?u=http-3A__markmail.org_search_-3Fq-3Dvtk-2Ddevelopers&d=DwICAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=RTHchWjhlQtHtkpaYSjNSag78sFhFdYa6LnDJBrNgcw&m=eJsgUc3SPtxFawzKQAvC2axRmCBvC5XtisU7BG-b01Q&s=yA_HNPLVuk03J-jKrVTI9l0bAEQFLnsi7wnmzCXNv58&e=

Follow this link to subscribe/unsubscribe:
https://urldefense.proofpoint.com/v2/url?u=https-3A__vtk.org_mailman_listinfo_vtk-2Ddevelopers&d=DwICAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=RTHchWjhlQtHtkpaYSjNSag78sFhFdYa6LnDJBrNgcw&m=eJsgUc3SPtxFawzKQAvC2axRmCBvC5XtisU7BG-b01Q&s=5ymapB7shDgmY0MeTYyc5B8KpCGBSxi-cDAjgeHl4qY&e=



--
Ken Martin PhD
Distinguished Engineer
Kitware Inc.
101 East Weaver Street
Carrboro, North Carolina
27510 USA

This communication, including all attachments, contains confidential and legally privileged information, and it is intended only for the use of the addressee.  Access to this email by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, distribution or any action taken in reliance on it is prohibited and may be unlawful. If you received this communication in error please notify us immediately and destroy the original message.  Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://urldefense.proofpoint.com/v2/url?u=https-3A__vtk.org_pipermail_vtkusers_attachments_20190219_8217761e_attachment-2D0001.html&d=DwICAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=RTHchWjhlQtHtkpaYSjNSag78sFhFdYa6LnDJBrNgcw&m=eJsgUc3SPtxFawzKQAvC2axRmCBvC5XtisU7BG-b01Q&s=2miRd-Bw06vNBoogtyqjKzLxCjyqrRx81NM1TMFm-Nc&e=>

------------------------------

Subject: Digest Footer

_______________________________________________
Powered by https://urldefense.proofpoint.com/v2/url?u=http-3A__www.kitware.com&d=DwICAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=RTHchWjhlQtHtkpaYSjNSag78sFhFdYa6LnDJBrNgcw&m=eJsgUc3SPtxFawzKQAvC2axRmCBvC5XtisU7BG-b01Q&s=2hV0T4ypSq-ERHhId-3ZBxUR0z8CA8opMwr3WW7kyMg&e=

Visit other Kitware open-source projects at https://urldefense.proofpoint.com/v2/url?u=http-3A__www.kitware.com_opensource_opensource.html&d=DwICAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=RTHchWjhlQtHtkpaYSjNSag78sFhFdYa6LnDJBrNgcw&m=eJsgUc3SPtxFawzKQAvC2axRmCBvC5XtisU7BG-b01Q&s=bwwTiiU3rScC-V9yRd5uQWuZPIPNOOde4Xfa0Bw_Q6k&e=

Please keep messages on-topic and check the VTK FAQ at: https://urldefense.proofpoint.com/v2/url?u=http-3A__www.vtk.org_Wiki_VTK-5FFAQ&d=DwICAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=RTHchWjhlQtHtkpaYSjNSag78sFhFdYa6LnDJBrNgcw&m=eJsgUc3SPtxFawzKQAvC2axRmCBvC5XtisU7BG-b01Q&s=BU8EfzGavnmjxNdeepjqaZcIwWOdMcL4ZbiSsyrGoVQ&e=

Search the list archives at: https://urldefense.proofpoint.com/v2/url?u=http-3A__markmail.org_search_-3Fq-3Dvtkusers&d=DwICAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=RTHchWjhlQtHtkpaYSjNSag78sFhFdYa6LnDJBrNgcw&m=eJsgUc3SPtxFawzKQAvC2axRmCBvC5XtisU7BG-b01Q&s=qqanjlkkOLXC9ZMA_Fo7ioqxkuIyEEXQvu2n7gg3iR8&e=

Follow this link to subscribe/unsubscribe:
https://urldefense.proofpoint.com/v2/url?u=https-3A__vtk.org_mailman_listinfo_vtkusers&d=DwICAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=RTHchWjhlQtHtkpaYSjNSag78sFhFdYa6LnDJBrNgcw&m=eJsgUc3SPtxFawzKQAvC2axRmCBvC5XtisU7BG-b01Q&s=hLJwxkWX6YPd9cUkAzkQqO1X6Nlh6o4iGoe3-cpGngo&e=



More information about the vtkusers mailing list