Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

unity_SpecCube0 only error in PC platform

Discussion in 'Shaders' started by chenwuqiong, Dec 29, 2021.

  1. chenwuqiong

    chenwuqiong

    Joined:
    Jul 17, 2019
    Posts:
    3
    unity_SpecCube0 always be unityBlackCube in PC but right in mobile platforms. Thanks!!!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,379
    Are you by chance using deferred rendering? When using deferred, the reflections are rendered into the camera view during the deferred lighting passes. When using deferred rendering Unity defaults to per pixel reflection probes rather than per object reflection probes, thus the shader on your objects will not have anything but the black cube texture.

    On mobile, Unity disables deferred rendering and falls back to forward rendering. In doing so, reflection probes are per object again.

    Your options are:
    1. Disable deferred rendering entirely. Switch to using forward rendering for the project on both desktop and mobile. But this does mean you don't get the benefits of deferred rendering like effecient support for lots of real time lights. Though you're already not getting that on mobile.
    2. Disable deferred reflections entirely. Under the graphics settings you can change the Deferred Reflections shader from built-in to not supported. This will let you access the reflection probes in you object's shader, at the cost of falling back to per object reflections.
    3. Replace the deferred reflections shader. Depending on what your goal is, you might get what you want by replacing the built in deferred reflections shader with your own custom one. This is a good choice if you're looking to have a unique look to rejections on all (opaque) surfaces.
    4. Force this object's shader to be forward only. If you're writing a Surface Shader you can prevent it from rendering as deferred by either changing its queue to Transparent, or by adding
      exclude_path:deferred
      to the
      #pragma surface
      line. This can cause problems with some post processing effects like SSAO though, either excluding this object from receiving the AO, or making it "invisible" to the AO where the shape of the objects behind this one will be visible in the AO rendered over it.
     
    Meceka likes this.
  3. chenwuqiong

    chenwuqiong

    Joined:
    Jul 17, 2019
    Posts:
    3
    I dont use deferred rendering, just using forward rendering.
    My unity version is 2019.4.27 and URP is 7.3.1, I dont know whether that has any influence.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,379
    Does this shader work for you?
    Code (CSharp):
    1. Shader "Unlit/ReflectionProbeTest"
    2. {
    3.     Properties
    4.     {
    5.     }
    6.     SubShader
    7.     {
    8.         Tags {"RenderType" = "Opaque" "IgnoreProjector" = "True" "RenderPipeline" = "UniversalPipeline"}
    9.  
    10.         Pass
    11.         {
    12.             HLSLPROGRAM
    13.             #pragma vertex vert
    14.             #pragma fragment frag
    15.  
    16.             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    17.             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
    18.  
    19.             struct Attributes
    20.             {
    21.                 float4 positionOS : POSITION;
    22.                 float3 normalOS : NORMAL;
    23.  
    24.             };
    25.  
    26.             struct Varyings
    27.             {
    28.                 float4 positionCS : SV_POSITION;
    29.                 float3 normalWS : TEXCOORD0;
    30.                 float3 viewDirWS : TEXCOORD1;
    31.             };
    32.  
    33.             Varyings vert(Attributes input)
    34.             {
    35.                 Varyings output = (Varyings)0;
    36.  
    37.                 VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
    38.                 output.positionCS = vertexInput.positionCS;
    39.  
    40.                 VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS);
    41.                 output.normalWS = normalInput.normalWS;
    42.  
    43.                 half3 viewDirWS = GetCameraPositionWS() - vertexInput.positionWS;
    44.                 output.viewDirWS = viewDirWS;
    45.  
    46.                 return output;
    47.             }
    48.  
    49.             half4 frag(Varyings input) : SV_Target
    50.             {
    51.                 float3 reflectVec = reflect(-input.viewDirWS, input.normalWS);
    52.                 half3 reflect = DecodeHDREnvironment(SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, reflectVec, 0.0), unity_SpecCube0_HDR);;
    53.  
    54.                 return half4(reflect, 1.0);
    55.             }
    56.  
    57.             ENDHLSL
    58.         }
    59.     }
    60. }
     
  5. chenwuqiong

    chenwuqiong

    Joined:
    Jul 17, 2019
    Posts:
    3
    Oh, it works!!!!

    I loss this progress which leads to UnityBlackCube. Thanks verrrrrrrrrry much!!!