Search Unity

unity 5.6.4 vertex fragment shader add shadow not correct.

Discussion in 'Shaders' started by dreamerflyer, Dec 26, 2017.

  1. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Code (CSharp):
    1. Shader "Custom/SolidColor" {
    2.     SubShader {
    3.         Pass {
    4.        
    5.             // 1.) This will be the base forward rendering pass in which ambient, vertex, and
    6.             // main directional light will be applied. Additional lights will need additional passes
    7.             // using the "ForwardAdd" lightmode.
    8.             // see: http://docs.unity3d.com/Manual/SL-PassTags.html
    9.             Tags { "LightMode" = "ForwardBase" }
    10.        
    11.             CGPROGRAM
    12.             #pragma vertex vert
    13.             #pragma fragment frag
    14.             #include "UnityCG.cginc"
    15.             // 2.) This matches the "forward base" of the LightMode tag to ensure the shader compiles
    16.             // properly for the forward bass pass. As with the LightMode tag, for any additional lights
    17.             // this would be changed from _fwdbase to _fwdadd.
    18.             #pragma multi_compile_fwdbase
    19.             // 3.) Reference the Unity library that includes all the lighting shadow macros
    20.             #include "AutoLight.cginc"
    21.             struct v2f
    22.             {
    23.                 float4 pos : SV_POSITION;
    24.                
    25.                 // 4.) The LIGHTING_COORDS macro (defined in AutoLight.cginc) defines the parameters needed to sample
    26.                 // the shadow map. The (0,1) specifies which unused TEXCOORD semantics to hold the sampled values -
    27.                 // As I'm not using any texcoords in this shader, I can use TEXCOORD0 and TEXCOORD1 for the shadow
    28.                 // sampling. If I was already using TEXCOORD for UV coordinates, say, I could specify
    29.                 // LIGHTING_COORDS(1,2) instead to use TEXCOORD1 and TEXCOORD2.
    30.                 LIGHTING_COORDS(0,1)
    31.             };
    32.             v2f vert(appdata_base v) {
    33.                 v2f o;
    34.                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    35.                
    36.                 // 5.) The TRANSFER_VERTEX_TO_FRAGMENT macro populates the chosen LIGHTING_COORDS in the v2f structure
    37.                 // with appropriate values to sample from the shadow/lighting map
    38.                 TRANSFER_VERTEX_TO_FRAGMENT(o);
    39.                
    40.                 return o;
    41.             }
    42.             fixed4 frag(v2f i) : COLOR {
    43.            
    44.                 // 6.) The LIGHT_ATTENUATION samples the shadowmap (using the coordinates calculated by TRANSFER_VERTEX_TO_FRAGMENT
    45.                 // and stored in the structure defined by LIGHTING_COORDS), and returns the value as a float.
    46.                 float attenuation = LIGHT_ATTENUATION(i);
    47.                 return fixed4(1.0,0.0,0.0,1.0) * attenuation;
    48.             }
    49.             ENDCG
    50.         }
    51.     }
    52.    
    53.     // 7.) To receive or cast a shadow, shaders must implement the appropriate "Shadow Collector" or "Shadow Caster" pass.
    54.     // Although we haven't explicitly done so in this shader, if these passes are missing they will be read from a fallback
    55.     // shader instead, so specify one here to import the collector/caster passes used in that fallback.
    56. //   Fallback
    57.     }
    sd.png
    why appear the shadow out of the shadowmap distance?how to remove~
     
  2. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
  3. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    this is bug??
     
  4. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
  5. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
  6. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
  7. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    still nobody??o_O
     
  8. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    (Case 987949) shader function LIGHT ATTENUATION() is wrong. HOPE TO FIX THIS!
     
  9. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    bug.jpg
    No Fixed ....
     
  10. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    still not fixed.
     
  11. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    after add Fallback "VertexLit",it is ok in opengl ,but still not fixed in vulkan,any help? vulkan.jpg
     
  12. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
  13. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    still not fixed
     
  14. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
  15. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    I feel like the amount of bumping you do is only making people less likely to help rather than more likely. You have already reported it as an issue, and that is the official way to go about this so I would stay hang tight and wait, or start a conversation with a unity developer here using the conversation function of the forum.

    Just bumping after bumping is not going to increase the likeliness of anyone responding, if it did'nt work the first few times it probably wont for the next.

    Unfortunately I am not savvy on this topic enough to help, Good luck to you!

    EDIT:

    Also, is there a reason you are on 5.6.4, a very strange release version to stay on?

    This issue is not present in 2017.X
     
  16. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Thanks your reply,This issue will appear in mobile devices with not opengl es gpu,like vulkan and metal,and the project is using unity 5.6.4.I had send email to unity bug team many times,but they connect with me with different people for this issue,and wait and wait....
     
  17. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    honestly, try updating and see if that helps. 2017 will sort this i believe
     
  18. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    My Project had use 5.6.4 ,and close to release,it is big risk to update unity version.
     
  19. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    right but you are unlikely to get a fix to this then. so up to you?
     
  20. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    hope unity bug team to fix it.If not ,maybe I should change to try use surface shader,but will cost big performance than vertex fragment shader
     
    MadeFromPolygons likes this.
  21. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    I mean unity 5 is a 2 year old release now. Unity 2017 is last years release. What I am saying is, your relying on unity coming and fixing a legacy version for a single bug that has existed a while.

    Chances are they wont or not in time. So upgrade, change to surface shader, or live with the bug. Those unfortunately are your options.
     
  22. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    emm....let me try unity 2017 tommorrow ,then think how to do.
     
    MadeFromPolygons likes this.
  23. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    Dont worry, if you use 2017.3 (dont use 2017.1 or 2017.2, too many bugs) you will be okay. We have done many upgrades and compatability between those two versions is pretty good.
     
    dreamerflyer likes this.
  24. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Unlucky,Test with 2017.3.1.p2,Vulkan mobile devices still not correct....,opengl es3.0 is right
    SHADOW.jpg
     
    MadeFromPolygons likes this.
  25. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Unity QA team ,if u see this,pls check this case,thanks!
     
  26. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Fixed by myself...
     
  27. flyf

    flyf

    Joined:
    Mar 27, 2017
    Posts:
    3
    how to fix this bug? some problem to me....
     
  28. apple_juicetin

    apple_juicetin

    Joined:
    Sep 5, 2015
    Posts:
    4
    Have the same problem too but on Unity 2018.2.14f1 and OpenGL ES. Would love to hear your solution!
     
  29. flyf

    flyf

    Joined:
    Mar 27, 2017
    Posts:
    3
    unity 5.3 is ok..F***....
     
  30. flyf

    flyf

    Joined:
    Mar 27, 2017
    Posts:
    3
    i found a method to solve this in unity5.6. change tier settings. do not use defaults.and change Cascaded Shadows to true.
    boring method like lightmap in mobile.
     

    Attached Files:

  31. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    Same problem with OpenGL2.

    Is a shader issue with OpenGL, don't happen in Editor and OpenGL3 is ok. I fix it doing the attenuation by myself inside the shader.