Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Shader Forge - A visual, node-based shader editor

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

  1. Ryirs

    Ryirs

    Joined:
    Jan 9, 2015
    Posts:
    12
    @IFL that looks like an interesting graph :)
    I'm currently working with PBL and so forward as deferred doesn't seem to support BPL

    I'd like to go realistic eyes iris such as http://www.impactlab.net/wp-content/uploads/2010/12/iris3.jpg
    might be a but heavy but i don't display much in my scene so i don't mind trying to push it, and it's a good exercise to get to know shader forge :)
     
  2. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    738
    Yeah, reading it again, those lines seems like a constant texture.
    Any idea how I can achieve this type of specular (Or idk what that is.)? (The white wavy lines).
     
  3. Tomer3

    Tomer3

    Joined:
    Apr 19, 2015
    Posts:
    2
    Heyas, I try to battle with water reflections some more (my post on previous page).

    Now I'm using the Water.cs script from unity standard assets. With Unity5 WaterProDaytime reflections work right like they should.
    But when I try my own ShaderForge node shader I only see red color on water quad.

    Here's comparison with unity water and my water:

    this is my ShaderForge node setup:

    and here are my waterquad and camera settings:

    Reflect layers is Everything except Water layer (which is on water quad)

    I have created new RenderTexture object to project folder, and also Water material which uses the above SF shader as shown.

    What am I doing wrong?
    Seems a simple thing as I have done this before by manually writing shader, but I think I have the node setup somehow wrong :(
     
  4. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    In terms of performance, the difference between both is so tiny that you might as well just ignore it, math is probably faster and is far easier to change at run time since you have all the variables to play with.

    The shader attached to this post should give you what you are looking for.

    I also did that post a while back too, it might help you, I dont know.
     

    Attached Files:

    Marco-Sperling likes this.
  5. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    That looks really good, I hope you can reduce the nodes to something more manageable :p.
    But yeah, sadly even node editors tend to be confusing after a little bit of work, if we had a way to group nodes that might help but I understand that Ace has a lot of stuff to do and Shader Forge is really getting far too complex for a single person.

    Still, Shader Forge is such a great learning tool! If it didn't exist I wouldn't have learned Shader Programming at all, thanks a lot for that Ace !
     
    IFL likes this.
  6. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Wow, that's detailed. I'm doing this eye shader in my free time, so I can't promise anything spectacular, but I'm working on it. I'll share when it gets to a decent point.
    Without parallax in the shader...
    SF_EyeWithoutParallax2.gif
    With it...
    SF_EyeWithParallax2.gif
    Well, I think that's another texture-based line. Or, it might be a texture based line multiplied by the light spec somehow. I could see making a kind of flow-map/normal-map that bends the specular light around in a wavy, electric way, but that's a ton of effort and processor time.
     
  7. TrentSterling

    TrentSterling

    Joined:
    Jan 4, 2013
    Posts:
    99
    Been playing with Dithered Shadows in SF as I noticed that the Unity 5 standard shader dithers shadows on transparent materials. In Unity5 Standard Shader, on Hard Shadows, the dithering is quite apparent, but when you switch to soft shadows, the blurring hides the dithering and transparent shadows "Just Work!"

    Standard Dither Hard Shadows


    Standard Dither Soft Shadows


    ShaderForge Dither Soft Shadows


    I guess the Dithering is just smaller? Any way we can get this feature to work like it does in U5's shader?
     
  8. P1st3ll1

    P1st3ll1

    Joined:
    Dec 13, 2012
    Posts:
    69
    Guys, can someone help me make a perlin noise based ocean waves ?
    I don't know anything about coding =/
     
  9. gfunk

    gfunk

    Joined:
    Mar 17, 2015
    Posts:
    23
    Hi guys, I'm sure the following question has already been asked, but I just can't find it.

    How must I set-up the nodes to control the strength/intensity of a normal map?

    Thanks!
     
    Last edited: Apr 22, 2015
  10. Ryirs

    Ryirs

    Joined:
    Jan 9, 2015
    Posts:
    12
    @IFL it already looks promising :)
    Are you using textures or is it fully procedural ?
     
  11. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Regarding the iris - creating a substance in Substance Designer might be an option. You can go real crazy with these and you've got access to a whole bunch of image manipulation nodes like transforms, rotations, tiles, distance functions, blending functions, blurring filters etc. Parameters can be exposed to Unity. And these parameters can be animated (via script or animation is up to you).
    That way you could shrink your actual shader code down to the necessary lighting calculations. But you've got to keep in mind that animating the parameters creates a new set of textures in the background - so this is probably not something you want to do on 30 characters at the same time unless they share the same substance.
     
  12. Eideren

    Eideren

    Joined:
    Aug 20, 2013
    Posts:
    309
    @HenriqueGomez If you dont know anything about coding, starting an ocean shader is the worst way to learn, it is far too complex for someone who just started learning sf.

    @gfunk There's a bunch of ways you could go, if you just want to lower the base intensity of the normal map then lerp your normal map to a vector3 = 0, 0, 1 (0, 0, 1 in a normal map means that it is oriented in the same way as the geometry's normals) with an intenisty value.

    If you want to merge two normal maps, add both normal map and multiply the result by 0.5 .
     
  13. P1st3ll1

    P1st3ll1

    Joined:
    Dec 13, 2012
    Posts:
    69
    But that's why I asked for help, I don't know that much of coding, but I'm not a noob at it =/
    I just want to know how to make the function for the waves based either on Perlin Noise or Phillips Spectrum algorithm =/
     
  14. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    For learning, shrink your goals down to a minimum. So forget the perlin noise in the shader. Use a perlin texture for that instead. From there, play around with the UVs and combining samplers in different ways. Try changing the U or the V of a sampler that's being added with another sampler.
    Thanks. It's mostly procedural. I use the substance that I posted above for perlin and voronoi noise.
    That's a great idea. Create the base grayscale, metallic, and roughness in a substance before modifying them in the shader. Thanks.
     
  15. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    I don's suppose anyone knows where to put Heightmaps in Shader Forge? I cannot put them in the Normal slot as that is already being used, so I am at a loss as to work out where they go?
     
  16. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Well, what do you want the heightmap to do? If you want it to add detail as a displacement map, use the DX11 tessellation & offset. If you want it for parallax mapping, there's a parallax node for that. If you want it just to change the position of the vertices, use it with the vertex offset output.
     
  17. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    I am using it for Vertex Blending, I have the Diffuse and Normals hooked up and ready to go, but can't work out where the Heightmaps go.
    I am trying to get the textures to sit in the "crevices" of the texture below, and using the Heightmap to do that.
     
  18. karitoSAO

    karitoSAO

    Joined:
    Mar 22, 2013
    Posts:
    3
    I ASK IF algino of you know as skin shader (realistic ) is ago , also Called scattering luzto to
    if they say hows and bases ago agradeceria far my shader management is almost nil as graphics engine
     
  19. karitoSAO

    karitoSAO

    Joined:
    Mar 22, 2013
    Posts:
    3
    Le pregunto si algino de ustedes saben que hace shader piel (realista) es, también llamada dispersión luzto a
    si dicen cómo y bases Hace agradeceria mucho, mi gestión shader es casi nula como motor gráfico

     
  20. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    I don't understand your question. Are you asking if SF can create a Screen-space Skin shader?
    Short answer: No.
    Longer answer: You can prototype your image effect shader in SF, but you have to manually edit the shader code afterwards and create your own Image effect script that uses the shader.

    Or are you merely asking how to achieve believable Skin?
    Then you might find this interesting http://graphics.ucsd.edu/~henrik/papers/skin-analysis/skin-analysis.pdf and this http://www.manufato.com/?p=902 for authoring your specular map in general. But the last link is fairly old now and you should just take away some basics like the difference in specular shading between conductors and dielectrics.

    SF also offers you a transmission slot in the main node. You can bake a thickness map and use that to fake subscattering.
     
  21. gfunk

    gfunk

    Joined:
    Mar 17, 2015
    Posts:
    23
    Great stuff, thanks!
     
  22. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    I'm working on one of my old ones now. Any idea how to replace a step (smoothstep is garbage too) with a smooth transition?
    SF_HeightBlending.jpg
     
  23. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    738
    Hello guys, is there a way to do transmission and light wrapping on Custom lighting?
    I noticed these options are disabled when I selected the Unlit/Custom option.
     
  24. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Yes, but it's all manual. You'd have to calculate all of it yourself.
     
  25. Deleted User

    Deleted User

    Guest

    Is this what your looking for?

    This will make your mask as smooth or hard edged as you like.
     
    IFL likes this.
  26. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Here's my version of a height-blended shader that uses vertex colors for mapping. This is more of an example than something I'd suggest for production, but it's usable. For adding Alpha, it's only about 60 more nodes. The relevant portion for your problem specifically is: Multiply the height by the vertex color, Step it against all of the other maps, and get the Min of those Steps for each channel. The shadowing makes it look a little less flat, but it's double the blended nodes. Since you're working with vertex colors, and those show up as black in the editor, I highly suggest turning off the node previews since it bogs down the editor like crazy.
    SF_HeightBlending02.jpg
     

    Attached Files:

    DMeville likes this.
  27. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Yes! Thank you. I was looking for a way to do contrast, but it wasn't directly related to my Step problem. I just gave up looking for a solution to it since I think it requires multiple sampling, and that's no fun.

    [EDIT::] Actually, I think I could use a variation of that for a dynamic contrast between the two inputs...
     
    Last edited: Apr 23, 2015
  28. kevinjappel

    kevinjappel

    Joined:
    Apr 23, 2015
    Posts:
    2
    Has anybody else gotten the following error when trying to import Shader Forge into Unity 5 Version 5.0.0b11 (0)?

    "Error while importing package: Package has u nknown format"
     
  29. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Thanks a lot, Ill take a look at it and see what I can do.
     
  30. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    738
    I am trying to write a double-sided custom-lighting shader, that uses a saturated version of the main texture as its backface texture.

    How do I do this?

    This is the closest I can think of. (I am very new to shaders, I apologize if there is a nerve wrecking mistakes all over.)

     
  31. Dimlos

    Dimlos

    Joined:
    Aug 13, 2014
    Posts:
    51
    Hello everyone.
    I'm trying to make my own water shader, it looks good in editor view but when I hit play, everything that is Depth Blend related disapears.

    I have a script on my main camera to set the DepthTextureMode to Depth, (I can see on the main camera: "Info: renders Depth texture")
    my shader is not writing to the depth buffer, and is in lend mode : Alpha blended.

    I just realised that problem, I should've hit play sooner I guess ;).
    Shaderforge problem.jpg

    EDIT: It seems to work when I make a build :D... but now I saw that ingame, the reflection is not working properly (in game view or in build), I used this script and fixed some errors:
    http://wiki.unity3d.com/index.php/MirrorReflection3

    In scene view it's perfect, but in game view, it doesn't show the texture the right way at all.

    EDIT 2: The next day, the shader works perfectly when I hit play. I guess it just needed a reboot.
    I still have this reflection problem. Working on it, if anybody got an idea, feel free to tell me :p
    Here is a screenshot of my problem:

    reflection problem.jpg

    EDIT 3: I don't understand. In my player settings I have rendering path set to Forward.
    My camera is using player settings.
    In Scene view there isn't any problem but in game view the reflection is facing the wrong way. BUT if I set my main camera rendering path to Deffered it works!
    I don't understand why it works in scene view with forward but not in game view :( help.
     
    Last edited: Apr 24, 2015
    DMeville and IFL like this.
  32. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    I think you'd have to create a backface-only shader, then a frontface-only shader, and then a coded shader where you copy the passes of each previous one into it. I've had success doing similar. It's not great for iterating, but it's doable.
     
  33. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    738
    Hmm, I think that's something that has to be done from outside Shader Forge?
    If that's so, I guess it's a little bit too complicated for me to do.

    Well, thanks anyways!
     
  34. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Are both cameras (main & reflection) set to use player settings? if the reflection camera is created in code, it might need to be set. I'm not 100% sure about that.

    Yeah, that has to be done outside of SF. To do it inside would require that SF have custom multi-pass support (which was once kind-of on the roadmap but has since been understandably abandoned).
     
  35. Dimlos

    Dimlos

    Joined:
    Aug 13, 2014
    Posts:
    51
    I added some lines to make sure they both use Player setting (forward), but it's the same.

    I used the frame debugger and it seams that the camera that is created in code doesn't care about the rendering path, it creates the reflecction texture the right way there, and at the end, it is displayed the wrong way by the main camera.

    It only works in Scene view, does that mean that the Scene Camera is always in Deferred?
    Thanks for your answer.
     
  36. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    That is really strange... If it's rendering the reflection correctly but not using it correctly then that sounds like it's a problem with the way you're using it. I believe you're doing it properly though since it does work in deferred mode. If you feel like it, send me a unitypackage that contains only the necessary stuff and I'll take a look at it for you.
     
  37. Dimlos

    Dimlos

    Joined:
    Aug 13, 2014
    Posts:
    51
    I'm uploading a package with my scene and all its dependencies.
    I'll pm you the mega link, thank you :)

    I did not write the reflection code, I just fixed some errors, I do not have the C# level to code this by myself, but I'm working on that^^

    EDIT:
    IFL helped me and found a way to fix this problem!

    For anyone encountering this problem later:

    Scene and Game views are flipped, reflection is in the right way for the Scene view but not for the game view in Forward rendering. I don't know why.

    For the reflection I used this script on my water plane:
    http://wiki.unity3d.com/index.php/MirrorReflection3

    I fixed some errors since it was outdated (don't forget to have the script name and class name the same):
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. // This is in fact just the Water script from Pro Standard Assets,
    5. // just with refraction stuff removed.
    6.  
    7. [ExecuteInEditMode] // Make mirror live-update even when not in play mode
    8. public class Reflection : MonoBehaviour
    9. {
    10.     public bool m_DisablePixelLights = true;
    11.     public int m_TextureSize = 256;
    12.     public float m_ClipPlaneOffset = 0.07f;
    13.  
    14.     public LayerMask m_ReflectLayers = -1;
    15.  
    16.     private Hashtable m_ReflectionCameras = new Hashtable(); // Camera -> Camera table
    17.  
    18.     private RenderTexture m_ReflectionTexture = null;
    19.     private int m_OldReflectionTextureSize = 0;
    20.  
    21.     private static bool s_InsideRendering = false;
    22.  
    23.     // This is called when it's known that the object will be rendered by some
    24.     // camera. We render reflections and do other updates here.
    25.     // Because the script executes in edit mode, reflections for the scene view
    26.     // camera will just work!
    27.  
    28.     public void OnWillRenderObject()
    29.     {
    30.         if (!enabled || !GetComponent<Renderer>() || !GetComponent<Renderer>().sharedMaterial || !GetComponent<Renderer>().enabled)
    31.             return;
    32.  
    33.         Camera cam = Camera.current;
    34.         if (!cam)
    35.             return;
    36.  
    37.         // Safeguard from recursive reflections.      
    38.         if (s_InsideRendering)
    39.             return;
    40.         s_InsideRendering = true;
    41.  
    42.         Camera reflectionCamera;
    43.         CreateMirrorObjects(cam, out reflectionCamera);
    44.  
    45.         // find out the reflection plane: position and normal in world space
    46.         Vector3 pos = transform.position;
    47.         Vector3 normal = transform.up;
    48.  
    49.         // Optionally disable pixel lights for reflection
    50.         int oldPixelLightCount = QualitySettings.pixelLightCount;
    51.         if (m_DisablePixelLights)
    52.             QualitySettings.pixelLightCount = 0;
    53.  
    54.         UpdateCameraModes(cam, reflectionCamera);
    55.  
    56.         // Render reflection
    57.         // Reflect camera around reflection plane
    58.         float d = -Vector3.Dot(normal, pos) - m_ClipPlaneOffset;
    59.         Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d);
    60.  
    61.         Matrix4x4 reflection = Matrix4x4.zero;
    62.         CalculateReflectionMatrix(ref reflection, reflectionPlane);
    63.         Vector3 oldpos = cam.transform.position;
    64.         Vector3 newpos = reflection.MultiplyPoint(oldpos);
    65.         reflectionCamera.worldToCameraMatrix = cam.worldToCameraMatrix * reflection;
    66.  
    67.         // Setup oblique projection matrix so that near plane is our reflection
    68.         // plane. This way we clip everything below/above it for free.
    69.         Vector4 clipPlane = CameraSpacePlane(reflectionCamera, pos, normal, 1.0f);
    70.         Matrix4x4 projection = cam.projectionMatrix;
    71.         CalculateObliqueMatrix(ref projection, clipPlane);
    72.         reflectionCamera.projectionMatrix = projection;
    73.  
    74.         reflectionCamera.cullingMask = ~(1 << 4) & m_ReflectLayers.value; // never render water layer
    75.         reflectionCamera.targetTexture = m_ReflectionTexture;
    76.         GL.invertCulling = true;
    77.         reflectionCamera.transform.position = newpos;
    78.         Vector3 euler = cam.transform.eulerAngles;
    79.         reflectionCamera.transform.eulerAngles = new Vector3(0, euler.y, euler.z);
    80.         reflectionCamera.Render();
    81.         reflectionCamera.transform.position = oldpos;
    82.         GL.invertCulling = false;
    83.         Material[] materials = GetComponent<Renderer>().sharedMaterials;
    84.         foreach (Material mat in materials)
    85.         {
    86.             if (mat.HasProperty("_ReflectionTex"))
    87.                 mat.SetTexture("_ReflectionTex", m_ReflectionTexture);
    88.         }
    89.  
    90.         // Set matrix on the shader that transforms UVs from object space into screen
    91.         // space. We want to just project reflection texture on screen.
    92.         Matrix4x4 scaleOffset = Matrix4x4.TRS(
    93.             new Vector3(0.5f, 0.5f, 0.5f), Quaternion.identity, new Vector3(0.5f, 0.5f, 0.5f));
    94.         Vector3 scale = transform.lossyScale;
    95.         Matrix4x4 mtx = transform.localToWorldMatrix * Matrix4x4.Scale(new Vector3(1.0f / scale.x, 1.0f / scale.y, 1.0f / scale.z));
    96.         mtx = scaleOffset * cam.projectionMatrix * cam.worldToCameraMatrix * mtx;
    97.         foreach (Material mat in materials)
    98.         {
    99.             mat.SetMatrix("_ProjMatrix", mtx);
    100.         }
    101.  
    102.         // Restore pixel light count
    103.         if (m_DisablePixelLights)
    104.             QualitySettings.pixelLightCount = oldPixelLightCount;
    105.  
    106.         s_InsideRendering = false;
    107.     }
    108.  
    109.  
    110.     // Cleanup all the objects we possibly have created
    111.     void OnDisable()
    112.     {
    113.         if (m_ReflectionTexture)
    114.         {
    115.             DestroyImmediate(m_ReflectionTexture);
    116.             m_ReflectionTexture = null;
    117.         }
    118.         foreach (DictionaryEntry kvp in m_ReflectionCameras)
    119.             DestroyImmediate(((Camera)kvp.Value).gameObject);
    120.         m_ReflectionCameras.Clear();
    121.     }
    122.  
    123.  
    124.     private void UpdateCameraModes(Camera src, Camera dest)
    125.     {
    126.         if (dest == null)
    127.             return;
    128.         // set camera to clear the same way as current camera
    129.         dest.clearFlags = src.clearFlags;
    130.         dest.backgroundColor = src.backgroundColor;
    131.         if (src.clearFlags == CameraClearFlags.Skybox)
    132.         {
    133.             Skybox sky = src.GetComponent(typeof(Skybox)) as Skybox;
    134.             Skybox mysky = dest.GetComponent(typeof(Skybox)) as Skybox;
    135.             if (!sky || !sky.material)
    136.             {
    137.                 mysky.enabled = false;
    138.             }
    139.             else
    140.             {
    141.                 mysky.enabled = true;
    142.                 mysky.material = sky.material;
    143.             }
    144.         }
    145.         // update other values to match current camera.
    146.         // even if we are supplying custom camera&projection matrices,
    147.         // some of values are used elsewhere (e.g. skybox uses far plane)
    148.         dest.farClipPlane = src.farClipPlane;
    149.         dest.nearClipPlane = src.nearClipPlane;
    150.         dest.orthographic = src.orthographic;
    151.         dest.fieldOfView = src.fieldOfView;
    152.         dest.aspect = src.aspect;
    153.         dest.orthographicSize = src.orthographicSize;
    154.         //dest.renderingPath = src.renderingPath;
    155.     }
    156.  
    157.     // On-demand create any objects we need
    158.     private void CreateMirrorObjects(Camera currentCamera, out Camera reflectionCamera)
    159.     {
    160.         reflectionCamera = null;
    161.  
    162.         // Reflection render texture
    163.         if (!m_ReflectionTexture || m_OldReflectionTextureSize != m_TextureSize)
    164.         {
    165.             if (m_ReflectionTexture)
    166.                 DestroyImmediate(m_ReflectionTexture);
    167.             m_ReflectionTexture = new RenderTexture(m_TextureSize, m_TextureSize, 16);
    168.             m_ReflectionTexture.name = "__MirrorReflection" + GetInstanceID();
    169.             m_ReflectionTexture.isPowerOfTwo = true;
    170.             m_ReflectionTexture.hideFlags = HideFlags.DontSave;
    171.             m_OldReflectionTextureSize = m_TextureSize;
    172.         }
    173.  
    174.         // Camera for reflection
    175.         reflectionCamera = m_ReflectionCameras[currentCamera] as Camera;
    176.         if (!reflectionCamera) // catch both not-in-dictionary and in-dictionary-but-deleted-GO
    177.         {
    178.             GameObject go = new GameObject("Mirror Refl Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(), typeof(Camera), typeof(Skybox));
    179.             reflectionCamera = go.GetComponent<Camera>();
    180.             //reflectionCamera.renderingPath = RenderingPath.UsePlayerSettings;
    181.             reflectionCamera.enabled = false;
    182.             reflectionCamera.transform.position = transform.position;
    183.             reflectionCamera.transform.rotation = transform.rotation;
    184.             reflectionCamera.gameObject.AddComponent<FlareLayer>();
    185.             go.hideFlags = HideFlags.HideAndDontSave;
    186.             m_ReflectionCameras[currentCamera] = reflectionCamera;
    187.         }
    188.     }
    189.  
    190.     // Extended sign: returns -1, 0 or 1 based on sign of a
    191.     private static float sgn(float a)
    192.     {
    193.         if (a > 0.0f) return 1.0f;
    194.         if (a < 0.0f) return -1.0f;
    195.         return 0.0f;
    196.     }
    197.  
    198.     // Given position/normal of the plane, calculates plane in camera space.
    199.     private Vector4 CameraSpacePlane(Camera cam, Vector3 pos, Vector3 normal, float sideSign)
    200.     {
    201.         Vector3 offsetPos = pos + normal * m_ClipPlaneOffset;
    202.         Matrix4x4 m = cam.worldToCameraMatrix;
    203.         Vector3 cpos = m.MultiplyPoint(offsetPos);
    204.         Vector3 cnormal = m.MultiplyVector(normal).normalized * sideSign;
    205.         return new Vector4(cnormal.x, cnormal.y, cnormal.z, -Vector3.Dot(cpos, cnormal));
    206.     }
    207.  
    208.     // Adjusts the given projection matrix so that near plane is the given clipPlane
    209.     // clipPlane is given in camera space. See article in Game Programming Gems 5 and
    210.     // http://aras-p.info/texts/obliqueortho.html
    211.     private static void CalculateObliqueMatrix(ref Matrix4x4 projection, Vector4 clipPlane)
    212.     {
    213.         Vector4 q = projection.inverse * new Vector4(
    214.             sgn(clipPlane.x),
    215.             sgn(clipPlane.y),
    216.             1.0f,
    217.             1.0f
    218.         );
    219.         Vector4 c = clipPlane * (2.0F / (Vector4.Dot(clipPlane, q)));
    220.         // third row = clip plane - fourth row
    221.         projection[2] = c.x - projection[3];
    222.         projection[6] = c.y - projection[7];
    223.         projection[10] = c.z - projection[11];
    224.         projection[14] = c.w - projection[15];
    225.     }
    226.  
    227.     // Calculates reflection matrix around the given plane
    228.     private static void CalculateReflectionMatrix(ref Matrix4x4 reflectionMat, Vector4 plane)
    229.     {
    230.         reflectionMat.m00 = (1F - 2F * plane[0] * plane[0]);
    231.         reflectionMat.m01 = (-2F * plane[0] * plane[1]);
    232.         reflectionMat.m02 = (-2F * plane[0] * plane[2]);
    233.         reflectionMat.m03 = (-2F * plane[3] * plane[0]);
    234.  
    235.         reflectionMat.m10 = (-2F * plane[1] * plane[0]);
    236.         reflectionMat.m11 = (1F - 2F * plane[1] * plane[1]);
    237.         reflectionMat.m12 = (-2F * plane[1] * plane[2]);
    238.         reflectionMat.m13 = (-2F * plane[3] * plane[1]);
    239.  
    240.         reflectionMat.m20 = (-2F * plane[2] * plane[0]);
    241.         reflectionMat.m21 = (-2F * plane[2] * plane[1]);
    242.         reflectionMat.m22 = (1F - 2F * plane[2] * plane[2]);
    243.         reflectionMat.m23 = (-2F * plane[3] * plane[2]);
    244.  
    245.         reflectionMat.m30 = 0F;
    246.         reflectionMat.m31 = 0F;
    247.         reflectionMat.m32 = 0F;
    248.         reflectionMat.m33 = 1F;
    249.     }
    250. }

    For the shader itself, what you need to do in order to flip the Game view is the following:
    fix.jpg

    You can use a switch if you want an easy way to go back and forth from a correct scene/game view.
    I did not find a way to make both view work in forward rendering for now.

    Thanks a lot to IFL. :)
     
    Last edited: Apr 24, 2015
    IFL likes this.
  38. Deleted User

    Deleted User

    Guest

    Is it faster/less expensive to put a front face and back-face sf shader into one shader onto one material? rather than 2 materials with separate shaders.
     
  39. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,294
    Yes
     
  40. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    Does anyone know why two equal shaders on equal objects would handle shadows differently? I'm using the same inputs on the main output node in SF for both shaders. One receives shadows, and one doesn't. Plugging the exact same values into the exact same output slots produces different results. Both shaders were created using the SF start screen. Blending settings are the same, lighting settings are the same, and the targets are the same.
    SF_ShadowIssue.jpg

    [EDIT::] Okay, so the fix is to change the lighting to forward, set blend mode to alpha-blended, compile, set the blend mode to opaque, set the lighting back to deferred, and compile again. What. I can't reproduce it, but it seems as if first compiling the shader in forward and using opacity was the cause. Probably just a fluke. Cheers.
     
    Last edited: Apr 25, 2015
  41. Deleted User

    Deleted User

    Guest

  42. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
  43. Deleted User

    Deleted User

    Guest

    1.I built in ShaderForge my custom shader (it modifies RGB values from texture2d titled "MainTex"). Shader works perfectly when applied in material on mesh surface, but It doesn't work properly when I apply this as Post Processing Effect.
    I use this script:

    var mat: Material;

    function OnRenderImage(src: RenderTexture, dest: RenderTexture) {
    // Copy the source Render Texture to the destination,
    // applying the material along the way.
    Graphics.Blit(src, dest, mat);
    }


    and shader works, but screen pixels are little darker :(. Why RGB values are different (surface material vs rendertexture). I should modify script or this is SF bug ?
    ----------------------------------------------------------------------------------------
    2. Does anyone have Parallax Occlusion Mapping self-shadowing node layout for SF ? I would like to implement this algorithm:
    http://www.cs.utah.edu/~sujin/courses/reports/cs6610/project-report/report.html
    (POM with soft shadows).
    ----------------------------------------------------------------------------------------
    3. Will Shader Forge support Compute Shaders ?
    http://docs.unity3d.com/Manual/ComputeShaders.html
     
  44. Deleted User

    Deleted User

    Guest

    How can i gat a value based on the col of what is behind/near the object... Any kind of simple and cheap value. (I.E a number between 0 and 1)
    If I could get an average color of a texture read from the y axis of its surroundings, that would be brilliant. can you average a texture into a color/value?
     
    Last edited by a moderator: Apr 25, 2015
  45. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    There's a link somewhere in this thread to a post-process script that works great with SF.

    POM requires a For loop, which means you'd need to use the code node. I don't know about compute shaders.
    Scene Color node. It's neat. You can multi-sample it to create blurring if that's what you're planning on.
     
  46. mrDewitt77

    mrDewitt77

    Joined:
    Apr 26, 2015
    Posts:
    3
    Hi,everyone.
    So...I need a little help with my shader.
    I dont know how to apply "DepthBlend clip"using code.
    Sorry for my bad English,and Thanks in advance. help.PNG help2.PNG
     
  47. Deleted User

    Deleted User

    Guest

    IFL
    What is multisampling? how do I multi-sample it to create blur??
     
    Last edited by a moderator: Apr 26, 2015
  48. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    When you simply plug a texture node into your shader graph you are already sampling the texture once at the UV coordinates provided by either you or the mesh.
    Multisampling means that you read multiple color information from the texture - most of the time you use UV offsets derived from the actual texture resolution. E.g. offsetX = UV.x + (1 / 512), offsetY = UV.y + (1/512)
     
    IFL likes this.
  49. Deleted User

    Deleted User

    Guest

    Thanks, Another question: I have this y projected texture.

    I want the "col map" texture to automatically align with the same texture on a unity terrain.
    The position of the texture already alligns automaticalybut not the scale, i can align the texture by fiddling with the tiling for 4 mins. I don't want to to do that.
     
  50. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    What do you mean that the scale isn't "aligned"? If you want to scale the y-projected UVs, multiply the output of the Append node by a scale value.