CrossGL / crosstl

Translates native shader languages into CrossGL universal shader language and vice versa.
https://crossgl.net
Apache License 2.0
36 stars 39 forks source link

enh(directx): add directx backend support for ASSIGN_AND #207

Closed MashyBasker closed 3 weeks ago

MashyBasker commented 1 month ago

PR Description

Implementation details:

Test details:

Related Issue

Fixes #185

shader Sample

shader main {
    // Fragment Shader
    fragment {
       PSOutput PSMain(PSInput input )  {
        PSOutput output;
        output.out_color = vec4(0.0, 0.0, 0.0, 1.0);
        if (input.in_position.r > 0.5) {
            output.out_color += input.in_position;
        }
        if (input.in_position.r < 0.5) {
            output.out_color -= vec4(0.1, 0.1, 0.1, 0.1);
        }
        if (input.in_position.g > 0.5) {
            output.out_color *= 2.0;
        }
        if (input.in_position.b > 0.5) {
            out_color /= 2.0;
        }
        if (input.in_position.r == 0.5) {
            uint redValue = asuint(output.out_color.r);
            output.redValue ^= 0 x1;
            output.out_color.r = asfloat( redValue);
            output.redValue |= 0 x2;
            output.redValue &= 0 x3;
        }
        return  output;
    }

    }

}

The above CrossGL code was generated from the following Directx HLSL code

PSOutput PSMain(PSInput input) {
        PSOutput output;
        output.out_color = float4(0.0, 0.0, 0.0, 1.0);

        if (input.in_position.r > 0.5) {
            output.out_color += input.in_position;
        }

        if (input.in_position.r < 0.5) {
            output.out_color -= float4(0.1, 0.1, 0.1, 0.1);
        }

        if (input.in_position.g > 0.5) {
            output.out_color *= 2.0;
        }

        if (input.in_position.b > 0.5) {
            out_color /= 2.0;
        }

        if (input.in_position.r == 0.5) {
            uint redValue = asuint(output.out_color.r);
            output.redValue ^= 0x1;
            output.out_color.r = asfloat(redValue);

            output.redValue |= 0x2;

            output.redValue &= 0x3;

        }

        return output;
    }

Checklist