Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Shader not working with Deffered Lighting

Discussion in 'Shaders' started by Mars91, Jun 4, 2014.

  1. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    560
    I found this shader here on the forum and it's working but not in Deffered Lighing. What should I have to do to make it work with Deffered?

    Code (csharp):
    1.  
    2. Shader"DiffuseToon" {
    3. Properties
    4.  {
    5. _Color ("MainColor", Color) = (.5,.5,.5,1)
    6. _OutlineColor ("OutlineColor", Color) = (0,1,0,1)
    7. _Outline ("Outlinewidth", Range (0.002, 0.03)) = 0.01
    8. _MainTex ("Base (RGB)", 2D) = "white" { }
    9.  }
    10.  
    11. SubShader
    12.  {
    13. Tags { "RenderType"="Opaque" }
    14. LOD200
    15.  
    16.  
    17. CGPROGRAM
    18. #pragmasurfacesurfLambert
    19.  
    20. sampler2D_MainTex;
    21. fixed4_Color;
    22.  
    23. structInput {
    24. float2uv_MainTex;
    25.  };
    26.  
    27. voidsurf (InputIN, inoutSurfaceOutputo) {
    28. fixed4c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    29. o.Albedo = c.rgb;
    30. o.Alpha = c.a;
    31.  }
    32. ENDCG
    33.  
    34. Pass
    35.  {
    36. Name"OUTLINE"
    37. Tags { "LightMode" = "Always" }
    38.  
    39. CGPROGRAM
    40. #pragmaexclude_renderersgles
    41. #pragmaexclude_renderersd3d11xbox360
    42. #pragmavertexvert
    43.  
    44. structappdata {
    45. float4vertex;
    46. float3normal;
    47.  };
    48.  
    49. structv2f {
    50. float4pos : POSITION;
    51. float4color : COLOR;
    52. floatfog : FOGC;
    53.  };
    54. uniformfloat_Outline;
    55. uniformfloat4_OutlineColor;
    56.  
    57. v2fvert(appdatav) {
    58. v2fo;
    59. o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    60. float3norm = mul ((float3x3)UNITY_MATRIX_MV, v.normal);
    61. norm.x *= UNITY_MATRIX_P[0][0];
    62. norm.y *= UNITY_MATRIX_P[1][1];
    63. o.pos.xy += norm.xy * o.pos.z * _Outline;
    64.  
    65. o.fog = o.pos.z;
    66. o.color = _OutlineColor;
    67. returno;
    68.  }
    69. ENDCG
    70.  
    71. CullFront
    72. ZWriteOn
    73. ColorMaskRGB
    74. BlendSrcAlphaOneMinusSrcAlpha
    75. SetTexture [_MainTex] { combineprimary }
    76.  }
    77.  }
    78.  
    79. Fallback"Diffuse"
    80. }
    81.  
     
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    It looks like you're missing a lot of spaces in your shader. Did you copy and paste in a weird way, or perhaps the new forum software is breaking your stuff?
     
  3. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    560
    I just copied it, however here's the shader file.
    Really hope you can help me.

    Cheers
     

    Attached Files:

  4. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Someone might be able to help you if you explain the problem in detail. "Not working" is about as vague as descriptions of problems get.
     
  5. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    560
    I'm so sorry.
    The problem is that the outline is not showing in deffered.
     
  6. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Looking at the code, I'm not sure why that would be. Unless extra passes aren't executed on surface shaders under deferred lighting, you should still get the outlines rendered in the right places.
     
  7. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    560
    I do not think that there could be any problem with my PC, I tried it on 3 different PC (MAC and Windows). COuld you try it on you PC? With both deffered and forward rendering.