# Texture sampling in procedural GUI textures? (SOLVED)

**URL:** <https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973>\
**Category:** Questions\
**Created:** [May 30, 2016, 12:13am UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973 "2016-05-30T00:13:20Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lukas\_Palmer](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/lukas_palmer/32/722_2.png) [@Lukas\_Palmer](https://forum.defold.com/u/Lukas_Palmer)\
**Post date:** [May 30, 2016, 12:13am UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/1 "2016-05-30T00:13:20Z")

</div>

I’m trying to create some procedural textures for a minimap system, and noticing that the upscaled 10x10 checkerboard texture shown in the screenshot is being rendered with linear filtering. As is visible, rendering is set to nearest in game.project which is reflected in the game sprites but not in the procedural texture. GUI textures such as the item and status icons render with ‘nearest’ sampling as well.

Is there a way to set the sampling of textures created with gui.new\_texture()?

 ![](https://forum-defold.b-cdn.net/uploads/default/original/2X/f/fed48fe7f2d9d8ddbc33749587d55e36864eb555.png)

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [May 30, 2016, 2:09am UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/2 "2016-05-30T02:09:52Z")

</div>

I’m assuming it’s using the built in material. I don’t know how to fix this the way it should be done, maybe there should be a way to override the built in defaults more easily.

A short term solution may be to edit your builtin, default files directly, but it would impact any project so not a good idea if you are working on many.

For example replace the gui.material file with one which uses the same material you use for your other GUI.

Defold-win32.win32.x86\plugins\com.dynamo.cr.builtins\_1.0.0.201605161607\builtins\materials

[gui.zip](https://forum.defold.com/uploads/default/original/2X/d/d0ea0ab522356cc98dceca8eee7aab26148d08de.zip) (384 Bytes)

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [May 30, 2016, 5:11am UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/3 "2016-05-30T05:11:45Z")

</div>

> [@Pkeod](#):
>
> I’m assuming it’s using the built in material. I don’t know how to fix this the way it should be done, maybe there should be a way to override the built in defaults more easily.

You can change the material of a gui scene by selecting the root of the gui scene and in the properties window change the material (the same place where you set the gui script file).

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [May 30, 2016, 5:35am UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/4 "2016-05-30T05:35:42Z")

</div>

Does that count for setting the material of gui.new\_texture() too though? I’ve not tested myself.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [May 30, 2016, 5:58am UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/5 "2016-05-30T05:58:06Z")

</div>

I would assume so, but I haven’t tested myself.

---

<div class="post-metadata">

**Author:** ![Lukas\_Palmer](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/lukas_palmer/32/722_2.png) [@Lukas\_Palmer](https://forum.defold.com/u/Lukas_Palmer)\
**Post date:** [May 30, 2016, 3:05pm UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/6 "2016-05-30T15:05:04Z")

</div>

I set minimap.gui’s material to the one you provided, and I still get the same result. Since the other gui textures render with nearest with both the built in material and the provided one, I’m starting to suspect that the texture created with gui.new\_texture isn’t using the material settings provided. When I get a chance, I’ll make a little altered copy of the fragment shader with some color modifications and see if those are reflected in the procedural texture.

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [May 30, 2016, 3:47pm UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/7 "2016-05-30T15:47:00Z")

</div>

Could you test replacing the one in the builtins folder too?

If it does not work there it may be the problem is with how Defold is using GLFW.

---

<div class="post-metadata">

**Author:** ![sven](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sven/32/1086_2.png) [@sven](https://forum.defold.com/u/sven)\
**Post date:** [May 30, 2016, 4:37pm UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/8 "2016-05-30T16:37:43Z")

</div>

You just need to make your own GUI material with changed sampler settings;

- I copied `gui.material` from builtins and added a sampler like this:  
 ![](https://forum-defold.b-cdn.net/uploads/default/original/2X/e/e5f659002f4a57a2cc0fe391c4c9c51debbc2444.png)

Then I changed my GUI to use this new material instead of the default:

 ![](https://forum-defold.b-cdn.net/uploads/default/original/2X/0/0026084605bf956991aadd4d9bea56118fee7abf.png)

And in game (I used a different color than you 🙂 ):

 ![](https://forum-defold.b-cdn.net/uploads/default/original/2X/2/24c1f1f4a4de1c5fd5bc9014b6e24b701da1542b.png)

(This is a box with size 200x200, while the texture is 10x10 iirc.)

---

<div class="post-metadata">

**Author:** ![Lukas\_Palmer](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/lukas_palmer/32/722_2.png) [@Lukas\_Palmer](https://forum.defold.com/u/Lukas_Palmer)\
**Post date:** [May 31, 2016, 1:53am UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/9 "2016-05-31T01:53:27Z")

</div>

Thanks everyone, it finally filters properly - @pkeod’s gui.material worked when I changed the sampler name to “texture” as @sven suggested as that’s the sampler name used in the built-in fragment shader.

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [May 31, 2016, 3:22am UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/10 "2016-05-31T03:22:59Z")

</div>

My mistake for forgetting about that, and also assuming you already tried changing the base material. Was thinking for some reason it was ignoring it. 😅

---

<div class="post-metadata">

**Author:** ![sven](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sven/32/1086_2.png) [@sven](https://forum.defold.com/u/sven)\
**Post date:** [May 31, 2016, 6:54am UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/11 "2016-05-31T06:54:18Z")

</div>

> [@Pkeod](#):
>
> For example replace the gui.material file with one which uses the same material you use for your other GUI.
> 
> Defold-win32.win32.x86\plugins\com.dynamo.cr.builtins\_1.0.0.201605161607\builtins\materials

Just a quick note on this;

There should be no need to grab any of the built in resources through the filesystem, the latest ones are always available in the project explorer:

 ![](https://forum-defold.b-cdn.net/uploads/default/original/2X/3/303c1265f1b310089b11ddda6947cc9bfbd1a50f.png)

👍

---

<div class="post-metadata">

**Author:** ![d954mas](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/d954mas/32/5401_2.png) [@d954mas](https://forum.defold.com/u/d954mas)\
**Post date:** [June 1, 2019, 2:01pm UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/12 "2019-06-01T14:01:30Z")

</div>

Is this working now? I create a material for gui. But Generated texture is blurry.

 ![2019-06-01_16-27-06](https://forum-defold.b-cdn.net/uploads/default/original/3X/c/2/c2e1754ad303c2c905f5b88885e607164bf67c89.png) ![2019-06-01_16-27-41](https://forum-defold.b-cdn.net/uploads/default/original/3X/7/5/75724005405f9a2bd6adc8263de5a485ca9c2986.png)

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 1, 2019, 2:05pm UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/13 "2019-06-01T14:05:48Z")

</div>

Hmm, that should work. @sven?

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [June 1, 2019, 3:27pm UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/14 "2019-06-01T15:27:02Z")

</div>

Should be texture\_sampler not texture for samplers name.

---

<div class="post-metadata">

**Author:** ![d954mas](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/d954mas/32/5401_2.png) [@d954mas](https://forum.defold.com/u/d954mas)\
**Post date:** [June 1, 2019, 3:48pm UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/15 "2019-06-01T15:48:13Z")

</div>

I try texture\_sampler, it not help

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [June 1, 2019, 3:57pm UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/16 "2019-06-01T15:57:36Z")

</div>

Is it normal textures or only generated textures? For me normal GUI textures work fine.

[pixel\_gui.zip](https://forum.defold.com/uploads/default/original/3X/2/b/2b5e95aa096400522b661fee96b311b5bbb9e561.zip) (4.2 KB)

 ![0%20-%20PixelGUI](https://forum-defold.b-cdn.net/uploads/default/original/3X/9/f/9f6d4d600e1bb693d72b4d142d63f775037aaddd.png) ![2019-06-01%2008_55_58-PixelGUI](https://forum-defold.b-cdn.net/uploads/default/original/3X/b/1/b16f53185c8c71f35ea0d94f52db38c51b40c54d.png)

---

<div class="post-metadata">

**Author:** ![d954mas](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/d954mas/32/5401_2.png) [@d954mas](https://forum.defold.com/u/d954mas)\
**Post date:** [June 1, 2019, 4:08pm UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/17 "2019-06-01T16:08:09Z")

</div>

Looks like all textures. In editor i see them ok. But in game they always linear.

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [June 1, 2019, 4:09pm UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/18 "2019-06-01T16:09:20Z")

</div>

If you put a sample texture into the sample project I uploaded does it look right or not?

Can you upload a sample texture that’s not working?

---

<div class="post-metadata">

**Author:** ![d954mas](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/d954mas/32/5401_2.png) [@d954mas](https://forum.defold.com/u/d954mas)\
**Post date:** [June 1, 2019, 4:11pm UTC](https://forum.defold.com/t/texture-sampling-in-procedural-gui-textures-solved/1973/19 "2019-06-01T16:11:37Z")

</div>

Thanks. My mistake=) I write texture\_sample instead of texture\_sampler.
