Home Unity Store

[RELEASE] Shader Forge - A node-based shader editor for Unity

Replies

  • Conor
    Options
    Offline / Send Message
    Conor polycounter lvl 18
    A selection of my recent Shader Forge experiments...

    WdF60nn.gifHbV9Jp2.gif
    0doUzIW.gif

    3wl0Ziv.gif6UShnHw.gifaxHBMEa.gif

    u7YwfGr.gif4FlRBmb.gifTJoN0To.gif

    Buzzcore - try using the Transmission parameter in the Main node.
  • circle of friends
    Options
    Offline / Send Message
    circle of friends polycounter lvl 10
    I'm not sure if I have a bug or not. If I don't something is really weird anyway. I'm trying to make a simple shader that uses a difference cloud map to affect a texture's UVs. I have two panners, one -1 in the U and one 1 in the U. Adding them together, then added to the texture's UV's makes the preview ball work as intended: you get an undulating random effect.

    However, in-game you only get whatever the first cloud's U scroll is set to. As in -1. It the preview ball shows both U panner inputs, the game-shader only shows the first. I've tried swapping them over, building them in completely different ways without panners etc. The only thing I can think of is somehow by adding them togther it's ignoring the second input, or more likely it just doesn't like a 3rd input to blend with.

    NaYuqKo.jpg

    I had a texture that has 3 different greyscale images, one in each channel. The texture above it is just the green channel from that composite (I was testing to see if it was a problem with using the same texture twice).

    As you can see on the preview ball, the effect is even and goes oth -1 and +1 in U space.

    Here it is in game:

    NUPQK6L.jpg

    There's no evenness because it's only scrolling in one UV direction (-1)


    Have I just done it wrong or is this a bug?

    Thanks
  • The Rizzler
    Options
    Offline / Send Message
    The Rizzler polycounter lvl 9
    Conor wrote: »
    4FlRBmb.gif

    Niiiice, I'm new to node type editors and shaders in general, how did you achieve that wobbly effect on the flames? Vertex offset right?
  • Acegikmo
    Options
    Offline / Send Message
    I keep relying too much on mail notifications; missed a lot of nice stuff, great work!

    In other news, this is it, Shader Forge 1.0 is now officially released! :D
    Time to celebrate!
    https://twitter.com/JoachimHolmer/status/547534633001553920

    New in Shader Forge 1.0:
    • Added node: Object Scale (Unity 5+ only)
    • Added node: Fog Color
    • Added node: DDX
    • Added node: DDY
    • The node flow is now from left-to-right instead of right-to-left
    • You can now make shaders support Unity 5's reflection probes
    • When using Unity 5, Unity 5's PBR method will now be used instead of the old one
    • You can now set per-node variable precision to either Float, Half or Fixed
    • You can now plug in Diffuse Ambient Occlusion into the main node
    • You can now plug in Specular Ambient Occlusion into the main node
    • You can now manually set the internal name of properties
    • You can now use two additional UV channels, uv2 and uv3 (Unity 5+ only)
    • You can now optionally disable the right-hand side node browser
    • The depth node now has a preview icon & data
    • You can now use Alpha without the shader being alpha blended
    • There's now a console, which will warn you about various issues you may have
    - Error when a connected node is missing required inputs
    - Error when property nodes have a name conflict
    - Warnings when not using lightmapping naming conventions
    - Warning when disabling the target renderer required to view the shader on the workstation
    - Warning when using alpha blending with no alpha connected
    - Warning when not using alpha blending with alpha connected
    - Warning when using Unity 5 lightmapping, due to it currently being broken
    - Warning when using PBL without specular
    • Optimized the editor performance of the node tree - especially when you have lots of nodes
    • The default blending mode, previously named Off, is now named Opaque
    • Fixed several issues with lightmapping in 4.x
    • Fixed minor issues with spacing and UVs unnecessarily declaring variables in the generated code
    • Fixed a bug in Unity 5 where fog didn't work at all
    • Fixed a bug in Unity 5 where light probes oversaturated on scaled objects
    • Fixed a bug where lightmapped surfaces didn't receive real-time shadows
    • Fixed a bug where the interface disappeared when pressing return on certain nodes
    • Fixed a bug where you couldn't use copy/paste/cut in the code node
    • Fixed a bug where pressing delete with a text field selected, deleted selected nodes instead of a character
    • Fixed a bug in the toggle node and the normal direction node, where they had incorrect default values on load
    • 20 nodes that unnecessarily defined variables, no longer do so


    (Unity 5 support is still partial though, simply because Unity 5 is still changing a lot, and the fact that the new lightmap system is tricky to work with)



    Thank you all for your patience with this update :)
    It has taken a long time to get this one done, I hope it works out well!
    (Otherwise I'll have a lot of bugfixing to do during this time of the year, being so close to the celebration of Newton's birthday and all)
  • adamsowinski
    Options
    Offline / Send Message
    Hi Guys,

    I am new to shaders in general. I have two questions:

    1. Can I pass some data like for example Vector3 (touch point) to shader and use it in the shader every frame? I would like to achieve an interactive vertex animation based on touch data.

    2. This one in related to the first one. I would like to pass a Vector3 to shader and blend a second texture with the main one at that position. This second texture does not cover a whole object and does not tile. Sort of an effect when you shoot a door with a pistol you can see some wholes on the door.

    Is this possible with Shader Forge or do I need to do this manually in shader code. I am totally lost here so I would be glad if someone could point me in the right direction.

    Marry Christmas!
    Adam
  • Acegikmo
    Options
    Offline / Send Message
    Both of those require a C# side that can pass that data into the shader. #2 can be tricky if you want to have more than just one decal like that. But if it's only one or two, it's easy enough :)
  • Acegikmo
    Options
    Offline / Send Message
    And now, the first patch release!

    New in Shader Forge 1.01:
    • Fixed a bug where Tessellation had holes if you used a non-uniform tessellation factor
    • Fixed a bug where Texture 2D nodes marked as normal maps didn't compile properly
    • Fixed a bug where DDX and DDY sometimes didn't work on OpenGL
    • Fixed a bug where the precision menu of nodes sometimes disappeared
    • The material asset ShaderForgeInternal.mat has now been removed due to version control annoyances
    • Fixed an issue where the precision dropdown menu was almost unreadable in the light Unity skin
  • adamsowinski
    Options
    Offline / Send Message
    Acegikmo wrote: »
    Both of those require a C# side that can pass that data into the shader. #2 can be tricky if you want to have more than just one decal like that. But if it's only one or two, it's easy enough :)

    Is there a special node that I can pass this data to shader?
  • Acegikmo
    Options
    Offline / Send Message
    All property nodes can be sent data using C#, and the material.SetColor("_MyColor", Color.red); style functions.

    Also, it was a long time ago since I last posted .gifs, so here's one!

    MultiAppend.gif

    Also, dithered alpha clip is coming with 1.03 too.
    Be sure to view this in full size, since dithering is a per-pixel effect :)

    DitheringStyles.png
  • Acegikmo
    Options
    Offline / Send Message
    1.03 is now out!

    Changelog:
    • You can now enable transparency dithering when using alpha clip
    • The append node will now accept more than two inputs
    • You can now hold Ctrl (Cmd on OSX) to temporarily toggle hierarchical node movement
    • Added warning when using lightmapping without Transparent/ in the shader path when using alpha clip or alpha
    • Added warning when when conflicting variable names are present
    • Fixed a bug where the d3d9 render platform failed to compile when using Unity 5
    • Fixed a bug where Shader Forge crashed when replace-opening a shader
    • Fixed a bug where replace-opening a shader didn't properly highlight the main node inputs
  • Arkham
    Options
    Offline / Send Message
    Arkham polycounter lvl 7
    I'm looking to make a vertically-billboarded shader for a candle flame (something that can make a simple poly plane face the camera by rotating around only the vertical axis). Is this possible with Shader Forge?

    Here is the shader as it stands right now, with no vertex offsetting of any kind (just plays the texture animation). Only thing it's missing is getting it to face the camera in the manner I described.

    e270ddf.jpg
  • skankerzero
    Options
    Offline / Send Message
    Acegikmo wrote: »
    1.03 is now out!

    Changelog:
    • You can now enable transparency dithering when using alpha clip
    • The append node will now accept more than two inputs
    • You can now hold Ctrl (Cmd on OSX) to temporarily toggle hierarchical node movement
    • Added warning when using lightmapping without Transparent/ in the shader path when using alpha clip or alpha
    • Added warning when when conflicting variable names are present
    • Fixed a bug where the d3d9 render platform failed to compile when using Unity 5
    • Fixed a bug where Shader Forge crashed when replace-opening a shader
    • Fixed a bug where replace-opening a shader didn't properly highlight the main node inputs

    Do you mean 1.04? In the shader window it says 1.04.
  • nooklp
    Options
    Offline / Send Message
    Hello.
    Im trying to simulate cubemap for moving car by rotation its reflections with endless texture as it said in advise from one racing game shader developer here. Thats why i need to rotate my cubemap around axis.
    So if've found my reflection vector to rotate it... Checkout my nodes:
    tlqqb16e_d0.jpg
    Now its in output of reflection node.
    Im supposing that i need to rotate the angle of reflection output vector, but i dont know how to do that by shader forge nodes. Any ideas? Please, im really need help.
  • circle of friends
    Options
    Offline / Send Message
    circle of friends polycounter lvl 10
    Hi guys, I don't know if anyone can help me. I have a scene where there are rings rotating around 0,0,0 and occasionally they clip through the camera on their rotation. What I want to do is set up a shader so that the when a vertex gets within a certain distance of the camera, it fades out. Is this doable?

    edit: got it!

    You can do it using this

    http://acegikmo.com/shaderforge/wiki/index.php?title=Distance_Blending

    change the red and blue colour nodes to 1 and 0 (alpha on and off) and set the distance, plug it in to the alpha node

    edit2: oh its so nearly there. When set to alpha_clip it really doesn't seem to work. Stuff doesn't sort properly, its really dark, and where you have a cutout area, the interior of it is bright green(??)

    when you use standard alpha it doesn't work at all

    edit3: Standard alpha doesn't seem to sort properly but also doesn't fade out properly. Alpha clip definitely does work now, I stupidly didn't realise to use alpha clip you must have both the alph_clip and alpha nodes connected, not just alpha_clip (!)

    However, it's still not sorting properly yet, so will investigate futher for my own sanity if not anything else.
  • shrogg
    Options
    Offline / Send Message
    shrogg polycounter lvl 12
    I have a Normal Map that is using Worldspace UV coordinates, But when the object that they're applied to rotates, it rotates the normals too And inverts them.

    [Edit] Facepalm.. Turns out i never set the normal maps to be marked as Normal maps in Unity.
  • pixelquaternion
    Options
    Offline / Send Message
    pixelquaternion polycounter lvl 6
    Hi there,

    Just a few questions before we decide to buy it:

    Is this compatible with RTP?

    Can it be use with standard unity terrain shaders?

    Does it include decent documentation or it is like all unity assets without any and your left on your own trying to figure out what do what?

    Regards Peter
  • SnowInChina
    Options
    Offline / Send Message
    SnowInChina interpolator
    i had this for some time now on my wishlist and finally purchased it
    loving it, guess iam going to fiddle with it some more on the weekend :)
  • KingKellogg
    Options
    Offline / Send Message
    KingKellogg polycounter lvl 6
    I know how to use none of this :D
  • PanCotzky
    Options
    Offline / Send Message
    I need to make a thing similar to Diablo 3 resource sphere (mana etc.). I've found an article (http://simonschreibt.de/gat/diablo-3-resource-bubbles/) on how to do this but that seams that this article is intended for more competent shader creators then me. I need to create a shader that takes a surface texture and makes it into a sphere (it will be a 2D game so using a simple 3D sphere with the texture is not an option). Can you show me the way of doing this in Shader Forge?
  • SkyWay
    Options
    Offline / Send Message
    SkyWay polycounter lvl 13
    Use the same method that's used in Simons blog, it's a flat mesh just like the sprites in Unity. If you're not competent enough to create that mesh and the UV's needed then I think Shader Forge can't help you, otherwise it's just a matter of panning the UVs in the shader using the Panner and a Time node.
  • SkyWay
    Options
    Offline / Send Message
    SkyWay polycounter lvl 13
    For the sake of actually helping, I made a similar shader some time ago. You still need to make the flat mesh with the custom UVs.

    7EG7s3S.png
    mcYx0fp.gif
  • AlecMoody
    Options
    Offline / Send Message
    AlecMoody ngon master
  • Behringer
    Options
    Offline / Send Message
    Behringer polycounter lvl 2
    Hi!

    First of all - I am a complete newbie in shaders, but I work with Unity3d for a long time. I've found Shader Forge and it looks like something that might help me, but I'd like to be sure before purchasing. Maybe someone can tell me if (and how - more or less) can I create a shader that resolves my problem.

    So: I have a set of textures. Depending on the situation I need to combine them into one texture and then apply a gaussian blur on it. I need a possibility of specifying which parts of the source textures should be placed as well as the final position of them on the new texture.

    I attach some images that explain it better. Note that in the example there are 3 textures, but in my case there are from 1 to 6 textures that have to be placed onto the new texture and blurred.

    1.Set of textures (i.e. coffee cups).
    2.Some images from the set combined into one texture:
    before_blur.png
    3.Combined textures with Gaussian blur
    blur.png
  • Acegikmo
    Options
    Offline / Send Message
    Apologies for not responding well in this thread!
    @Behringer; I believe you asked me this in a mail, which I replied to :)


    Anyhow, a little update!

    Shader Forge is now getting it's next major update, with 1.1, which is first and foremost Unity 5 support. The downside is that I've also dropped Unity 4 support as of 1.1, so, if you're on Unity 4, you're stuck on 1.06!

    This is primarily to save a *massive* amount of time and pain with legacy support.

    In the meantime, here's a Unity 5 PBL shader with transmission and lightwrapping :)
  • Acegikmo
    Options
    Offline / Send Message
    Shader Forge 1.10 is now released!

    New in Shader Forge 1.10:
    • Unity 4 features dropped:
    - Minimum Unity version is now 5.0.0f4
    - Removed deferred pre-pass support
    - Removed "Double Incoming Light" setting
    • New features:
    - The Physically Based Lighting is now matching Unity's implementation
    - You can now use the Unity 5 deferred rendering pipeline
    - You can now switch between Specular and Metallic when using PBL
    - You can now switch between Gloss and Roughness
    - You can now now switch normal space between tangent, object and world
    - Added a button to highlight the current shader in the project window
    • Changes:
    - Lightmap and light probe support is now in the same checkbox
    - Removed PBL Fresnel/Visibility term checkboxes - it's now always enabled. Cheaper BRDF types may come later
    - Removed the broken instruction counter
    - Removed the broken "open compiled" button
    - Modified the example scene. Removed some content to make the package smaller
    • Fixes:
    - Fixed a bug where some nodes broke shaders when using them in multiple places (If, Noise, NormalBlend & Rotator)
    - Fixed a bug where lightmapping didn't work (Note that Directional Specular lightmaps aren't supported yet)
    • Terminology:
    - Binormal is now Bitangent
    - Alpha is now Opacity
    - Alpha Clip is now Opacity Clip
    • Render Platforms:
    - Removed Flash
    - Added iOS Metal
    - Added OpenGL ES 3.0
    - Added Xbox One
    - Added PlayStation 4
    - Added PlayStation Vita
  • varion
    Options
    Offline / Send Message
    In Unreal I could get the screen space and add to the z position. The screen space position node in SForge doesn't have z.

    How can i make a shader that moves the verts exactly towards the camera.
    I've tried using the camera vector and tried to transform it, but maybe I'm doing it wrong.

    Anybody?
  • Acegikmo
    Options
    Offline / Send Message
    Shader Forge 1.12 is now out!
    Mostly bugfixes :)

    http://acegikmo.com/shaderforge/changelog/
    varion wrote: »
    In Unreal I could get the screen space and add to the z position. The screen space position node in SForge doesn't have z.

    How can i make a shader that moves the verts exactly towards the camera.
    I've tried using the camera vector and tried to transform it, but maybe I'm doing it wrong.

    Anybody?

    Use a Vector3, set it to (0,0,1) or (0,0,-1) and then transform it, using the transform node, from view to world, and then you should have the offset you need :)
  • MattyWS
    Options
    Offline / Send Message
    MattyWS polycounter lvl 11
    This may seem obvious but I was wondering about ways to toggle RGB channels individually for particle shaders so that I could pack multiple particle textures into one image. and turn the channels on/off in the material. How easy would this be? I know there's a toggle node in Shader Forge but how to go about using it is a tad confusing. I haven't used Shader Forge much either so I'm a bit on the noob side. Any help would be much appreciated! unity4.

    EDIT: I have this so far, if there's a better way of doing it I'm all ears. :)

    Screeny01.png
  • Zugzug
    Options
    Offline / Send Message
    Zugzug polycounter lvl 5
    you can use Channel Blend node to get what you want, go to http://acegikmo.com/shaderforge/nodes/ and the scroll done to Channel Blend to see how to use it. you can use a color node to "toggle" rgb channels individually.
  • Acegikmo
    Options
    Offline / Send Message
    Zugzug wrote: »
    you can use Channel Blend node to get what you want, go to http://acegikmo.com/shaderforge/nodes/ and the scroll done to Channel Blend to see how to use it. you can use a color node to "toggle" rgb channels individually.

    Yep! Although it's easier to use the vertex colors for particles specifically, but yes, you're looking for the channel blend node :)
  • gridside
  • Acegikmo
    Options
    Offline / Send Message
    Shader Forge 1.13 is now out!
    • You can now switch transparency mode between Fade and Reflective. Reflective keeps reflections intact, even when fully transparent
    • Added premultiplied alpha blending to the blend mode presets
    • The blend mode preset will now show the name of your blend mode, in case you manually set Src and Dst to one of the presets
    • Fixed a bug where global texture nodes reverted to regular properties on load
    • Fixed a bug where shaders sometimes didn't compile when using diffuse and transmission
    • Fixed a bug where shaders sometimes didn't compile when switching to deferred after using Opacity in forward

    FadeReflective.jpg
  • THendersonVFX
    Options
    Offline / Send Message
    THendersonVFX polycounter lvl 6
    This stuff is amazing, thanks for making this!!
  • steyrboy
    Options
    Offline / Send Message
    Our team is still using unity 4.6.3. Is there a place where we can pick up a compatible version of the plugin?
  • Razz Mattazz
    Options
    Offline / Send Message
    Hey,

    Im trying to create a skydome shader that has stars + moon textures on one side and sun on the other, classic cartoon style that moves as the scene directional light rotates.

    A bit like this, but 3d on the unity 5 sky, (without the faces!): https://www.youtube.com/watch?v=N0m2uHc8_58

    I understand how to blend it all together, but im really struggling with the vector math of creating the uvs - if i have one texture thats just a moon (clamped not tiling), how do I create the UVs for that texture on the skydome?
    Ive tried a dot product of light direction and normal direction, which gives a useful radial gradient behind the light, do I want to move these 45 degrees round the sphere then append them?
    Ive also tried a cross product, which kinda works but not quite.
    Has anyone done this before? Im sure its possible from other examples...Thanks!
  • Razz Mattazz
    Options
    Offline / Send Message
    if anyone is interested, my house mate fixed my problem by writing a small script that was attached to the directional light to create the offset which was then fed into the shader. Im not exactly sure how it works, but if you are interested I will share it!
    If anyone knows how to do this 100% in shader id love to know.
  • Crest
    Options
    Offline / Send Message
    Crest polycounter lvl 6
    if anyone is interested, my house mate fixed my problem by writing a small script that was attached to the directional light to create the offset which was then fed into the shader. Im not exactly sure how it works, but if you are interested I will share it!
    If anyone knows how to do this 100% in shader id love to know.

    That would help me out a lot since I am still working in Unity 4 as well, I thought it would be script based but I just have no idea what links to what.
  • THendersonVFX
    Options
    Offline / Send Message
    THendersonVFX polycounter lvl 6
    Acegikmo wrote: »
    Hello!
    I've been working on a shader editor for a couple of weeks now, which is starting to shape up quite neatly :)
    The goal with Shader Forge is to provide an intuitive and visual way of creating shaders in the Unity engine, just like the Material Editor in UDK.


    Since most of you are artists here - What features would you like to see in this editor?
    And if you've used a shader/material editor before, what did you like/dislike about them, that Shader Forge can do better?

    I've come across a need for a node quite a few times now that I would love to see in Shader Forge. I don't know if this has been suggested yet, or how doable it is, but I'd like to see a node that outputs a visual decimal representation of numeric values. I've been doing distance to object and camera work, and since those values are hard to guess at some times, I'd love to see something that outputs numeric values in the editor in real time, instead of just seeing a fade from black to white. This would be really helpful for outputting camera and object position information. Even if just the Distance node had an option to show numeric values, that would be awesome.

    Ex: if you plugged a sin node into the suggested node, you would see the values going up and down from 0 to 1 and back to 0.
  • Razz Mattazz
    Options
    Offline / Send Message
    Crest wrote: »
    That would help me out a lot since I am still working in Unity 4 as well, I thought it would be script based but I just have no idea what links to what.

    hey download it here: https://dl.dropboxusercontent.com/u/4633015/sky.unitypackage

    Full credit goes to Richard McCarthy for this one
  • Shuaws
    Options
    Offline / Send Message
    Shuaws polycounter lvl 5
    Hello I made these crystals and I'm just using a normal map translucency and a base color. This is in marmoset, I would like to make this with shaderforge but im not sure if I can replicate this?

    oZZRsfz.jpg?2
  • Drakshin
    Options
    Offline / Send Message
    Shuaws wrote: »
    Hello I made these crystals and I'm just using a normal map translucency and a base color. This is in marmoset, I would like to make this with shaderforge but im not sure if I can replicate this?

    Well, the overall thing is totally replicatable, it might need some work if you want it to look exactly like that, but overall, as far as anything i can see on that picture goes, shaderforge is capable of producing such a result.
  • sotec
    Options
    Offline / Send Message
    hi,
    i just create a triplanar shader which doesn't use worldposition (i needed it for dynamic object ^^ ) and it work very well but i don't kow how i can put the normal map in since i use Normal Dir to create the channel blend mask ...
    if you have another way to do a mask that split the face of a cube , it's welcome :/

    here this the picture of my shader :
    360858shaderTriplanarWithRotation.png


    EDIT : it has a little bug / problem , the normal dir that's used to create the mask are not in local space, and putting a transform node doesn't seem to give me this effect, if you have an idea about it ^^
  • D4N005H
    Options
    Offline / Send Message
    D4N005H polycounter lvl 6
    Please Help.
    The right object in the scene below, is a road with a standard Unity3D shader for it, The left object is a road with a shader that was provided by ShaderForge:
    10yjqtf.jpg
    You can see that the reflection of the standard unity3D shader is way realistic than the one that Shader Firge 1.3 made. Notice both of them have normal and specular maps.

    Is there anyway to add that realistic reflection of the standard shader to the Shader Forge's one?

    And how would I tweak the strength of the Normal and Specular maps of a material in Shader Forge v1.3?
  • D4N005H
    Options
    Offline / Send Message
    D4N005H polycounter lvl 6
    2m2jaxl.jpg

    To make everything simple, I didn't use normal and specular maps for each diffuse and instead I used one specular and one normal map for this material. (As you've noticed, there are 2 diffuse maps).
  • Eric Chadwick
    Options
    Offline / Send Message
    D4N005H wrote: »

    To make everything simple, I didn't use normal and specular maps for each diffuse and instead I used one specular and one normal map for this material. (As you've noticed, there are 2 diffuse maps).

    Perhaps you need a Gloss input.
  • D4N005H
    Options
    Offline / Send Message
    D4N005H polycounter lvl 6
    Thanks Mr.Chadwick. I successfully managed to work with the shader. :)
    I also applied some other parameters to the shader, for those who want to know how I solved the problems please read the page which I shared it's address below:
    http://forum.unity3d.com/threads/shader-forge-a-visual-node-based-shader-editor.222049/page-75#post-2114265

    Regards.
  • AlecMoody
    Options
    Offline / Send Message
    AlecMoody ngon master
    Is it possible to change UV tiling for different channels of the same texture file? I am looking to pack splat and mix maps into one file but they need different UV scales. Is there a way to do this without creating 4 separate texture asset nodes? I tried feeding 1 texture asset into the tex input of 4 different texture 2d nodes, and then altering the UVs on each of those texture 2d nodes, but it didn't work.
  • Ravenok
    Options
    Offline / Send Message
    Ravenok polycounter lvl 7
    Yo!

    Been having some serious difficulties getting something to work. I hope I can get some light shed on this issue with your combined minds :)

    I'm trying to create a shader which is able to take a single RGB texture and from it, create alpha textures for each unique RGB value.

    Meaning if I have a map with 4 colors in it, each has its own unique RGB value, I would get 4 alpha maps - each one white in the area of a specific RGB value, and black everywhere else.

    The reason I want to do this is because I'll need to use 1 texture to mask well over 10 different textures, combining them all to 1 texture that covers the entire UV range. This "master masker" texture will dynamically change based on interaction.

    A good example would be if you'd create a texture with 16 different shades of grey:
    4_bit_grayscale_palette_by_10binary-d36dso3.png

    Now I want from this texture to create 16 different alpha maps, each isolating a specific shade of grey, turning it to white, and everything else to black:
    R-107
    G-107
    B-107
    Isolated to this:
    NYcdtjC.jpg


    No matter what I do, I can't get it to work. There are all kinds of problems.
    An ideal situation would be where I have 1 texture2D node which contains the full texture, and it's connected to a structure of nodes which allows me to choose an RGB value, and the output is a black and white map which shows the selected RGB value in white and everything else in black.

    I'd much appreciate any help in the matter. :)

    Thanks guys.
  • Zoltan Erdokovy
    Let's use your grayscale example for now: what you want is to find texels which are the same as your input value or in other words they differ by 0. This means that your first step is subtracting the texture from the input value and taking the absolute value of the result: where that is 0 there you have your target. Subtract it from 1 to make it behave like a mask.

    The next is to get rid of all the non 1 values. You can use a conditional node (I haven't used SF in ages, I can't remember if it had an 'if' node) to set every non-one value to zero. Alternatively the floor() function could be of help.

    So this was grayscale. With RGB you do this 3 times for each channel which will get you three sets of masks. Where their average is 1 there you have an texel matching the given color. (And again, get rid of all the not-quite-one values.)

    At least this is the theory. In practice texture compression and filtering will screw you so you will have to turn them off to avoid artifacts. If you can get away with that then that's it.

    Back in the day I did something similar but because of the issues only 8 masks were available: white, black, red, green, blue, cyan, yellow and magenta. In case of cyan (0,1,1) for example the math looked like this:
    Floor(Clamp01(((G+B)-R)/2))
    So basically I came up with an expression which only produced 1 for the color I wanted, in all other cases it was less than 1. Not a generic solution.

    Filtering was off and compression was not an issue because these colors were 8x8 squares in an image, mapped on a mesh in different ways. I never tested this method with some intricate shapes like text or vector graphics.

    Well, I hope this helps. Good luck! :)
  • Ravenok
    Options
    Offline / Send Message
    Ravenok polycounter lvl 7
    Thanks Zoltan!

    The solution works perfectly for grayscale.
    This is already enough of a solution, but I will test the RGB solution tomorrow since it'll allow us to use color coding in the alpha texture for convenience. But for now at least I know we can contain 255 alphas in a single texture. :)

    The input value I choose seems to have to be in a 0-1 range, so I had to create a value node remapped from 0-255 to 0-1 for convenience (otherwise I'd have to find the 0-1 value within an RGB channel and they can sometimes be funky).

    We're not going to use compression on this image, it'll be a small map and each pixel will represent a mask - so it'll be completely clean.

    Great solution! I knew there had to be a mathematical solution to this, not having to use conditioning.

    Many thanks.
Sign In or Register to comment.