Search code examples
scenekitfragment-shadervertex-shaderscnprogram

Odd border line on SCNPlane when alpha is set to 0


I have an odd behaviour on the borders of SCNPlane, I trust any geometry would have that, which looks like similar to SceneKit - Remove stitching line in edges borders

I set transparency via SCNProgram and in fragment I run

float alphaBloom(float2 uv) {
uv *=  1.0 - uv.yx;   
float vig = uv.x*uv.y * 15.0;
vig = pow(vig, 3.95);
return vig;
}

Looks like the geometry is drawn with the correct alpha and at the end of it a line is drawn with the same color as the border, but alpha 1.

enter image description here

I do believe vertex and fragment shaders are ok and this looks like to me more a set/setting issue which I do not know yet.

Is any flag to get rid of those?

The same plane with diffuse transparent material with no program used is working ok.

Opaque is set to yes. Setting it to NO will make the material alpha constant , I want it to change and be 0 towards the end of the surface. I do it through alphaBloom function set above.


Solution

  • Solved.

    In order to get rid of the extra line on the borders :

    • .isOpaque = false
    • #pragma transparent at the top of your program
    • change your code so that it uses premultiplied alphas: return float4(0.0, 0.00000001, 0.0, 1) has to be return float4(0.0 * 0.00000001, 1.0 * 0.00000001, 0.0 * 0.00000001, 0.00000001) without .isOpaque

    HTH!