<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Hello. I sent a recent email stating I needed to pass arbitrary data to a shader, encoded in a texture of float format.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Unfortunately, my shader only received texels with values clamped between 0-1.  As you can imagine, this is a problem. </p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">I have traced the problem down to vtkOpenGLTexture::Load() function.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">What Load() does is : </p>
<p style="margin-top:0;margin-bottom:0">- Checks number of inputs. If 1, normal texture. If 6, cubemap texture.  (OK)</p>
<p style="margin-top:0;margin-bottom:0">- Gets the image scalars (aka pixels) and number of components (aka: channels)   (OK)</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">- Calls MapScalarsToColor if not depth map, or if colormpde is Map_Scalars, or<b><u> if datatype is NOT unsigned char.  (UGH!)</u></b></p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">- Resizes the input of the source exceeds GL's internal dimension capacity. (OK)</p>
<p style="margin-top:0;margin-bottom:0">- Resamples the image if needed. (OK)</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"><span style="font-size: 12pt;">- Creates a 1-channel floating point depth image, if it's a depth texture, by calling CreateDepthFromRaw(). (OK)</span><br>
</p>
<p style="margin-top:0;margin-bottom:0">  (or, if not a depth map)</p>
<p style="margin-top:0;margin-bottom:0">- Creates a 3 or 4-channel cube map, or normal texturemap, by specifying the new converted data type of VTK_UNSIGNED_CHAR.  </p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">There is actually very little to do to support arbitrary float data: Simply avoid remapping to unsigned char if the data is float (unless there's intentional remapping by using such ColorMode), and pass the actual format
 down to CreateXXXFromRaw()</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">My proposed change is to not convert incoming float data to unsigned char, but rather, to leave float color data alone.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"></p>
<div>Edit:</div>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Change this (eg: remove red line)</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"></p>
<div><b>        if (this->IsDepthTexture != 1 &&</b></div>
<div><b></b><span style="color: rgb(255, 0, 0);"><b><span style="color: rgb(0, 0, 0);">          (this->ColorMode == VTK_COLOR_MODE_MAP_SCALARS
<span style="color: rgb(255, 0, 0);">||</span></span></b></span></div>
<div><b><span style="color: rgb(255, 0, 0);">          </span><span style="color: rgb(255, 0, 0);"> inscalars->GetDataType() != VTK_UNSIGNED_CHAR</span> ))</b></div>
<div><b>
<div style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;">
        {</div>
<div style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;">
          dataPtr[i] = this->MapScalarsToColors (inscalars);</div>
<div style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;">
          bytesPerPixel = 4;</div>
<div style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;">
        }</div>
<div><br>
</div>
</b></div>
<div>to this:</div>
<div><br>
</div>
<div>
<div><b>        if (this->IsDepthTexture != 1 &&</b></div>
<div><b><span style="font-size: 12pt;">          (this->ColorMode == VTK_COLOR_MODE_MAP_SCALARS))</span><br>
</b></div>
<div><b></b>
<div style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;">
<b>        {</b></div>
<div style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;">
<b>          dataPtr[i] = this->MapScalarsToColors (inscalars);</b></div>
<div style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;">
<b>          bytesPerPixel = 4;</b></div>
<div style="font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;">
<b>        }</b></div>
<div><b><br>
</b></div>
<div><b><br>
</b></div>
<div>and these:</div>
<div><b><br>
</b></div>
<div><b>
<div>          this->TextureObject->CreateCubeFromRaw(</div>
<div>            xsize, ysize, bytesPerPixel, <span style="color: rgb(255, 0, 0);">
VTK_UNSIGNED_CHAR</span>, vtmp);</div>
<div><br>
</div>
<div>          this->TextureObject->Create2DFromRaw(</div>
<div>            xsize, ysize, bytesPerPixel, <span style="color: rgb(255, 0, 0);">
VTK_UNSIGNED_CHAR</span>, resultData[0]);</div>
<div><br>
</div>
</b></div>
<div><b><br>
</b></div>
<div>to these:</div>
<div><br>
</div>
<div><b></b>
<div style="font-weight: bold;">          this->TextureObject->CreateCubeFromRaw(</div>
<div style=""><span style="font-weight: bold; font-size: 12pt;">            xsize, ysize, bytesPerPixel,
<span style="color: rgb(75, 165, 36);">dataType</span>, vtmp);</span><br>
</div>
<div style="font-weight: bold;"><br>
</div>
<b></b><br>
</div>
<div>
<div style="font-weight: bold;">          this->TextureObject->Create2DFromRaw(</div>
<div style="font-weight: bold;"><b style="font-size: 12pt;">
<div style="display: inline !important;">            xsize, ysize, bytesPerPixel,
<span style="color: rgb(75, 165, 36);">dataType</span>, resultData[0]);</div>
</b><br>
</div>
<div style="font-weight: bold;"><br>
</div>
<div style=""><br>
</div>
<div style="">And that's all there is to it.</div>
<div style="font-weight: bold;"><br>
</div>
<div style="">Does anyone have any objection?  The only side effect I can imagine is that more texture memory is consumed iff the source image data is float and no remapping is desired. With recent GPU hardware, I'd be surprised if this was a problem. </div>
<div style=""><br>
</div>
<div style="">In any case, with <span style="font-size: 12pt;">this change, we can effectively pass unclamped arbitrary floating-point data buffers to shaders to be used for advanced viz techniques.</span></div>
<div style=""><br>
</div>
<div style="">Thanks</div>
<div style="">Patrick Bergeron</div>
</div>
</div>
</div>
<div style=""><br>
</div>
<div style=""><br>
</div>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"><img size="40581" contenttype="image/png" id="img393602" tabindex="0" style="max-width: 99.9%; user-select: none;" data-outlook-trace="F:1|T:1" src="cid:4ef6fc93-3360-44ea-8ddb-1187a837e507"><br>
</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<p></p>
</div>
</div>
</div>
</body>
</html>