Clamp Greyscale Texture Min / Max

Node-based Shader Editor

Clamp Greyscale Texture Min / Max

Postby jake.carvey » Thu Feb 22, 2018 9:55 pm

I need to do something similar to the Min/Max/Clamp UV example in the tutorials:

https://www.youtube.com/watch?v=R0yyoqgpdg8&t=29s

But I need it to work on a greyscale image channel, and clamp doesn't work with texture samplers:

12345.jpg
12345.jpg (8.17 KiB) Viewed 3025 times


Desired result: extract ONLY the number "2', and remap it to black & white

12345_extract2.jpg
12345_extract2.jpg (4.37 KiB) Viewed 3025 times


very grateful for any help

- jake
jake.carvey
 
Posts: 16
Joined: Thu Feb 22, 2018 9:39 pm

Re: Clamp Greyscale Texture Min / Max

Postby Ricardo Teixeira » Fri Feb 23, 2018 12:03 pm

Hello Jake,

Thanks for getting in touch, we would be happy to help.

The Clamp node does work but, unfortunately, not for the specific effect that you intend to build. To a certain extent, extracting specific values from a texture is possible but, depending on the complexity of your texture, it requires a considerable amount of work.

Have you considered using an alternative masking system such as an atlas based on the included sample? (ReadFromAtlas sample)

I took the liberty of building a simple example using the functionality you were looking for.

Image

Check the attached Unity Package.

Thanks!
Attachments
TextSample.unitypackage
(16.88 KiB) Downloaded 109 times
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: Clamp Greyscale Texture Min / Max

Postby jake.carvey » Fri Feb 23, 2018 3:45 pm

Let me be a bit more specific. We are looking to use a single texture channel, to create approx.16 individual masks. In order do so, we need to clip any value above, say, [ 0.54 ] brightness to black, and then, clip any value below [ 0.50 ] brightness to black (the rest is fairly simple).

clip-map-grey.png
clip-map-grey.png (48.75 KiB) Viewed 3009 times


clip-map-grey-min-max.png
clip-map-grey-min-max.png (8.05 KiB) Viewed 3009 times


ReadFromAtlasd doesn't seem like it will work for our purposes - the entire point is that each mask stays in it's exact UV position, and all other masks are overwritten with black, as the intention is to mask a specific piece of UV mapped geometry.

The system works very with specific texture maps, but it just requires many separate maps which is just grossly inefficient, and we are already running out of texture memory.

I look forward to more ideas! It is so very close, I can almost taste it!

cheers

jake
jake.carvey
 
Posts: 16
Joined: Thu Feb 22, 2018 9:39 pm

Re: Clamp Greyscale Texture Min / Max

Postby Ricardo Teixeira » Fri Feb 23, 2018 5:44 pm

jake.carvey wrote:Let me be a bit more specific. We are looking to use a single texture channel, to create approx.16 individual masks. In order do so, we need to clip any value above, say, [ 0.54 ] brightness to black, and then, clip any value below [ 0.50 ] brightness to black (the rest is fairly simple).

The attachment clip-map-grey.png is no longer available


The attachment clip-map-grey-min-max.png is no longer available


ReadFromAtlasd doesn't seem like it will work for our purposes - the entire point is that each mask stays in it's exact UV position, and all other masks are overwritten with black, as the intention is to mask a specific piece of UV mapped geometry.

The system works very with specific texture maps, but it just requires many separate maps which is just grossly inefficient, and we are already running out of texture memory.

I look forward to more ideas! It is so very close, I can almost taste it!

cheers

jake


I understand what you are trying to build but, unless you have a specific technique in mind, it's going to become a bit "complex" to extract/clamp 16 mask from a single texture.

Check the sample attached, do take into account that texture filtering will influence the results, you will have to account for it. I made it B&W using different nodes as an example, it really depends on your specific use.

Have you considered using a Texture Array? ASE includes a sample and tool to build them.

With a few adjustments/remapping, the Atlas method could work well; in any case, it really depends on how you intend to use it.

Thanks!
Attachments
Text2.unitypackage
(14.29 KiB) Downloaded 106 times
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: Clamp Greyscale Texture Min / Max

Postby jake.carvey » Fri Feb 23, 2018 7:39 pm

I have made progress using CLAMP for the UV coordinates - although it is not ideal, as I have to create an individual texture sample for each extracted mask (with a max of 16 ( minus a few for albedo and normal ).

Here is a quick screengrab of the network. I would love to just be able to just draw rectangles of white or black over the top, bottom, left and right, to block the unwanted areas. That would save a ton of texture samplers, and be very easy to adjust. Maybe with overlaid gradients somehow?

node network 002bv.jpg
node network 002bv.jpg (230.72 KiB) Viewed 3004 times


Thank you for that second example - I was able to arrive at something similar, but still not able to eliminate both above and below the threshold. I will keep trying.

jake
jake.carvey
 
Posts: 16
Joined: Thu Feb 22, 2018 9:39 pm

Re: Clamp Greyscale Texture Min / Max

Postby jake.carvey » Fri Feb 23, 2018 7:47 pm

Ok - the last sample is giving me a couple of new ideas how to approach it - thank you.

jake
jake.carvey
 
Posts: 16
Joined: Thu Feb 22, 2018 9:39 pm

Re: Clamp Greyscale Texture Min / Max

Postby Ricardo Teixeira » Sat Feb 24, 2018 2:50 pm

That amount of Texture Samples is not recommended for that specific purpose.

Adjusting UV coordinates would be ideal but, alternatively, you can also try to mask it as shown in the sample shared.

Looking forward to see what you build!
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: Clamp Greyscale Texture Min / Max

Postby Lars Nonne » Sun Feb 25, 2018 7:29 am

Hi,

I|m not entirely sure, what you are trying to achieve, since you could simply use the same texture multiple times.
Either to that in the shader or, in some cases you might need to enable gpu instancing.

Anyways. I added a small shader.
ColorSeparation.unitypackage
(61.06 KiB) Downloaded 120 times

Since I'm not certain what you are trying to do, this might or might not help.

Lars
Lars Nonne
 
Posts: 18
Joined: Mon Feb 12, 2018 4:54 pm

Re: Clamp Greyscale Texture Min / Max

Postby Ricardo Teixeira » Sun Feb 25, 2018 11:30 am

Lars Nonne wrote:Hi,

I|m not entirely sure, what you are trying to achieve, since you could simply use the same texture multiple times.
Either to that in the shader or, in some cases you might need to enable gpu instancing.

Anyways. I added a small shader.
ColorSeparation.unitypackage

Since I'm not certain what you are trying to do, this might or might not help.

Lars


Hello Lars,

Thank you for helping out!

I think the UV option would be the best option for his current requirements.

Thanks!
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: Clamp Greyscale Texture Min / Max

Postby jake.carvey » Sun Feb 25, 2018 3:35 pm

Lars,

Thanks - I will check yours out as well!

Already tried the separate image mask strategy, but we need more than 16 masks per shader.

The issue is with the UV's, I couldn't find a way adjust the UV coordinates of a texture that's shared through a Local Var. Each separated UV "section" requires a unique Texture Sample?

Luckily Ricardo's last shader example put me on the right path - I will have the new shader built tonight and will share it here!!! it has a few unique requirements, but I can live with that.

thanks!
jake.carvey
 
Posts: 16
Joined: Thu Feb 22, 2018 9:39 pm

Next

Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 0 guests