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;
}
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
|
show 7 more comments
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
Looks correct to me.
– Eddge
Sep 27 '18 at 13:38
@Eddge Event theSrcBlend = SRCALPHA;
which I usedBlend 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
|
show 7 more comments
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
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
unity3d xna shader shaderlab unity3d-shaders
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 theSrcBlend = SRCALPHA;
which I usedBlend 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
|
show 7 more comments
Looks correct to me.
– Eddge
Sep 27 '18 at 13:38
@Eddge Event theSrcBlend = SRCALPHA;
which I usedBlend 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
|
show 7 more comments
1 Answer
1
active
oldest
votes
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Jan 4 at 13:26
Kalle HalvarssonKalle Halvarsson
481210
481210
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Looks correct to me.
– Eddge
Sep 27 '18 at 13:38
@Eddge Event the
SrcBlend = SRCALPHA;
which I usedBlend 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