Shader of SkMesh

21 views
Skip to first unread message

João Oliveira

unread,
Jul 16, 2025, 12:15:07 PMJul 16
to skia-discuss
Whilst using SkMesh to render 3D geometries I attempted to use backface culling, hence I need to discard the pixel if the normal of the vertex is not in view of the camera. 
These are my shaders: 

    const char* vs = R"(
        uniform float4x4 proj_model;
        uniform float4x4 model;
        uniform float3 camera_forward;
        Varyings main(const Attributes a) {
            Varyings v;
            float4 clip = proj_model * float4(a.position, 1.0);
            float3 ndc = clip.xyz / clip.w;
            v.position = (ndc).xy;
            v.lighting = clamp(dot(a.normal, camera_forward), 0.0, 1.0);
            v.v_color = a.color;
            return v;
        }
    )";

    const char* fs = R"(
        float2 main(const Varyings v, out half4 color) {
            color = half4(v.v_color.rgb * v.lighting, v.v_color.a);
            return v.position;
        }
    )";

    auto result = SkMeshSpecification::Make(
        SkSpan(attributes),
        sizeof(Vertex),
        SkSpan(varyings),
        SkString(vs),
        SkString(fs)
    );
 Yet when I use the keyword discard in the fragment shader, the SKSL compiler complains that I can only use it when compiling a fragment shader? A bit of clarity if I am attempting do to something illegal with the SkMesh would be helpful

Reply all
Reply to author
Forward
0 new messages