Search Unity

Shader Forge - A visual, node-based shader editor

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

  1. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    I have a 3D model in FBX format - which is modeled via 3DS Max - that has multi/subobject material assigned to, each material ID is connected to one multi/subobject, when I import it into Unity3D the 3D model cannot have those multi/subobjects all in one time, which means Unity3D doesn't support Multi/Subobject materials and MaterialIDs that 3DSMax generates, So I found out that I should detach each element that has a specific material ID as a new object then I should assign "standard material" to them, in this case my 3D model (which in fact was one object) would be more than one object and this messes the project management up and time wasting.

    With that said, how would I make Unty3D understand multi/subobject materials? Is this problem able to be fixed with ShaderForge?
     
  2. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    For Unity to understand Multi/subobject materials you would have to take a look at fbx Format and see if it actually provides meta data for these types of Information.
    If it does you would have to create your own mesh importer (called asset processor in Unity I guess) that assigns multiple materials to individual mesh parts.

    If you cannot do the above you are stuck to what you've been told to do. Or you could try to limit yourself to 4 "materials" per subobject and use vertex colors (RGBA) to tint the parts of your mesh that should use another material.
    In SF you would have to create a graph that blends different textures based on vertex Colors.

    my 2 Cents - there might be other Options... like using Maya
     
  3. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    That looks like a shadow to me... try turning off shadows for the lights to see if that's the issue.

    Does this awesome post by @Murgilod help? Or the second graph in this horrible post? Or this page on the wiki?
    [EDIT::] I suppose I should mention that the graphs by Murgilod and I rely on Vertex Color but wouldn't be much of a chore to re-purpose.
     
    Last edited: Jul 2, 2015
    DMeville likes this.
  4. sotec

    sotec

    Joined:
    Sep 14, 2012
    Posts:
    34
    I'm surprised that i missed @Murgilod 's post, i will try it tomorrow . thank you
     
  5. Ekibyou

    Ekibyou

    Joined:
    Feb 19, 2014
    Posts:
    10
    Double checked it, but that didn't help... The shader is the one in the sample assets, so I'm pretty sure that can't be wrong either. Any other ideas?
    Seems like it just wants to go to the top left corner, no matter what normal map with this effect I try.
     
  6. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    Thanks for your reply and attention to my post, but FBX files do have those data (at least the FBX file that I have for Unity3D has it) and I do got stuck for the problem, that's why I asked it here.
    What does Maya do that 3DS Max can't do in this "Material ID" case?

    I believe RGBA won't work for me - as you mentioned, limited material IDs.
     
  7. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    I just checked the Unity documentation and several posts on Unity answers. From reading the following pages I understand that Unity seems to support your 3dsmax material IDs:
    http://docs.unity3d.com/Manual/HOWTO-ImportObjectMax.html
    http://answers.unity3d.com/questions/430568/how-to-export-a-model-with-multipsub-object-materi.html
    http://answers.unity3d.com/questions/23513/3ds-max-unity-the-best-way-to-import-a-multisub-ob.html

    So I am not sure what is wrong on your end of the pipeline or if you are expecting a different result.
     
    imDanOush likes this.
  8. RUBILYN

    RUBILYN

    Joined:
    Jun 22, 2013
    Posts:
    54
    HELLO ! Everyone ...

    Is there a Way to do Vector Displacement With Shader forge Like in unreal Engine ??



    So we can model things with Mudbox or zbrush and bring properly to unity ...
    With distance based tessellation ...

    Can Someone Help finding a Way for it ? Please !!



    I tried with the Nodes bellow but i reaaly cant convert it to shaderforge ..

    Im So Desperate for this Feature that i could even pay or donate to someone that could release the nodes combination or custom node code method here ... Anyone to help please ?

    Thank you so much.

    Some Further Readings
    Vector Displacemnt in unreal :
    https://forums.unrealengine.com/showthread.php?5886-Vector-displacement-map
    Distance based tesselation in unreal :
    https://wiki.unrealengine.com/Distance_Based_DX11_Tesselation_-_Video
     
    Last edited: Jul 3, 2015
  9. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    633
    Hi, any chance of supporting Surface Shaders. I would like to prototype shaders quickly with SF and then edit them manually later, but vertex/fragment shaders are a bit out of my league presently and there is so much clutter in the generated shader.
    It would really help if you could support that and remove the reusable and boilerplate code to a .cginc or something and leave only the surf function and lighting model in the .shader file Please can you think about it Joachimo_O
     
  10. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    This is now implemented in 1.17 :)

    You can make vector displacement in SF, yeah. Just plug it into vertex offset, or displacement, if you're doing tessellation.

    No, Shader Forge is not made for Surface Shaders at all I'm afraid! It would require massive changes in order for that to work
     
    RUBILYN likes this.
  11. BigDill

    BigDill

    Joined:
    Jan 1, 2013
    Posts:
    31
    Hi all, very new to all of this and trust me to pick my first shader that is truning out to be a bit confusing. I have tried to replicate the following freely available shader and I am trying to translate it into Shader Forge so I can get some experience but I have fallen at the first hurdle! I can't seem to figure out how I get Shader Forge to represent appdata_base and have also struggled with the if statements and actually had a go at removing them by using clamp and step but it has all gone pear shaped. I love the product but have struggled to find any in depth tutorials? I suppose it is still early days still in terms of numbers of users and the amount of training information that is on the web?

    Anyway my question is about appdata_base and any reason why the following shader could not be translated into shader forge?

    Code (CSharp):
    1. Shader "Custom/planet" {
    2.     Properties {
    3.         _Tex0 ("Tex 0", 2D) = "white" {}
    4.         _Tex1 ("Tex 1", 2D) = "white" {}
    5.         _Tex2 ("Tex 2", 2D) = "white" {}
    6.         _Tex3 ("Tex 3", 2D) = "white" {}
    7.         _Tex4 ("Tex 4", 2D) = "white" {}
    8.      
    9.         _Blend0to1and1to2 ("Blend between 0 and 1, 1 and 2", Vector) = (0,1,2,3)
    10.         _Blend2to3and3to4 ("Blend between 2 and 3, 3 and 4", Vector) = (0,1,2,3)
    11.      
    12.     }
    13.     SubShader {
    14.         Lighting Off
    15.         Fog { Mode Off }
    16.         Pass {
    17.             Blend SrcAlpha OneMinusSrcAlpha
    18.             CGPROGRAM
    19.                 #pragma vertex vert
    20.                 #pragma fragment frag
    21.                 #include "UnityCG.cginc"
    22.                 #pragma target 3.0
    23.                 sampler2D _Tex0;
    24.                 sampler2D _Tex1;
    25.                 sampler2D _Tex2;
    26.                 sampler2D _Tex3;
    27.                 sampler2D _Tex4;
    28.                 float4 _Blend0to1and1to2;
    29.                 float4 _Blend2to3and3to4;
    30.                 uniform float4 _Tex0_ST;
    31.      
    32.                 struct v2f {
    33.                     float4 pos : SV_POSITION;
    34.                     float2 uv : TEXCOORD0;
    35.                     float4 col : COLOR;
    36.                 };
    37.              
    38.                 v2f vert (appdata_base vInput) {
    39.                     v2f OUT;
    40.                     OUT.pos = mul (UNITY_MATRIX_MVP, vInput.vertex);
    41.                     OUT.uv = TRANSFORM_TEX(vInput.texcoord, _Tex0);
    42.                     OUT.col = length(vInput.vertex);
    43.                     return OUT;
    44.                 }
    45.              
    46.                 half4 frag (v2f fInput) : COLOR {
    47.                     half4 c0 = tex2D (_Tex0, fInput.uv);
    48.                     half4 c1 = tex2D (_Tex1, fInput.uv);
    49.                     half4 c2 = tex2D (_Tex2, fInput.uv);
    50.                     half4 c3 = tex2D (_Tex3, fInput.uv);
    51.                     half4 c4 = tex2D (_Tex4, fInput.uv);
    52.                     if (fInput.col.x < _Blend0to1and1to2.x) return c0;
    53.                     if (fInput.col.x > _Blend0to1and1to2.x  fInput.col.x < _Blend0to1and1to2.y) return lerp(c0,c1,((fInput.col.x - _Blend0to1and1to2.x)/(_Blend0to1and1to2.y-_Blend0to1and1to2.x)));
    54.                     if (fInput.col.x > _Blend0to1and1to2.y  fInput.col.x < _Blend0to1and1to2.z) return c1;
    55.                     if (fInput.col.x > _Blend0to1and1to2.z  fInput.col.x < _Blend0to1and1to2.w) return lerp(c1,c2,((fInput.col.x - _Blend0to1and1to2.z)/(_Blend0to1and1to2.w-_Blend0to1and1to2.z)));
    56.                     if (fInput.col.x > _Blend0to1and1to2.w  fInput.col.x < _Blend2to3and3to4.x) return c2;
    57.                     if (fInput.col.x > _Blend2to3and3to4.x  fInput.col.x < _Blend2to3and3to4.y) return lerp(c2,c3,((fInput.col.x - _Blend2to3and3to4.x)/(_Blend2to3and3to4.y-_Blend2to3and3to4.x)));
    58.                     if (fInput.col.x > _Blend2to3and3to4.y  fInput.col.x < _Blend2to3and3to4.z) return c3;
    59.                     if (fInput.col.x > _Blend2to3and3to4.z  fInput.col.x < _Blend2to3and3to4.w) return lerp(c3,c4,((fInput.col.x - _Blend2to3and3to4.z)/(_Blend2to3and3to4.w-_Blend2to3and3to4.z)));
    60.                     return c4;
    61.                  
    62.                 }
    63.             ENDCG
    64.         }
    65.     }
    66. }
     
  12. KenneyNL

    KenneyNL

    Joined:
    Jun 16, 2015
    Posts:
    8
    Would an effect similar to the one below be possible in any way? (highlighting corners, giving them a sort of beveled look)

     
  13. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Possibly - the tricky part is to detect the corners. I'm not entirely sure how to do that in the best way possible. I would recommend adding additional vertices to vertex paint where you need those bevels
     
  14. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Pretty likely that the effect is simply from normals, as it only appears on one side.
    As for detecting corners, have you considered that the normals of the corners might be facing diagonally? (This could be done when generating the mesh).
     
  15. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Hue node coming in 1.17 :)
    The range 0 to 1 gives you the entire spectrum. Values ahead/beyond that range will make it wrap!
     
    RUBILYN likes this.
  16. Deleted User

    Deleted User

    Guest

    Can i make it so a shader that ignores certain objects?
    Its for a shader involving a lattice of intersecting planes.
    the planes have a desaturation shader using the "scene color" and desaturate node.
    I don't want the planes to acknowledge each-others presence.
     
  17. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    1.17 is now released!

     
    zenGarden and IFL like this.
  18. BigDill

    BigDill

    Joined:
    Jan 1, 2013
    Posts:
    31
    I just can't see what node will give me access to appdata_base. Ace, will I need to use the Code node to achieve the standard shader in my post above? Please can you advise?

    Thanks
     
  19. kuchaku

    kuchaku

    Joined:
    Oct 14, 2014
    Posts:
    37
    Hey, I recently bought Shader Forge. I'm developing a 2D tile-based game, and I'm wondering if anyone has any examples or advice in masking textures so they appear only on foreground elements and not on the background.

    I've read taking a render texture of the foreground camera and multiplying the texture to be drawn by this render texture's alpha would be useful for masking. However, I don't know how I'd implement such a solution in Shader Forge.

    I'd appreciate any advice or examples of feeding a render texture into Shader Forge comparing it with an on-screen texture's coordinates. Alternate solutions for masking 2D elements would be appreciated as well. Thank you.
     
  20. DavidMiranda

    DavidMiranda

    Joined:
    Nov 30, 2012
    Posts:
    617
    What about a #include "file.cginc"? :)
    Ive been waiting for a year ^^

    Cheers!
     
  21. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    appdata_base is just an output structure, you're already using it under an other name in SF :)

    It involves more than just SF I'm afraid, you need to do things in C# as well

    I'll add this in the next version!
     
  22. siluno

    siluno

    Joined:
    Jun 18, 2013
    Posts:
    1
    Hi. Hope this is the correct place to ask a question.
    Attached you will see the shader which I am referring to.
    Im trying to create a repeating tiled animated texture (caustic that basically animates )
    I used this link as a base which works fine until i tried to repeat the texture with a basic multiply node. The middle column would work fine, but the others would jitter for some reason? The way i 'fixed' that is to add the "frac" node at the end and in that way basically repeat the uv rather than the texture. This work, except at the edge of the repeating texture...where the old one stops and the next one starts...causing a seam.
    I assume this is some sort of texture bleed since the uv's are right next to each other?
    Does anybody have any suggestions as to correctly tile animated textures?


    tiled_anim.png caustics_sheet.jpg
     

    Attached Files:

  23. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    As far as I understand it, that's a precision problem related to rasterization. Frac used on anything but Time usually does that... I don't currently have a solution. That said, for your specific shader, you could rework the sequencing math for use with the world-space position. That might be a great exercise of patience though.
     
  24. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    Hello,

    First of: Shader Forge is amazing. I spent a few days learning shaders and i was getting frustrated that i couldnt get a simple mask working (almost had it though). Buying shader forge it took me 15 minutes to get very close to the desired result!

    Right now i'm trying to use a dissolve effect but it doesnt seem to fully "fade-in" as it where. always some artifacts left.
    Am i missing a crucial node?
     

    Attached Files:

  25. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Glad you like SF!
    As for dissolve, you generally use add instead of power. Try it :)
     
  26. BigDill

    BigDill

    Joined:
    Jan 1, 2013
    Posts:
    31
    I am sorry Ace but your response has not really helped me. I can't find any tutorials that allow me to see each node in operation and therefore I have no point of reference to determine what nodes I might need to emulate the shader code I shared above in a previous post.

    All I have to go on is the shader code I shared and the fact that I can't get the output structure in SF the same as the code! I know I am missing a crucial set of nodes but without some tutorial or clear advice I am stuck.

    From what I can tell the shader output is based on vertex height using a float4. How do I get SF to reproduce this? I have used the vertex node but it is not working out for me. haha, noobs buy Unity Assets as well as pros, and we need help too, but at a different level.

    Looking forward to a bit more documentation then I can leave you alone to focus on the next version.
    thanks
     
  27. Ga2Z

    Ga2Z

    Joined:
    Feb 16, 2012
    Posts:
    68
    Hello, this is not a Shader Forge related question but as you guys really know how to code shaders and I don't. I would like to ask this (I think is fairly easy to achive and solve it but I don't really know the right syntax)

    I need this shader to be able to use normal maps and use it in my terrain, it currently works defining a top and bottom colors according to world pos, I was going to use shader forge but terrain shaders in shader forge won't support normals yet, so I found this shader code, I find fairly easy to understand and I copy pasted the normal mapping part from the unity manual with no success :(

    here's the code:


    Code (CSharp):
    1.  
    2. Shader "Custom/HeightDependentTint"
    3. {
    4.    Properties
    5.    {
    6.      _MainTex ("Base (RGB)", 2D) = "white" {}
    7.      _Normal ("Normal (A)", 2D) = "bump" {}
    8.      _HeightMin ("Height Min", Float) = -1
    9.      _HeightMax ("Height Max", Float) = 1
    10.      _ColorMin ("Tint Color At Min", Color) = (0,0,0,1)
    11.      _ColorMax ("Tint Color At Max", Color) = (1,1,1,1)
    12.    }
    13.  
    14.    SubShader
    15.    {
    16.      Tags { "RenderType"="Opaque" }
    17.  
    18.      CGPROGRAM
    19.      #pragma surface surf Lambert
    20.  
    21.      sampler2D _MainTex;
    22.      sampler2D _Normal;
    23.      fixed4 _ColorMin;
    24.      fixed4 _ColorMax;
    25.      float _HeightMin;
    26.      float _HeightMax;
    27.  
    28.      struct Input
    29.      {
    30.        float2 uv_MainTex;
    31.        float2 uv_NormalMap;
    32.        float3 worldPos;
    33.      };
    34.  
    35.      void surf (Input IN, inout SurfaceOutput o)
    36.      {
    37.        half4 c = tex2D (_MainTex, IN.uv_MainTex);
    38.        float h = (_HeightMax-IN.worldPos.y) / (_HeightMax-_HeightMin);
    39.        fixed4 tintColor = lerp(_ColorMax.rgba, _ColorMin.rgba, h);
    40.        o.Albedo = c.rgb * tintColor.rgb;
    41.        o.Alpha = c.a * tintColor.a;
    42.        o.Normal = UnpackNormal (tex2D (_Normal, IN.uv_NormalMap));
    43.      }
    44.      ENDCG
    45.    }
    46.    Fallback "Diffuse"
    47. }
    Thanks.
     
  28. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Is anyone having issues with lightmaps in SF? We're on 5.1.1p3 - everything looks fine in the editor but on a device ( iOS ) everything becomes much darker. All renderers are assigned the correct index, offset, the lightmap atlas is correctly loaded. if i switch to a mobile/unlit with lightmap support shader, it works fine. When we use a shader forge shader, we're not sure what is causing this thing to darken so much. Unchecking the lightmap+lightprob check box makes it look like the same as a device/very close - not sure where we are going wrong. We've tried unchecking/checking a whole schwack load of things...on SF 1.16
     
  29. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    Add still doesnt give a complete 100% transparency.

    [edit] setting the value to -1 does make it 100% transparent and 1 makes it fully visible. Good enough!
     

    Attached Files:

    Last edited: Jul 8, 2015
  30. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Sorry if it didn't help. That said, don't take this the wrong way, but it's not my job to be everyone's personal technical artist. More than half of the support questions I get has very little to do with Shader Forge and is simply a question on how to make specific shaders.

    As for the shader, it's an unnecessarily expensive one. You generally want to avoid if-statements as much as possible in shader code.
    I would suggest not trying to translate that shader directly, and instead see what it does and try to figure out why it has the functionality it does, which, of course, may be difficult depending on how much shader code you know.

    So here's what you need:
    • Distance from the center of the object to the current fragment being rendered
      • In the shader code, this was done using length(v.vertex), but it's a bit more involved in SF
      • Take the world position, and subtract it by the object position, then use the length node
    • A per-channel offset of that distance to determine where to use which texture
      • The offset should be a Vector4 property, so you can tweak it per-material
      • You may need an initial offset to set where to start blending
      • You will need to clamp this to make sure it's in the 0-1 range
      • This is then used as a mask in the Channel Blend node mentioned below
    • Sample all the textures you need, and blend them based on that distance
      • Sampling textures is done using the Texture2D node
      • Blending is most commonly done using the Channel Blend node
    You can search for nodes in the node documentation here: http://acegikmo.com/shaderforge/nodes/
     
  31. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Does anyone know if it makes sense to apply translucence as a post effect (instead of a forward-rendering pass per batch) when using deferred lighting? Is using a forward-rendering shader with deferred lighting better on performance than another deferred camera in the scene (with close clipping) for use with a post effect?

    Also, I just noticed that there are now over 4000 posts in this thread. :eek:
     
  32. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    That is using it the same as if it was a forward camera (for those draw calls!).
    Can you explain what you want with "translucence"? If it doesn't really need subsurface scattering but just a translucency map there is some "space" that can be used in the deferred pipeline.
     
  33. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    I get that it's the same as using a forward camera for those draw calls. I'm intrigued by the "space" you mentioned. Are you referencing another channel in the buffer?
    [EDIT::] And I am wanting SSS, but only the illusion of it really.
     
  34. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Correct.

    SSS can only be approximated in realtime graphics, but one of the "cheapest" approximations that if commonly used for leaves ect is to have a "translucency map", basically allow so much (%) of the (diffuse) light to always be allowed, even tho it's in shadow because it's facing away. (If it's actually in shadow it does NOT get lit!).
     
    IFL likes this.
  35. KenneyNL

    KenneyNL

    Joined:
    Jun 16, 2015
    Posts:
    8
    The trouble is that I'd like the effect to work with any mesh in the scene, not just with cubes. I've been asking around on Twitter and Reddit but nobody has been able to give a neat solution to this sadly :(

    I thought I was onto something with depth blend (to fade a normal map attached to other blocks) but adding that bugs everything out...

     
  36. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    So, I don't know enough about writing to the deferred channels. Where might I find out about such sorcery? I'm assuming you were talking about writing to the alpha channel, but that's turning out to be useless, or at least the way I'm doing it is.
     
  37. Amnoon

    Amnoon

    Joined:
    Jul 20, 2013
    Posts:
    31
    Hi guys!

    I need some help with shader Forge and Unity 5. Maybe some one of you have already experimented this issue and have some idea about how to proceed. I made some custom lightning shaders in Unity 4 and when I upgraded the project to Unity 5 all shaders have become very clear and desaturate. I supose that it's the new PBR workflow and llighting but I really don't know how to fix it.

    As you can see in the picture in Unity 4 all shaders were fine but in Unity 5 I can't get the right colours of the shaders in the viewport.

     
  38. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    @Amnoon - The lighting halved in Unity5. Could that be the issue? I'd expect your shader to be darker, not brighter, but that's the best I can come up with. If you're using ambient light in your shader, you might check the unity editor's lighting tab to see if that's an issue... Also, your screenshots are gorgeous.
     
  39. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    If you want it to be applied to *everything*, you may be able to do it by customizing the deferred pipeline, to do some post-processing on the normal buffer. Though it's not going to be easy. Not sure if it's possible even :)
     
  40. Amnoon

    Amnoon

    Joined:
    Jul 20, 2013
    Posts:
    31
    Thanks IFL! It was a light problem. When I upgraded the project, the lights's intensity became the double. I really dont' know why. I was focused in the shader to fix the problem. Thanks a lot!. I am glad you like the style of the project!
     
    IFL likes this.
  41. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    There's a Video conference talk a few pages back where someone from Valve explains how they used ddx and ddy to create an edge detection shader to modify the glossiness/roughness of their surfaces.
    That edge detection could be helpful in achieving the look you are after. It can be done in SF (I tried).
     
    IFL likes this.
  42. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Not really, because Unity's ddy/ddx is per-triangle, and you wouldn't get edge-highlights properly either. It works well on tessellated smooth objects, but not on hard edges or low-poly meshes
     
  43. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Umm, so your saying unity has changed the way ddx/ddy works completly!?
    As normally it checkeds the adjecent pixel, (sometimes within a 2x2 render "block").
     
  44. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    I've heard it works properly on DX11, but on all other platforms it works on a per-triangle basis. I'd love to be wrong about this, so, let me know if I am :D
     
  45. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    sf_newshader_7102015.png
     
  46. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Is that sphere using hard edges or soft? And how does it look if you only output the normals?

    NVIDIA: http://http.developer.nvidia.com/Cg/ddx.html
     
  47. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Ok, perhaps it worked for me since I was using normal maps and was on a Windows DX11 project back then.
     
  48. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    It's a soft-edged sphere and the normals are smooth
     
  49. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Another solution:
    If in deferred you can use command buffers to read the normalmap, and blur it! (Before lighting is done), as that could give the beveled look. If this is only to be applied on some objects, then you can use the stencil buffer to tag them.

    If not in deferred you have a harder time, and one "simple" option is to use a more "complex" mesh for the cubes, so that using soft normals it actually does bevel the normal. Main downside of this is the extra poygons required. (You need to have quads that are pretty thin along each edge, with their normals facing straight out, then the corner normal facing diagonally if on a corner, if combined it would obviously face straight out again.

    If you don't need it to care about lighting, you can use the normals in screen space anyways, for an example look at the AA post processes. Unity has some in their standard assets, and I think some of them might be using normals, basically it's the DepthTextureMode.DepthNormals . Don't think it'd be easy to do with shader forge however without adding per-vertex data.
     
  50. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    http://www.gamedev.net/topic/599518-directx-ddxddy/
    And if you think about it, when you use ddx over a NOT very spherical sphere, then look at the CHANGE per pixel, well, the change varies alot from polygon to polygon. So the only really interesting part is to see if the pixels

    Interesting post, from what I understand actually claiming the behavior is correct, and another thing to think about is what happens where polygons "change", http://blog.selfshadow.com/2012/11/12/counting-quads/ , it causes overdraw, as each quad will be rendered if somewhat inside a polygon, even the pixels of the quad outside of it. So perhaps that is what is causing this?

    But as the OP for the question wants to FIND where the edges are, what happens with a Hard-edged object, then the DDX within the face should result in 0, and at the edges result in non-0!