Search Unity

Shader Forge - A visual, node-based shader editor

Discussion in 'Assets and Asset Store' started by Acegikmo, Jan 11, 2014.

  1. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Replace the UV Coord node by a WorldPos node and grab the X and Z components as your new UV coordinates.
    You might need to scale these values somewhat to fit your scene.
     
  2. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,145
    It does. You can enable "double incoming light" in the lefthand sidebar in the Shader Forge editor.
     
  3. Guideborn

    Guideborn

    Joined:
    Jun 15, 2013
    Posts:
    231
    In the SF editor, what option allows me to use a diffuse map to determine outline color?
     
  4. dart4140

    dart4140

    Joined:
    Nov 25, 2013
    Posts:
    2
    Ok thanks a lot, follow up question. Do you have a tutorial or could you tell me how to have an input array of colors I can't seem to find the option anywhere.
     
  5. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Try plugging the diffuse Texture2D right into the outline colour input!
     
  6. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Well, by "array" (note the quotation marks) I meant simply having some amount of color nodes, and using them as if they are an array. There's no built-in support for arrays at the moment
     
  7. Seplabmikash

    Seplabmikash

    Joined:
    Sep 30, 2014
    Posts:
    12
    Hey Cactus on Fire!

    I would very much like to see inside your shader, what nodes are you using?
    How do you get the sparks to follow a path, is it like a sprite animation, or do they follow a path a different way?
    I have no programming, or shader-writing background, so any info you wish to share would be most welcome!
    Also the smoke distortion is very interesting.
    You could also send me a personal message if that suits you better!

    Cheers!

     
  8. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Quick question, hopefully...

    ...I understand with shaders in general, it is possible to offset vertices and have shadows behave correctly. I believe I understand it has to do with proper implementation of the shadow collector in the shader...

    ...how would I be able to have correct shadows on my offset vertices? :D

    Thanks in advance!

    -Steven
     
  9. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Oh and actually one more thing (related to the above question):

    Joachim helped me with this quite some time ago, and the node graph he implemented worked great in a much earlier version of Shader Forge, but in the latest the exact same implementation doesn't work at all. It does do something, just not what is expected and not what was otherwise correct in the earlier version.

    So that said, could someone guide me in the thought process behind creating the now often sought after 'curved world' effect?

    This is the node graph I'm currently rock'in:

    sf_curvedworldvertex_9302014.png

    Thanks yet again fellas!

    -Steven

    sf_curvedworldvertex_9302014.png
     
  10. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Okay sheesh, I had to convert from World Space to Local; so barring anything unforeseen, I solved the curved world aspect...

    ...so it's just proper shadow casting that I need to figure out and I'm golden! ( I truly hope this is doable )

    Cheers!

    -Steven
     
  11. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    ...hmmmm is it my imagination or is Shadow Collection working correct?!

    I feel silly that I'm having this conversation by myself, so I would still love any insight anyone can offer! :D

    -Steven
     
  12. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    @SteveB:
    A shot in the dark... but...

    You are deforming your scene geometry based on camera view, right?
    Have you taken a look at the shadow collector and shadow caster passes that SF generates in your shader code? Are they doing the same as your shading pass - deforming geometry based on camera position?

    Rendering a shadow usually involves "seeing" the scene from the perspective of a given light in an orthographic view. If however the geometry is view dependent the light creates a geometry that differs from the geometry your camera sees.
    I don't know what camera matrix SF or Unity pass into the caster/collector passes. I'd guess that they (SF/Unity Engine) have access to the correct one somehow. But it might be the wrong one in your specific case...

    I didn't try your shader nor did I try view dependent vertex transformation to test what I just wrote - I'm just trying to keep your conversation flowing ;)
     
  13. lobachevscki

    lobachevscki

    Joined:
    Apr 22, 2014
    Posts:
    9
    Hi.

    New to Shaderforge, great piece of software by the way.

    I was wondering what would be the proper way to load a sequence of image as a part of animated texture.

    We have some fluid rendered as a mask to a image sequence and we want to multiply that sequence to our actual texture.

    Could you drop a hint on this?

    Thanks in advanced.
     
  14. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    I
    You know, it appears to work fine so I honestly didn't investigate this further. For the sake of our continued conversation, if there were an issue with the shadow collection, I would've been hard pressed as to how to fix it confidently...I'm not a shader coder hence why I'm using SF...yikes! Thank goodness all appears to correct, and even if it isn't I can't tell! :D

    Haha, I truly appreciate you making the effort thank you. Sometimes all thats needed is yelling at the monitor and subsequently asking on the forums.

    Thanks a bunch Marco!

    -Steven
     
  15. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    SF_lobachevscki_01.jpg
    Tested with this image:
    SF_lobachevscki_02.png
    Hint status: dropped
     
  16. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Thanks for taking the time IFL :)
    I should really make a node for this
     
    Deon-Cadme likes this.
  17. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Great work IFL. That's a shader forge gem right there !
     
  18. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    @Seplabmikash

    it's kinda hard to explain also the nodes don't even fit the screen for a screenshot :D
    but basically I made a gradient map for the sparks, then I used a lerp between 1 and 0 and a hard mix blend node to mask the smoke lines. as the slider goes, the mask slowly reveals the lines.


    Check back a few posts before, I posted what both maps look like. It should make it easier to understand.
     
  19. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Glad to help. I'm really looking forward to the next version of SF due out next year. ;)
     
  20. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
  21. ok8596

    ok8596

    Joined:
    Feb 21, 2014
    Posts:
    40
    Could anyone teach me if you know pls.
    I made my toon shader with SF. like this
    1st.png
    But, this shader was not perfect when I use the point light. point light was displayed square.
    Then, I sat Light Attenuation like this.
    2nd.png
    The influence of the point light is ok.
    But, I do'nt need this black shadow. I want to make this light effect.
    How should I divide influence of the light and the shadow?
     
  22. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Done. I might fill in some of the other links in the next week.
    I think this is simple... if you don't want the black shadow, turn off the shadow for the lights or set them up to use layers via Culling Mask.
     
    Last edited: Oct 3, 2014
    Acegikmo likes this.
  23. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    Hi Guys,

    I've got another Noob question :
    I am trying to do a texture splatting(with Shader Forge of course) following the tutorial on the Wiki and that's what I get:

    Could you please tell me where is my mistake?

    Thanks a lot :)
     

    Attached Files:

  24. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    There's a checkbox that says "double incoming light" in the lighting settings - check it :)
    (That's for matching Unity's shaders)
     
  25. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    REALLY REALLY THANKS!
     
  26. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    And again me!

    I do have an issue with a procedural generated mesh. The texture applied appears as you can see in the attached picture(veeery bad).
    The material attached to the mesh is described in the other pic (a simple texture with Diffuse, nothing special).
    Any "magical" suggestions?

    Thanks again
     

    Attached Files:

  27. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    It looks like your mesh has its uv mapped to xy instead of xz. It also looks like your texture is clamped instead of repeating.
     
  28. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    Hey IFL, Thanks for the reply.
    I cheched and the texture is repeating. Unfortunately I have no clue how to change the UV Mapping from xz to xy.
    Maybe Acegikmo can explain me or pointing to a tutorial/guide?

    Thanks :)
     
  29. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    The mesh you are texturing obviously has some uv coordinates - else everything you'd see would be a single Color because the UVs would probably end up being 0, 0.

    I see 2 options:
    1) Check the UV creation process. You say that you are using a procedurally generated mesh. That means that you have to check that generator algorithm to fix this issue.
    It may be as easy as setting a checkbox to export planar UVs. But it might be as hard as going through the actual generator code to fix this.
    2) Provide your own UVs via Shader Forge nodes. Plug a WorldPos node in the graph. Grab its X and Z components and plug those into the UVs of your texture asset.

    Edit:
    I just filled a section of the SF wiki that deals with World Space UV Mapping. Option #2 at your Service ;)
     
    Last edited: Oct 5, 2014
  30. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Like Marco has said, it has to do with your mesh generation process. If your mesh generation script isn't licensed or compiled, I can fix it for you - just send it via PM or something. The mesh generation and the associated errors aren't within the scope of ShaderForge. ;)
     
    micuccio likes this.
  31. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,145
    I know I can't use the Light Direction node and custom lighting in deferred shaders. Are there any other things I need to look out for, other than alpha sorting stuff?
     
  32. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    So, first of all thanks fo the answer:

    I will try to explain my situation. The mesh generate quads (two triangles) and I apply a Material (generated with Shader forge).
    I obtain something like the pic shown.
    The quad mesh is generated via the attached code and after I simply appy the material.


    It is really weird and is driving me crazy. I would really apprecciate your help!
     

    Attached Files:

  33. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Wut. So... I think you're either (1) using world-space coords for the texture transition or (2) UV1 or UV2 is being used in the shader. If that's not it, it might be vertex colors, weird normals, or your computer is haunted. The shader used in your last post obviously isn't the one previously shown.
     
  34. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    You are right in both of your observations.(Except for the Haunted computer :) )
    I think I messed up a bit. I used the World-Space-Coordinate to "adjust the texture" but I have not very good knowledge of the use.I was just trying.
    And I've used the UV coordinates too.
    Here is the shader used.

    Any Idea/Suggestion?

    Or a "act of random kindness" = example?


    Thanks
     

    Attached Files:

  35. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Looks like you're simply not generating UV coordinates for your generated quad. The lerp uses the uv coords to do the texture fading
     
    micuccio likes this.
  36. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    You mean in the code right? if yes, you are right. I did not generate the UV coordinate in it. I was thinking it was not necessary.
    Should I do then?
     
  37. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    If you drive your texture transitions via UV coordinates you should most definitely generate UV coordinates - else the lerp-function would (for every fragment/pixel) always return the same result.
    Though I wonder why you want to use the UVs for texture transitioning?
     
  38. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    I see.
    I have still a lot of thingh to learn about shader I suppose, and of course I am willing to learn.
    I will update the code then to associate to each triangle a UV coordinate.

    @Marco Sperling : What do you mean exactly? what should be a better idea?
     
  39. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    You generally use either:
    Vertex colors (Simple but cheap painted blending)
    RGBA Texture mask (Splatmap) in world coordinates (More expensive, but can look much better)
    World coordinates (Usually used for height-based blending, such as blending in snow on peaks of distant mountains)

    But you can of course use UVs as well, it's just much harder to make something look the way you want, unless you have a very simple use case :)
     
    micuccio likes this.
  40. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    Hey @Acegikmo , thanks for your time.

    So If I understood correctly my steps are :
    1)Modify the code in order to associate a UV coordinates (in case I decide for them)
    2)generate a simple shader for the texture blending as reported in you Wiki (I am referring to the one that use LERP)


    and, due to my unlimited source of questions:

    When you refer to Vertex colors, RGBA texture mark and World coordinate, does this imply the presence of the UV coordinates in the code that generate the mesh?
     
  41. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    It depends on which one.
    When mapping textures, you need to generate UV coordinates somewhere, be it in the mesh generation code or the shader.

    Vertex color blending doesn't need UVs at all.

    RGBA texture masking needs UVs. You can either generate them when generating the mesh, or in the shader. It really depends on the situation. Would a top-down projection work, or is the mesh more complicated than that? If it's more complicated, you most likely need to generate UVs on mesh generation, otherwise you can just use the world position node in the shader to generate your UVs in the shader.

    Blending based on world coordinates is a very simple blending method. As mentioned before; blending a texture based on it's height in the world, to fade in snow on mountaintops, or grass on the lower areas.

    You can also blend based on normal direction, to blend in cliffs in steep areas of a terrain, and many, many other things.

    It all comes down to how you want it to look and it what situation you're using it.
     
  42. micuccio

    micuccio

    Joined:
    Jan 26, 2014
    Posts:
    143
    The final generated mesh is pretty complex (a lot of triangles) . I would like quality textures, so I have to include the UV mapping in the code.
    I will dig a bit more for the vertex color blending, I think could be interesting for my project.

    I've read you wiki and, with some difficulties, I've reached some results. I have an advice to ask to you:
    can you suggest me a guide/paper to understand the basics of shader?
    Or are you planning to release other tutorials or new part of the wiki?

    I hope I am not the only one with difficulties in shaders
     
  43. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    The YouTube tutorials and the Wiki aside - not sure.
    You could look into the example shaders, or simply experiment in SF and see what happens. The node documentation should be helpful in this regard as well
     
  44. ok8596

    ok8596

    Joined:
    Feb 21, 2014
    Posts:
    40
    Thank you for replying.
    But I didnt solve this problem...
    I decided not to use point light for toon shader.
     
  45. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    When will we be able to use View Direction to offset vertices ?
    What should i put in the code node to have the same result ?
     
  46. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Hey all.

    How would I recreate the 'Transparent Cutout / Soft Edge Unlit' shader within SF ? I think it's a great workaround for accurate transparency with correct drawing order.
    I know that Soft Edge Unlit uses two passes on top of each other to get the right order, but I don't know how to do something like that with SF.

     
    ViktorCor likes this.
  47. irwit

    irwit

    Joined:
    Sep 30, 2014
    Posts:
    55
    Hi all

    Just Trying out shader forge and it was suggested I post in this thread. I just wondering what kind of node setup would I use to create a strength slider for a normal map. I know how to fade it out but not sure on the maths it order to make a normal map stronger?
     
  48. Seplabmikash

    Seplabmikash

    Joined:
    Sep 30, 2014
    Posts:
    12
    Thank you so much for your reply!
    I'm afraid my knowledge with nodes is the bare minimum, with long arduous work I managed to get a emission mask and reflection with a cubemap. If you could bring it up to make some screenshots I would be much obliged!
     
  49. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Basically you give a really high contrast to the gradient map and use it as a mask to gradually reveal the diffuse map.

     
    Deon-Cadme, Acegikmo and Murgilod like this.
  50. Jiraiya

    Jiraiya

    Joined:
    May 16, 2013
    Posts:
    12
    are there any graphs showing what an occluded shader (draws silhouette of object behind another object)