Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. BoyNoodle

    BoyNoodle

    Joined:
    May 11, 2017
    Posts:
    3
    You can create splat-map shaders in SF but I can't think of a way to actually paint on the splat map (other than using a pre-prepared splat map. The Ikari Vertex Painter lets you paint on objects in scene view & texture them in real-time but that is done by changing vertex colours. Is there a similar painting tool available for splat-mapping that can be used with SF?
     
  2. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    thx man. ill let them know
     
  3. kaimelis

    kaimelis

    Joined:
    Apr 28, 2016
    Posts:
    18
    Hi. Trying to make some nice texture transition to another. Just started using shader forge so this is my first try of doing anything. And I have problem with making it loop only once through object. can someone help?
     

    Attached Files:

  4. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Time in shaders is different to time normally. If you have t/20 (from your time node) once play is pressed or the game starts, it starts counting and doesn't stop, doesn't pause, doesn't resume or change speed. It's just the total time since the application 'began' with some modifier.

    For transitions, it's generally better to pass a variable (Value) through to the material from a script. So you'd start with the material having a transition value of 0, then script it at some point to change that value to 1. Maybe have some nice smoothness too where each FixedUpdate it increments the transition up by 0.01 or something. Also remember to clamp the transition to between 0 and 1; in code it's Mathf.clamp(value, 0, 1); and in Shader Forge it's the Clamp node (choose whichever you want)
     
  5. retmia

    retmia

    Joined:
    May 31, 2013
    Posts:
    25
    Hello Everyone.
    I need your help to make an idea work !

    I have a material with a custom shader. There is a serie of 10 "lamps" on the texture, I want to light them one by one. But I can't manage to make the synch work ...

    See the gif and the shader tree to preview what I have.

    I though I could do it with a time + posterize node, but it appears that I just can't make it perfect. It always offsets a little, no matter how precise I try to posterize the time.

    What am I doing wrong ?
    How would you approach it ?

    Hope someone has an idea.
    Kind Regards :)
     

    Attached Files:

  6. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Hi retmia,
    I would simply use a grayscale mask. First light would be darkest shade of gray, last light brightest gray value.
    Then you can step()-compare your frac() time value to the grayscale value of the light pixels. Hope this doesn't sound too vague, I'm in a hurry.
     
  7. retmia

    retmia

    Joined:
    May 31, 2013
    Posts:
    25
    Hello Marco-Sperling,
    Thank you very much for your quick answer, I've tried a few things without success unfortunately. I'm far from mastering all the shader philosophy ! Could you illustrate your idea with a node tree ? It would be wonderful !
    Thanks in advance :)
     
  8. OneManBandGames

    OneManBandGames

    Joined:
    Dec 7, 2014
    Posts:
    207
    Hello Everyone,

    I'm currently struggling with the following Shader problem: I'm trying to create a shader for the unity terrain detail objects (Grass, bushes, flowers....) by overwriting the default shader for this. Amongst other details I would like to have a wind effect, so that the vegetation bends around a bit randomly. I am able to achieve what I want, however it turns out that apparently Unity packs the textures for the terrain details in some sort of combined atlas, which messes with the UV coordinates of those textures. This leads to the following problem:



    I apply a vertex offset to the plants according to their v-coordinates, there is 0 offset at V=0 since this is where the plant is "rooted" in the terrain, but with increasing V-value more and more vertex offset gets applied, resulting in the plant being "bend over by the wind".
    The first two plant images are bending with the wind as intended, the third orange-yellowish plant is being pushed around in its positioning as well with the bending. The reason for this is that the first two plants still have their v-coordinate originating at 0, while the yellow-orangeish has their V-coordiantes starting somewhere higher in the atlas.

    (I added a v-coordinate threshold that would simply color in parts of the texture in red to see what the min-max values for the different plants are.)

    My question would be now: Is there a way to normalize the UV-coordinates for the single plants when being processed / rendered by the shader? I'm fairly new to Shaders and ShaderForge, so I have trouble figuring out how I could normalize these coordinates, especially when I have no clue how the texture atlas will be packed when I add / remove terrain details in the unity editor.
     
  9. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Try this:

    From the V coord, multiply that by 2, then use a frac node on that. Plug that into where ever you were plugging the V coord.

    I don't know how Unity handles the atlas generator. If it's a 2x2 (patches with 4 types of grass? A good guess) then use 2 like above. Check the default Unity grass shader, see what that says.
     
  10. OneManBandGames

    OneManBandGames

    Joined:
    Dec 7, 2014
    Posts:
    207
    Thanks for your reply, Jesus! I tried your suggestion, however there still seems to be something off: At multiplication by 2, none of the plants move anymore, as if the V-cordinate would always be 0 then. At multiplication by 3 the first two plants from the example work like intended, the third orange plant stays in place but bends "in reverse", as if it was attached at the top, and the bottom part where it should be rooted is then moving instead.
    I need to experiment / debug more to find out how the textures are arranged in the atlas so I can find a matching normalization it seems.
     
  11. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Interesting.

    Maybe make a texture in PS/Paint, that looks like a sprite sheet, but divided into 4 columns.

    On the left it's have 2 rows, numbered 1 and 2 (from the bottom)
    in the 2nd one, 3 rows, the third 4 rows and the 4th 8 rows.

    Or some other way of working out the atlas layout (is it 2x2? 3x3? 4x4?)
     
  12. OneManBandGames

    OneManBandGames

    Joined:
    Dec 7, 2014
    Posts:
    207
    Thanks for your reply again! I created a simple "color stripe" shader that will just color the object according to the V-coordinate:

    The intervals are set at 0.1 each, 0 -> 0.1 gets a color, 0.1 -> 0.2 a different color, and so on. Now I could watch how this pattern would be applied to the plant textures as I add and remove them in the editor:


    With this information I could find out that Unity packs the plant textures for the terrain prototypes as follows (The squares represent the atlas texture, the number represents the order in which the textures are packed into the atlas):


    ...and so on. As soon as the atlas needs to be increased in size for additional textures, unity will fill out one column first, then fill the remaining spots in the rows until the atlas needs to be increased again.

    So far so good, but that means your suggestion with mulitply for 2 & then frac should have worked for normalizing the UVs for the three textures from the initial example?

    Well, turns out there seems to be more to it. For once, I would expect the V-coordinate for the different rows to be split up evenly across the atlas. I would expect the V-coordinate for the bottom row for a 4x4 atlas to go from 0 to 0.25. However by using my stripe shader from above, I could find out that the V-coordinate seems to go from 0 to approximately 0.238. So it seems some kind of offset or "frame" is in this atlas as well. I found that if I multiply with 4.2 instead of 4 in a 4x4 atlas, the frac approach seems to work just fine as I get the full stripe pattern over ALL plants in my test shader this way:



    Then, and this is currently my main issue, there seems to be another problem with the vector offset in correspondence with the V-coordinates in general. No matter which calculation method I try, it seems that only the "bottom row textures" in the atlas are being offset correctly. Here is a "minimal approach" to bending grass using multiply *4.2 & frac and the result:
    As you can see, only the 4 bottom row textures are being bent, the rest is pushed around again. I even tried to hardcode the V-intervals in this "beautiful" construct, with the exact same result:

    The strange thing is these approaches to normalize the V-coordinate seem to be working for other aspects of the shader. For example I also reduce the opacity of the plants towards the ground so they blend better with the environment. For this aspect the V-coordiantes multiplied with 4.2 and frac seem to work just fine.


    Does anyone have any idea why I can't use the vertex offset properly even though I seem to have figured out & normalized the V-coordinate after the plant texture has been packed into the atlas?
     
    Ga2Z, Jesus and neoshaman like this.
  13. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Time to file a bug report, good job!
     
  14. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    That's actually really interesting, you may be the first person to openly publish that info as far as I'm aware.

    I assumed that others may have come across it, it at least to some degree used (copypasted) whatever is in the default grass shaders for their terrain shaders, but it's good to see these things in detail.
     
  15. OneManBandGames

    OneManBandGames

    Joined:
    Dec 7, 2014
    Posts:
    207
    Thank you both for commenting on this issue again. You mentioned the default grass shaders in your first reply already Jesus, and I totally forgot to look at them while I was occupied with my quest of deciphering the atlas packing / normalizing the v-coordinate.

    I had a look at the built-in shader today. Although I barely understand shader code, I found this comment regarding vertex colors in one of the shader functions:
    Code (CSharp):
    1. void WavingGrassVert (inout appdata_full v)
    2. {
    3.     // MeshGrass v.color.a: 1 on top vertices, 0 on bottom vertices
    4.     // _WaveAndDistance.z == 0 for MeshLit
    5.     float waveAmount = v.color.a * _WaveAndDistance.z;
    6.  
    7.     v.color = TerrainWaveGrass (v.vertex, waveAmount, v.color);
    8. }
    Could it be that easy? Yes, it is: By using the VertexColor node you get exactly the 0 >1 interval that I originally expected for the v-coordinate. Here it is applied in the "minimal bending shader", and the result:


    This is a perfect workaround for my original problem, as I can now just use the VertexColor node for all my v-coordinate needs. The issue from my post above ("Why is my normalized v-coordinate not properly applied to the vector offset for all plants?") still remains however. Do you think this might be a bug inside ShaderForge? If yes, I should indeed file a bug report so it can be investigated / fixed for the other users.
     
    Ga2Z and neoshaman like this.
  16. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Does anyone know how to apply a shader directly to the camera ? I can apply the postprocessing materials after I put a plane infront of the camera. Is there a way to make it so they work like a script ?
     
  17. retmia

    retmia

    Joined:
    May 31, 2013
    Posts:
    25
    Hello Everyone,
    I up my request because I haven't yet found how I can make that work ... anybody can help ?
    (Original post with pictures, just 12 messages before :))
    Kind Regards :)
     
  18. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    197
    Hey All,

    I have a small issue with a snow shader that was apparently made in shader forge (I did not make it so I don't have the shader forge data). When using realtime or baked lighting the shader looks great, it renders snow based on the normal map like it should. However when using mixed mode lighting, the shadow mask bakes correctly (can be seen by switching to shadow mask view) but the objects using the snow shader do not receive realtime light from the mixed directional source. Is this an issue with shader forge or can it be fixed if I can get the shader forge data? The issue is resolved by switching to the standard shader but then I loose the snow..

    Cheers,
    Colton

    Attached a copy of the shader for reference
     

    Attached Files:

    Phoenix116 likes this.
  19. ChainsawFilms

    ChainsawFilms

    Joined:
    May 28, 2016
    Posts:
    18
    I am trying to do a mosaic / pixelation shader but I'm not quite sure where to start with this one. Could someone please give me a nudge in the right direction, thank you :)
     
  20. OneManBandGames

    OneManBandGames

    Joined:
    Dec 7, 2014
    Posts:
    207
  21. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Hello everyone, not something I've needed until now, but I am hoping someone knows how to make a sprite/ui shader which utilises triplanar, or something similar to triplanar?
     
  22. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
  23. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
  24. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    Hey!

    While Unity's Standard Shader is affected, Shader Forge shaders don't seem to be affected by "Ambient Source" (Lighting tab -> Environment Lighting).

    Is this to be expected or can I solve this somehow? As a workaround, I don't really want to calibrate all the textures used in custom shaders to fit the scene.

    Image.jpg


    Best wishes,
    Shu
     
    Last edited: Sep 23, 2017
  25. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Has there been an update regarding this? Working with the latest beta most of my shaderforge shaders broke, and I can't open them in the editor.

    Console saying things like "WARNING: Shader Unsupported: 'Shader Forge/CharacterShader" - Pass 'FORWARD' has no vertex shader.

    It's odd because this is only happening on OSX builds. Editor works fine, and windows editor and builds work fine.

    Anyone have any suggestions?

    EDIT: The specific issue on OSX was due to the shaders excluding or not including metal as a compile target. Since I couldn't open them in the SF editor, editing the shader code by hand fixed this issue and allowed the shaders to work as expected on osx.
     
    Last edited: Jun 19, 2017
  26. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    I PM'd Ace, he said he's aware of the issue and he will fix it wtih an update in a week or two.
     
    DMeville likes this.
  27. ATeam_Production

    ATeam_Production

    Joined:
    Nov 23, 2013
    Posts:
    82
    Hello to all genious Shader Forge users!

    When I see some shaders that you create, it's just amazing.

    I'd like to know if it's possible to create a shader similar to his one with Shader Forge ?
    Does someone already do something like that : "Raymarching Shader" ?


    Could something similar could work on mobile platform ?

    Thank you in advance for your help
     
  28. DTek

    DTek

    Joined:
    May 29, 2013
    Posts:
    15
    Hello , purchased shader forge quite some time ago, it was mainly for our artists as I usually write my own shaders. However, nowadays I've found it to be an interesting tool and I thought I'd give it a try.

    There are 3 things I can't manage :
    1. I cannot get the latest version from the asset store. When I import it in Unity, I get 1.30, and when going to the asset store, there is no "Update" button. Removed and retried downloading several times won't do it.

    2. I cannot get the display in the right side of shaderforge ( the one seen in the tutorials ) to be seen. Is there any way to open that display ?

    3. How would I go about creating a shader ( possibly for post-effect ) that makes the entire screen black ( with a selectable alpha 0-1 ) , except for objects on certain layers ?
     
  29. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Working on realistic explosion shaders that makes use of basic camera multisampling. The lights create shadows from the volumetric explosion clouds as well as result in self-shadowing. There is too much noise due to few samples so it can run in realtime.



     
  30. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Wouldn't something like Temporal AA or FXAA have a field day with solving noise issues for that? Might be something to look into if you haven't already.

    Another thing I've found that helps with this sort of low-res noise is to add a shader-level jitter. Find out what half a 'pixel' or whatever is, then offset it by that every other frame.
     
  31. Deyuko

    Deyuko

    Joined:
    May 13, 2017
    Posts:
    1
    Hmm off the top of my head,
    You can either skin the mesh so only the op part changes color, however as long as the objects remain in that position (aka you dont roatate them) you can make the shader do the work for you as well

    1. You could use Sin or Cos and multiply with (Time node multiplied by a Value node, how fast you want it to change)
    Plug that into T part of lerp, plug the colors (green and yellow) you want in A and B (if you skinned your model skip part 2)
    2. Make a Channel Blend ("summed" in the drop down list) node, Plug the previous Lerp node into Gcol, Create a Normal Direction node and plug that into "Mask" of the Channel Bend node. Plug the color you want the rest of the cylinder to have (in the video this would be green)
    3. Plug it into diffuse

    That should do the trick with the color
    For the movement, I'm not sure.. I havent used it for a good while..
    Probabaly Normal Direction plugged into Comp.Mask (I think the color you need to select is B (Blue)) and plug that into a multiply
    Along with a Sin multiplied by time by frequency (a number), plugged into the same multiply


    I'm having some dificulties with shader forge after installing the new version of Unity, so I cant do a test run for you unfortunately
    But I hope at least that gave you some ideas where to start


    Edit: Oh right and you can create multiple materials and change the value to have some variety (the green nodes enable you to change stuff directly from the material)
     
    ATeam_Production likes this.
  32. Arkham

    Arkham

    Joined:
    Dec 16, 2013
    Posts:
    9
    Hello all --

    I'm trying to figure out why recompiling my shaders in a new version of SF/Unity is (apparently) breaking the shaders' normal lighting and reflecting capabilities.

    I was using SF version 1.25 under Unity 5.2.1f1 for quite a while, and created two existing shaders: a shader used for a brick wall, and another used for a glass bottle.

    I recently decided to upgrade both Unity and SF to more recent versions, but when I started making some edits to the shaders I noticed that the lighting on the objects became much brighter, and seemed to stop responding to the presence of reflection probes -- they look the same whether one is present or not. This change would occur even if I made no edits and just clicked "recompile" straight after opening the shaders.
    (And yes, I did make sure "Reflection probe support" is checked.)

    Screenshots below. The relevant parts are the wall and potion bottle glass:

    sf shaders recompiled.jpg
    Both of these images are from Unity 5.6.0f3, but the one on the left shows the shaders that were generated with the older version of SF and Unity, which look about how I intended them to look. The one on the right shows them after being recompiled in SF 1.37.

    Could someone help me figure out why the new version of SF is recreating the shaders in such an odd way, and what I might need to do to fix it and keep it consistent with the look/behavior of the old shader?
     
  33. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Does anyone know how to use vertex displacement maps? They work on flat surfaces where all the normals are facing upwards but they look funny when the mesh is spherical or have normals facing other directions as well.

     
  34. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    With a flat surface you're probably adding in the vertex offset in world space?

    You want to be adding it in normal space / tangent space, because you need that directionality. Be careful though as if you're adding Y (green) to get the offset to go up on a plane, you need to make that blue in normal tangent space. Red should make it go right, green up and blue out.
     
    hopeful likes this.
  35. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Yeah, is there a way to do that so it applies the displacement in tangent space rather than world space ?
     
  36. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Transform node.

    You'll probably want to transform from world space to tangent space? Honestly I'm not too sure on that node, and I've run out of goats that I usually sacrifice to it, but there's only 16 possible combinations out of the 2 x 4 options available.

    Out of curiosity, there is some option in the panel for vertex offset being in world space, or using normals, or something, have you found/tried that?
     
  37. ChameleonPower3DDev

    ChameleonPower3DDev

    Joined:
    Mar 14, 2017
    Posts:
    24
    Good morning everyone! I'm a new SF user and have been through some great tutorials but am still quite new to this. At my job I need to create a shader that can mask patterns with up to 4 substance materials on the same surface. The materials need to be swapped out at runtime as the user chooses. The only way we've been able to accomplish this thus far is by generating geometry into the patterns and then applying the different materials directly to it. Creating a different substance for each possible material combination is obviously out of the question so I'm wondering, is this something I can accomplish with a shader?
     
  38. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Typically a material will have a shader, and shaders don't have materials.

    The only way I can think of doing this is to use additive blending and PBR. Start with a normal PBR shader, then multiply albedo/emission by Vertex Color (red, for the first one). For normals, lerp between (0,0,1) and (normal map) by the same vertex color. Change the blending to One One (I think that's what additive is), but make sure it's still rendered as a solid object.

    Rinse and repeat until you've got one that uses Vertex Coors (G, B, A). For the object, give it 4 materials, each using one of the above shaders with that substance outputs plugged into albedo/normal/etc.

    Then you'll need to use a vertex painter to chance the vert colors.
     
  39. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    There's 2 options under the geometry tab, "relative" and "absolute", relative being the default selected one but those don't really help. I'm not sure what to use the transform node with because normally I don't multiply the vector displacement texture with the normal dir. node. I tried plugging it to the vector disp texture to the trasnform node but it ends up with pink error with most combinations.
     
  40. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Attempting to build a triplanar shader which uses different textures for each texture tile, so instead of having a texture with a 1 on it, and having the object have:

    1 1 1 1
    1 1 1 1
    1 1 1 1
    1 1 1 1

    I could have a set of textures on the shader like 1, 2, 3 and 4, and have a shader that tiles like so:

    1 4 3 1
    2 1 3 3
    1 1 4 2
    4 1 3 2

    Or something similar (or random, random is good :D)

    I was just wondering if this is possible.

    My current graph is getting a bit cramped as I added a sort of height-based dirt option, but here you go, is it possible to do the above?
     

    Attached Files:

  41. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    I'm having another look at this now, it seems like something I'd done before but can't find the project of. Can you post the displacement map for that (for parity) ?

    This I HAVE done before, different application but possible. The problems you might run into would be that if you were using 4 grass textures and randomly blending in one of them per square meter, then you're using 4 textures just for grass. You can get away with a lerp between all of those, and the dirt to save on heightmap blends, but if you then want 4 dirt textures, 4 sand textures, etc, that's a lot of textures. And remember they all have to work together, so you'd need 4 green-ish grasses and 4 dead/dry grasses, if they mid they'd look weird.

    The solution to that is to have a 2x2 Green Grass Atlas, and that'd save your texture inputs and sanity, otherwise you'd spend years scrolling through the materials inspector every time. Of course then you'd need to handle bilinear and trilinear filtering on textures that don't 'wrap' normally....
     
  42. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    The texture variations are not an issue, I build all of my texture sets procedurally from the ground up using Substance Designer, so I can create several variations with identical colour and blending, just with different dirt, scratches and paint, so I can make several sets which will snap together seamlessly in tiles, but look different.

    The issue is working out how to actually achieve this in a shader.

    I do remember that Portal 2 used something very similar for its wall tiles:



    If you look on the right, the 5th tile from the corner tiles on the second, third and fifth tile, this is due to the fact that the shader in Hammer uses all these different textures (about 20 of them (although, no height maps, or other special maps, just diffuse)) and then tiles them randomly around the surface using triplanar so BSP building can be used in-engine (same reason an in-game level editor was so easy, no complicated UV's).

    A different shader was used for the bottom ones which have the grime on.

    How this would be achieved in a shader in SF I have no idea, but if I could get it working it would be wonderful for me and speed things up hugely, and I would be more than happy to share with the community and release for free on the Asset Store, crediting anyone who could help.
     
  43. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Sure, this is the one I used.

     
  44. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    random_tile_borked_edges_and_rgb_dx11_offset.png

    few things to sort out as expected. The tiles are selected randomly, but since the randomness is done in the shader, it's calculating a random value at per pixel cost, instead of per tile. Might make it use an alternate method. Also, as expected the seams are borked but I can fix that.

    The RGB offset was a bit interesting. I tried some other farm animals, had some moderate success. I know you can work out lighting for a grayscale heightmap, but haven't even started trying to generate normals off this. I don't know how other programs handle it, but is there an accompanying normal map that's used with this displacement map?
     
  45. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    How did you get it to displace in all directions? Did you use something other than vector offset?

    No but with vector displacement maps you can probably use the same map for normals as well. Like this vector displacement map is packed the normals into the R and B channels while G is used to push the vertices off. And the result is you get a displacement map with accurate normals.

     
    deadlycrow likes this.
  46. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    Well the first problem then is the lack of stability when it comes to what does what. The first example was in tangent space, that's a world space displacement map, possibly a world space normal map (cue nonstop vomiting)

    I looked into it more, and there isn't any real agreed upon way to build normals for them. In offline renderers they tend to displace the mesh, then recalculate normals from that mesh, then apply the textures. For realtime stuff sometimes there's a normal map provided with the displacement's affect precalculated, other times there's nothing and other times they do a rough calculation of what the normals might be.

    I might add this into a utility shaders pack if I can get the normal calculation going nicely and relatively quickly. Will probably post more WIPs here though to give people some idea how it's going.

    BTW, that sphere with the pointy bits in my picture above. That's a Unity sphere with DX11 tesselation. Brace yourself lads, because it looked pretty bad at anything below level 7 tesselation and for that pic it's set to 15. You could get away with 11, maybe. Also I tiles that rgb displacement map 8x4 times though, so if you had a 1:1 texture map for the sphere you could probably get away with a lot less tesselation, but for finer details you WILL need to crank it up.


    EDIT:
    Did it the old fashioned way, unborked the edges of the tiles. Check the randomness on the left. Problem with this is that it's then set at an unchangeable atlas tile (in this case 2x2). I want to make it so that you just put in the atlas tiles (3x2, 1x4, whatever) and it just handles it but I have to do filtering in the shader, which sucks. On the plus side, it'd give me the ability to adjust for rarity of tiles (such as having a random broken one appear sometimes but not as often as the others).

    Tile dimensions can be set in the material, 1m wide and 1.5m high when vertical, 1m wide and long (when flat).

    This'll probably also end up in a USV pack with the one above, in the meantime I might get in touch with the lads at Probuilder see if they're interested.

    randomtile_unborked_edges.png
     
    Last edited: Jul 18, 2017
  47. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    This is looking really cool, great job.

    Having a rarity adjustment would mimic the Hammer (Portal 2) shader perfectly :D
    Also, I have noticed you are always using square tiles, is this due to your texture, or is it just how I would have to use it?
    Would I, for example when using 1w by 2h tiles on a texture, would they always have to be in 2's to make them square?

    Also, what image effects are you using? Your renders look so clean, and I'm not too good at balancing image effects :/
     
  48. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    In the texture it's just a 512x512 square, with 4 tiles in a 2x2 pattern. The changes I was talking about should hopefully let you assign a texture with whatever arbitrary amount of tiles.
    In-game however, I've set the wall tiles to be 1.5m high and 1m wide. the ground/ceiling ones are 1x1. Just plug those numbers into the material, easy to adjust. Also have an offset so you can raise all the tiles if you need to to align them with a ground plane at (say) Y=0.2m.

    Can you post a picture of the Hammer shader options? if they've put other stuff in there it's probably useful in some way.
     
  49. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    After a few hours of looking, I can't find the shader (Portal 2's files are like a maze).
    However, I was able to unpackage the pak01_dir.vpk file (Valve material/texture file package) and under materials/tile are most of the tile textures used in Portal 2, including the walls.

    I have uploaded the ones that seem relevant to the link below, which will be available for the next 30 days (July 18 2017 - August 17 2017).

    Please Note:
    THESE FILES ARE PROPERTY OF THE VALVE CORPORATION AND SHOULD NOT BE USED IN ANY PROJECT.

    https://ufile.io/k5y19

    As you can see from these files, the general layout of the Portal 2 wall tiles were 1m wide by 2m high (same layout I am using in my game), and their textures either contain a 2x1 or 4x2 in a variety of different styles.

    I wasn't able to get all the files, but white_wall_tile004e.png for example has 4x2 tiles, and is generally seen with white_wall_tile004d.png tiling with it.

    I haven't been able to confirm this, but I am fairly certain that in addition to using multiple diffuse maps, I am fairly certain Portal 2 also cuts the tiles into individual ones for dispersion, leading to a dual diffuse setup with maps like those mentioned in the sentence above would net 16 individual tiles which would be randomly dispersed, making the tiling effect almost undetectable.

    This is essentially what I would like to do, place multiple diffuse maps (along with normal and metallic (with inverted roughness in the alpha)(I know, it's a lot)), this would bring this method into a more PBR-friendly light and make it perfect for almost any instance when you would want to reuse textures, but not have them look the same everywhere.
     
  50. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    The textures are kinda interesting as a reference, but I meant the Hammer version of the material inspector like you'd find in Unity (where you plug in texture/color/etc with some sliders and numbers and such). The whole rarity thing would be one example of that - a slider to determine the probability of (tiles) appearing.

    One thing I might do is add a ghetto vertex painter - they're using different tiles for the top and bottom so you get the grime in corners - and have that control blending between different tile sets.