Porting XNA Shader pass, blend and cull mode into Unity shaderlab





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







5















I had to port XNA shader into Unity's shader and want to verify that I did this correctly.



The Pass1 section that uses alpha blending like SrcBlend, DestBlend and set's cull to none is the only place I want to make sure I got right.



This is the XNA shader version:



pass Pass1
{
AlphaBlendEnable = true;
SrcBlend = SRCALPHA;
DestBlend = INVSRCALPHA;
CullMode = None;

VertexShader = compile vs_2_0 TheVertexShader();
PixelShader = compile ps_2_0 ThePixelShader();
}


This is the Unity Shaderlab port I made:



Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
LOD 100
Blend SrcAlpha One
Blend DstAlpha OneMinusSrcAlpha
ZWrite Off
Cull Off


It seems to be working fine in Unity but is this the exactly the equivalent pass settings in Unity? If not, then what changes is requred to get the exact equivalency.










share|improve this question

























  • Looks correct to me.

    – Eddge
    Sep 27 '18 at 13:38











  • @Eddge Event the SrcBlend = SRCALPHA; which I used Blend SrcAlpha One on the Unity side?

    – Programmer
    Sep 27 '18 at 13:42











  • That is the hard part, my gut says that is correct but my head says that would instantly set the SrcAlpha to 1, which might not be what you want... however my head is also saying that with that line you are saying srcAlpha is multiplied by 1, rather then the inverse, or the oneMinus...

    – Eddge
    Sep 27 '18 at 13:47






  • 1





    because if I remember correctly XNA tried to follow the same scheme as DirectX(or was HLSL), so SrcBlend would be the SrcColor, and DstBlend would be the DstColor. which would mean they possibly seperated the Alpha as well, so you might not need to do anything with Alpha but just Color.

    – Eddge
    Sep 27 '18 at 13:59








  • 1





    @Eddge Forgot about this question. I tried it and the output looked the-same as the one in my question. Although, that doesn't mean that what you said is not correct.

    – Programmer
    Oct 5 '18 at 2:33


















5















I had to port XNA shader into Unity's shader and want to verify that I did this correctly.



The Pass1 section that uses alpha blending like SrcBlend, DestBlend and set's cull to none is the only place I want to make sure I got right.



This is the XNA shader version:



pass Pass1
{
AlphaBlendEnable = true;
SrcBlend = SRCALPHA;
DestBlend = INVSRCALPHA;
CullMode = None;

VertexShader = compile vs_2_0 TheVertexShader();
PixelShader = compile ps_2_0 ThePixelShader();
}


This is the Unity Shaderlab port I made:



Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
LOD 100
Blend SrcAlpha One
Blend DstAlpha OneMinusSrcAlpha
ZWrite Off
Cull Off


It seems to be working fine in Unity but is this the exactly the equivalent pass settings in Unity? If not, then what changes is requred to get the exact equivalency.










share|improve this question

























  • Looks correct to me.

    – Eddge
    Sep 27 '18 at 13:38











  • @Eddge Event the SrcBlend = SRCALPHA; which I used Blend SrcAlpha One on the Unity side?

    – Programmer
    Sep 27 '18 at 13:42











  • That is the hard part, my gut says that is correct but my head says that would instantly set the SrcAlpha to 1, which might not be what you want... however my head is also saying that with that line you are saying srcAlpha is multiplied by 1, rather then the inverse, or the oneMinus...

    – Eddge
    Sep 27 '18 at 13:47






  • 1





    because if I remember correctly XNA tried to follow the same scheme as DirectX(or was HLSL), so SrcBlend would be the SrcColor, and DstBlend would be the DstColor. which would mean they possibly seperated the Alpha as well, so you might not need to do anything with Alpha but just Color.

    – Eddge
    Sep 27 '18 at 13:59








  • 1





    @Eddge Forgot about this question. I tried it and the output looked the-same as the one in my question. Although, that doesn't mean that what you said is not correct.

    – Programmer
    Oct 5 '18 at 2:33














5












5








5


1






I had to port XNA shader into Unity's shader and want to verify that I did this correctly.



The Pass1 section that uses alpha blending like SrcBlend, DestBlend and set's cull to none is the only place I want to make sure I got right.



This is the XNA shader version:



pass Pass1
{
AlphaBlendEnable = true;
SrcBlend = SRCALPHA;
DestBlend = INVSRCALPHA;
CullMode = None;

VertexShader = compile vs_2_0 TheVertexShader();
PixelShader = compile ps_2_0 ThePixelShader();
}


This is the Unity Shaderlab port I made:



Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
LOD 100
Blend SrcAlpha One
Blend DstAlpha OneMinusSrcAlpha
ZWrite Off
Cull Off


It seems to be working fine in Unity but is this the exactly the equivalent pass settings in Unity? If not, then what changes is requred to get the exact equivalency.










share|improve this question
















I had to port XNA shader into Unity's shader and want to verify that I did this correctly.



The Pass1 section that uses alpha blending like SrcBlend, DestBlend and set's cull to none is the only place I want to make sure I got right.



This is the XNA shader version:



pass Pass1
{
AlphaBlendEnable = true;
SrcBlend = SRCALPHA;
DestBlend = INVSRCALPHA;
CullMode = None;

VertexShader = compile vs_2_0 TheVertexShader();
PixelShader = compile ps_2_0 ThePixelShader();
}


This is the Unity Shaderlab port I made:



Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
LOD 100
Blend SrcAlpha One
Blend DstAlpha OneMinusSrcAlpha
ZWrite Off
Cull Off


It seems to be working fine in Unity but is this the exactly the equivalent pass settings in Unity? If not, then what changes is requred to get the exact equivalency.







unity3d xna shader shaderlab unity3d-shaders






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 13 at 16:18









Fattie

20.6k31209455




20.6k31209455










asked Sep 27 '18 at 13:12









ProgrammerProgrammer

79.2k1093163




79.2k1093163













  • Looks correct to me.

    – Eddge
    Sep 27 '18 at 13:38











  • @Eddge Event the SrcBlend = SRCALPHA; which I used Blend SrcAlpha One on the Unity side?

    – Programmer
    Sep 27 '18 at 13:42











  • That is the hard part, my gut says that is correct but my head says that would instantly set the SrcAlpha to 1, which might not be what you want... however my head is also saying that with that line you are saying srcAlpha is multiplied by 1, rather then the inverse, or the oneMinus...

    – Eddge
    Sep 27 '18 at 13:47






  • 1





    because if I remember correctly XNA tried to follow the same scheme as DirectX(or was HLSL), so SrcBlend would be the SrcColor, and DstBlend would be the DstColor. which would mean they possibly seperated the Alpha as well, so you might not need to do anything with Alpha but just Color.

    – Eddge
    Sep 27 '18 at 13:59








  • 1





    @Eddge Forgot about this question. I tried it and the output looked the-same as the one in my question. Although, that doesn't mean that what you said is not correct.

    – Programmer
    Oct 5 '18 at 2:33



















  • Looks correct to me.

    – Eddge
    Sep 27 '18 at 13:38











  • @Eddge Event the SrcBlend = SRCALPHA; which I used Blend SrcAlpha One on the Unity side?

    – Programmer
    Sep 27 '18 at 13:42











  • That is the hard part, my gut says that is correct but my head says that would instantly set the SrcAlpha to 1, which might not be what you want... however my head is also saying that with that line you are saying srcAlpha is multiplied by 1, rather then the inverse, or the oneMinus...

    – Eddge
    Sep 27 '18 at 13:47






  • 1





    because if I remember correctly XNA tried to follow the same scheme as DirectX(or was HLSL), so SrcBlend would be the SrcColor, and DstBlend would be the DstColor. which would mean they possibly seperated the Alpha as well, so you might not need to do anything with Alpha but just Color.

    – Eddge
    Sep 27 '18 at 13:59








  • 1





    @Eddge Forgot about this question. I tried it and the output looked the-same as the one in my question. Although, that doesn't mean that what you said is not correct.

    – Programmer
    Oct 5 '18 at 2:33

















Looks correct to me.

– Eddge
Sep 27 '18 at 13:38





Looks correct to me.

– Eddge
Sep 27 '18 at 13:38













@Eddge Event the SrcBlend = SRCALPHA; which I used Blend SrcAlpha One on the Unity side?

– Programmer
Sep 27 '18 at 13:42





@Eddge Event the SrcBlend = SRCALPHA; which I used Blend SrcAlpha One on the Unity side?

– Programmer
Sep 27 '18 at 13:42













That is the hard part, my gut says that is correct but my head says that would instantly set the SrcAlpha to 1, which might not be what you want... however my head is also saying that with that line you are saying srcAlpha is multiplied by 1, rather then the inverse, or the oneMinus...

– Eddge
Sep 27 '18 at 13:47





That is the hard part, my gut says that is correct but my head says that would instantly set the SrcAlpha to 1, which might not be what you want... however my head is also saying that with that line you are saying srcAlpha is multiplied by 1, rather then the inverse, or the oneMinus...

– Eddge
Sep 27 '18 at 13:47




1




1





because if I remember correctly XNA tried to follow the same scheme as DirectX(or was HLSL), so SrcBlend would be the SrcColor, and DstBlend would be the DstColor. which would mean they possibly seperated the Alpha as well, so you might not need to do anything with Alpha but just Color.

– Eddge
Sep 27 '18 at 13:59







because if I remember correctly XNA tried to follow the same scheme as DirectX(or was HLSL), so SrcBlend would be the SrcColor, and DstBlend would be the DstColor. which would mean they possibly seperated the Alpha as well, so you might not need to do anything with Alpha but just Color.

– Eddge
Sep 27 '18 at 13:59






1




1





@Eddge Forgot about this question. I tried it and the output looked the-same as the one in my question. Although, that doesn't mean that what you said is not correct.

– Programmer
Oct 5 '18 at 2:33





@Eddge Forgot about this question. I tried it and the output looked the-same as the one in my question. Although, that doesn't mean that what you said is not correct.

– Programmer
Oct 5 '18 at 2:33












1 Answer
1






active

oldest

votes


















0














You should only put the "Blend" keyword once: the two keywords after it are the blend factors used for the source and destination respectively. You can think of it as being on the format "Blend [SrcBlend] [DstBlend]".



Here is the correct blending:



Blend SrcAlpha OneMinusSrcAlpha


This results in basic alpha blending.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52537853%2fporting-xna-shader-pass-blend-and-cull-mode-into-unity-shaderlab%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You should only put the "Blend" keyword once: the two keywords after it are the blend factors used for the source and destination respectively. You can think of it as being on the format "Blend [SrcBlend] [DstBlend]".



    Here is the correct blending:



    Blend SrcAlpha OneMinusSrcAlpha


    This results in basic alpha blending.






    share|improve this answer




























      0














      You should only put the "Blend" keyword once: the two keywords after it are the blend factors used for the source and destination respectively. You can think of it as being on the format "Blend [SrcBlend] [DstBlend]".



      Here is the correct blending:



      Blend SrcAlpha OneMinusSrcAlpha


      This results in basic alpha blending.






      share|improve this answer


























        0












        0








        0







        You should only put the "Blend" keyword once: the two keywords after it are the blend factors used for the source and destination respectively. You can think of it as being on the format "Blend [SrcBlend] [DstBlend]".



        Here is the correct blending:



        Blend SrcAlpha OneMinusSrcAlpha


        This results in basic alpha blending.






        share|improve this answer













        You should only put the "Blend" keyword once: the two keywords after it are the blend factors used for the source and destination respectively. You can think of it as being on the format "Blend [SrcBlend] [DstBlend]".



        Here is the correct blending:



        Blend SrcAlpha OneMinusSrcAlpha


        This results in basic alpha blending.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 4 at 13:26









        Kalle HalvarssonKalle Halvarsson

        481210




        481210
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52537853%2fporting-xna-shader-pass-blend-and-cull-mode-into-unity-shaderlab%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas