keijiro / Pcx

Point cloud importer & renderer for Unity
The Unlicense
1.35k stars 196 forks source link

iOS problem with AR Foundation #55

Open PabloBuitrago opened 4 years ago

PabloBuitrago commented 4 years ago

Hello Keijiro,

I want to congratulate you on the work of this Unity project it looks really cool.

I was currently working with Unity 2019.1.21f and AR Foundation 3.1.0, I had problems with the Pcx/Assets/Pcx/Runtime/Shaders/Point.shader shader since the graphics API used by the AR Foundation is OpenGLES3 (and not used OpenGLE2 because AR Foundation not supported but only shader when not used AR Foundation worked well) and in compilations in iOS it gave me this result:

New Project (1)

In the end, in the Point.shader file, change all the half to float, since you got the half non-recognition error when loading the point cloud. And I made it look good:

New Project

Any ideas why this happens? (I am loading .ply files at runtime after download with external cloud, now works in Android and iOS with AR Foundation)

Thanks

franMx commented 3 years ago

Hi, had a similar issue (using ipad). Solution by @PabloBuitrago is working nicely.

Boellis commented 1 year ago

Longshot here, but do you happen to still have the point.shader file? After trying this on my end, my pointlcouds either still don't show at all or showing pink.

Boellis commented 1 year ago

Longshot here, but do you happen to still have the point.shader file? After trying this on my end, my pointlcouds either still don't show at all or showing pink.

Incase anyone else runs into this issue in the future. Pablo's comment is correct. I had to move the PCX folder out of my package cache and directly into my Assets folder. I found that the script kept resetting otherwise, and wouldn't save the changes when converting from half to float. Here's the final script I ended up with per the recommendations above:

Shader "Point Cloud/Point" { Properties { _Tint("Tint", Color) = (0.5, 0.5, 0.5, 1) _PointSize("Point Size", Float) = 0.05 [Toggle] _Distance("Apply Distance", Float) = 1 } SubShader { Tags { "RenderType"="Opaque" } Pass { CGPROGRAM

pragma target 3.0

        #pragma vertex Vertex
        #pragma fragment Fragment

        #pragma multi_compile_fog
        #pragma multi_compile _ UNITY_COLORSPACE_GAMMA
        #pragma multi_compile _ _DISTANCE_ON
        #pragma multi_compile _ _COMPUTE_BUFFER

        #include "UnityCG.cginc"
        #include "Common.cginc"

        struct Attributes
        {
            float4 position : POSITION;
            float3 color : COLOR;
        };

        struct Varyings
        {
            float4 position : SV_Position;
            float3 color : COLOR;
            float psize : PSIZE;
            UNITY_FOG_COORDS(0)
        };

        half4 _Tint;
        float4x4 _Transform;
        float _PointSize;

    #if _COMPUTE_BUFFER
        StructuredBuffer<float4> _PointBuffer;
    #endif

    #if _COMPUTE_BUFFER
        Varyings Vertex(uint vid : SV_VertexID)
    #else
        Varyings Vertex(Attributes input)
    #endif
        {
        #if _COMPUTE_BUFFER
            float4 pt = _PointBuffer[vid];
            float4 pos = mul(_Transform, float4(pt.xyz, 1));
            float3 col = PcxDecodeColor(asuint(pt.w));
        #else
            float4 pos = input.position;
            float3 col = input.color;
        #endif

        #ifdef UNITY_COLORSPACE_GAMMA
            col *= _Tint.rgb * 2;
        #else
            col *= LinearToGammaSpace(_Tint.rgb) * 2;
            col = GammaToLinearSpace(col);
        #endif

            Varyings o;
            o.position = UnityObjectToClipPos(pos);
            o.color = col;
        #ifdef _DISTANCE_ON
            o.psize = _PointSize / o.position.w * _ScreenParams.y;
        #else
            o.psize = _PointSize;
        #endif
            UNITY_TRANSFER_FOG(o, o.position);
            return o;
        }

        half4 Fragment(Varyings input) : SV_Target
        {
            half4 c = half4(input.color, _Tint.a);
            UNITY_APPLY_FOG(input.fogCoord, c);
            return c;
        }

        ENDCG
    }
}
CustomEditor "Pcx.PointMaterialInspector"

}