Page MenuHome

Image texture node: Enable clipping and alpha representation for GLSL viewport
Needs ReviewPublic

Authored by Ralf Hölzemer (cheleb) on May 31 2016, 10:17 PM.

Details

Summary

Sample scene:

Set left viewport to rendered shading mode and change the clipping mode in the node and the alpha settings in the properties panel.

Diff Detail

Event Timeline

Ralf Hölzemer (cheleb) retitled this revision from to Image texture node: Enable clipping and alpha representation for GLSL viewport.
Ralf Hölzemer (cheleb) updated this object.
Ralf Hölzemer (cheleb) set the repository for this revision to rB Blender.

I'm not sure if this is an appropriate place for asking a question, but would it be possible to enable clip and extension mapping modes in Blender Internal texture as well? I hope it isn't difficult to implement and it will greatly help with placing decals and other similar tasks.

Sergey Sharybin (sergey) requested changes to this revision.Jun 2 2016, 11:49 AM

There are two issues here.

First one is that clipping will cause leakage of a wrapped pixels to the border one, you will need somewhat similar trick as for extension.

Second issue is that textureSize() is not currently usable on OSX, see rBcccd06e for details.

I'm also not sure we want to do such things in shader itself, this is similar to an interpolation method which should be done using glTexParameteri().

This revision now requires changes to proceed.Jun 2 2016, 11:49 AM
Ralf Hölzemer (cheleb) edited edge metadata.
Ralf Hölzemer (cheleb) removed rB Blender as the repository for this revision.

Hey Sergey,

i finally found some time to dig deeper into this.

First one is that clipping will cause leakage of a wrapped pixels to the border one, you will need somewhat similar trick as for extension.

Fixed in the new diff. Thanks for pointing that out.

Second issue is that textureSize() is not currently usable on OSX, see rBcccd06e for details.

That i didn't know. Proposed solution below.

I'm also not sure we want to do such things in shader itself, this is similar to an interpolation method which should be done using glTexParameteri().

Please note that i am more of an artist than a developer, so all of this could be totally wrong! :)

It took me some time to get a grip on what is necessary to make things happen via glTexParameteri(). So i did a quick and dirty new function "GPU_texture_wrap_mode" in GPU_texture.c which would set a new wrap mode for img->gputexture[0] in node_shader_tex_image.c. This worked well for an image with just one user, but did not work for multiple image nodes using the same image because they (obviously) would all point to the same GPUTexture. Therefor, when the extend mode changed in one instance of an image node, all other instances would also change.

I tried to come up with a nice solution for that problem but couldn't find anything satisfying. I am sure there is a nice solution, but it seems to me that it would be quite involved. As I said, I could be wrong - still learning. :)

So, to keep it simple, the next patch still does everything in the shader and solves the textureSize() problem by simply querying the Image in node_shader_gpu_tex_image and pass that information down to image_texture_lookup in gpu_shader_material.glsl

Just in case it will help with something: I have found out that there is a way to turn extend mapping in 3D viewport in Blender's UV\Image editor. I don't understand how exactly that works, but still. The problem is that this option wouldn't stay enabled after reloading so you'll have to manually turn it back on for every clamped\extended image. I was thinking about forming a bug report on this, but I'm not sure if that's supposed to work like that.

  1. Create a Plane with UVs and scale UVs up to make a visible tiling.
  2. Turn on Textured Solid mode or change viewport shading to Textured. It seems very strange, but if you'll switch to Material shading right away, this trick won't work.
  3. Add either Blender material or Cycles material and attach an image texture to it.
  4. Enter Edit Mode, select your Plane's polygon and assign the same image to it in UV\Image editor.
  5. In UV\Image editor open Properties panel and set Clamp X and Y. Now you should see your texture clamped or extended (if your image had a transparent border it will be clamped, otherwise it will be extended).
  6. Now it should be possible to use that image clamped in Material shading as well.

I'm using BI render, but if it will be implemented in Cycles that would be nice too. Since this function kind of works, perhaps it would be possible to make it properly clip the image, link it to image texture properties somehow and make this option stay on after reload?