Bitmap texture without interpolation

This may sound like an odd question, and I assume the answer out of the box is no, but is there any way to render a bitmap onto a surface without interpolation? That is, if you set a 8x8-pixel bitmap texture, you’d see a pixelated checkerboard with hard edges (rather than blurred)? Basically, I want the display conduit to render the color of the bitmap pixel that’s closest to the screen pixel UV coordinate, rather than interpolating.

1 Like

Hi @Jon,

Can you provide an image or screen shot of what you’re after?

– Dale

Hi Dale,

Yes, what I’m after is actually the default behavior when assigning a texture to a custom material in Rhino (left). But using DisplayMaterial.SetBitmapTexture() gives a blended look by default (right). What do I have to do to get the smiley face version?

    var material = new DisplayMaterial();
    material.SetBitmapTexture(bitmapPath, true);

Thanks,

Jon

@dale I’m not sure there’s enough exposed in common to get at all of the texture components… Unfortunately, the default texture construction sets the filtering to “linear” (ON) instead of “nearest” (OFF).

In the C++ SDK this is easily solved by walking through the material’s m_textures array looking for the bitmap texture, and then setting the filter mode to nearest

Here is the C++ code that would do that… I’ll let you figure out if it’s doable in common.

Given the material mat that contains a bitmap texture:

int   ti = mat.FindTexture(nullptr, ON_Texture::TYPE::bitmap_texture, -1);
if (ti >= 0)
{
  // then `mat` contains a bitmap texture...locate within the array...
  ON_Texture&  tex = mat.m_textures[ti];

  // Now force the filter to `nearest` (aka OFF)...
  tex.m_magfilter = ON_Texture::FILTER::nearest_filter;
}

@Jon You can certainly turn it off using Rhino’s UI… Your screenshot above actually shows the control to do it…it’s the one on the very bottom of your screenshot “Enable filtering”… It’s unchecked for the image on the left, but my guess is that it’s checked for the image on the right.

But that’s probably not how you want to control this… I’m assuming you want to be able to do this in code. @Dale is probably going to have to add more wrappers in common to get you there.

-J

Hi @jeff and @dale,

Thanks for looking into it. Yes, I’m trying to do this in C#, so adding it to common would be fantastic if possible. :slight_smile:

Cheers,

Jon

I’ve added the request to the pile.

https://mcneel.myjetbrains.com/youtrack/issue/RH-50589

– Dale

Related question. I know it’s possible to write a texture evaluator for a RenderTexture (e.g.). But is there any way to do this for a DisplayMaterial? Or use a RenderTexture directly in a pipeline draw method?

I’m asking because I have a conduit that draws meshes that are not doc objects. It would be incredibly useful to describe the color of these meshes using functions. This would make the above interpolation issue easy to solve, and – more importantly – would allow writing complex textures procedurally.

To make this less abstract, consider the texture below, which displays statistics about daylight levels at many sensors in a room over the course of a year. A procedural definition of this texture would be very lightweight, and would hold up perfectly at arbitrary zoom. … Much more efficient than writing and loading a very-high-res bitmap. The simulation producing the data updates every second or so, and the data itself is replaced in real time in response to user controls, so efficiency ends up mattering a lot.

Cheers,

Jon