相机在 ios 中捕获的 alpha 值

alpha value captured by camera in ios

我正在尝试使用 RenderTexture 制作假阴影

我动态创建了一个摄像机,并将一个 RenderTexture 分配给摄像机作为渲染目标。 RenderTexture 的格式设置为 ARGB32

然后我使用 RenderTexture 作为带有自定义着色器的平面上的纹理,将颜色更改为黑色并调整 alpha 值,以便可以正确显示阴影

下面是我使用的着色器:

Shader "Fake Shadow" {
    Properties {
        _ShadowTex ("Fake Shadow", 2D) = "white" { TexGen ObjectLinear }
        _SAlpha ("Shadow Intensity", float) = 0.35
    }
    Category {
        Tags { "Queue" = "Transparent-1" }
        Lighting Off
        ZWrite On
        Cull Back
        Blend SrcAlpha OneMinusSrcAlpha, one one
        Subshader { 
            LOD 200

            Pass {
                SetTexture[_ShadowTex] {
                    ConstantColor(0,0,0,[_SAlpha])
                    matrix [_ProjMatrix] 
                      Combine texture * constant, texture * constant
                }
            }
        }
    }
}

当我在 Unity3D 编辑器和 Android 上测试游戏时一切正常 但是,ios

中的结果不正确

结果图片在下面的 link 中(抱歉我还不能 post 图片)

shadow in editor
shadow in ios

似乎 ios 在 RenderTexture 中将 alpha 设置为 1,即使在相机没有捕捉到任何东西的像素上也是如此

我找到了解决这个问题的方法,就是在播放器设置中检查 32 位显示 但我担心检查32位显示会影响性能

有没有不检查32位显示的其他解决方案?

我正在做同样的事情(用于模拟阴影的相机和投影仪),并且我使用基于此页面上的着色器:http://en.wikibooks.org/wiki/Cg_Programming/Unity/Projectors

着色器如下:

Shader "Cg projector shader for drop shadows" {
   Properties {
      _ShadowTex ("Projected Image", 2D) = "white" {}
      _ShadowStrength ("Shadow Strength", Float) = 0.65
   }
   SubShader {
      Pass {      
//          Blend Off
          Blend Zero OneMinusSrcAlpha // attenuate color in framebuffer 
            // by 1 minus alpha of _ShadowTex
            // fb_color = black + fb_color * OneMinusShadowAlpha;
         CGPROGRAM

         #pragma vertex vert
         #pragma fragment frag

         // User-specified properties
         uniform sampler2D _ShadowTex;

         uniform float _ShadowStrength;

         // Projector-specific uniforms
         uniform float4x4 _Projector; // transformation matrix 
            // from object space to projector space 

          struct vertexInput {
            float4 vertex : POSITION;
            float3 normal : NORMAL;
         };
         struct vertexOutput {
            float4 pos : SV_POSITION;
            float4 posProj : TEXCOORD0;
               // position in projector space
         };

         vertexOutput vert(vertexInput input) 
         {
            vertexOutput output;

            output.posProj = mul(_Projector, input.vertex);
            output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
            return output;
         }


         float4 frag(vertexOutput input) : COLOR
         {
            if (input.posProj.w > 0.0) // in front of projector?
            {
               return tex2D(_ShadowTex , 
                  float2(input.posProj) / input.posProj.w) * _ShadowStrength;
            }
            else // behind projector
            {
               return float4(0.0);
            }
         }

         ENDCG
      }
   }  
   // The definition of a fallback shader should be commented out 
   // during development:
   // Fallback "Projector/Light"
}