-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webgl blendequation use error #162
Comments
two way test results in unity is the same. |
I'm sorry I'm not really understanding your question. Maybe you could modify this small sample to show the issue you're running into? |
and/or include some screenshots. You can just drag and drop images into these messages |
https://jsfiddle.net/zL7uq7z8/1/ i find when l add the premutiply alpha in fragmentshader in the 2nd link。the result is right。 so when i need use "premutiply alpha" in shader ,maybe you can give me some useful link abount it? if you have used unity3d ,l also want to ask that "premutiply alpha" is not need for the shader in 2nd link to get same result by my test? |
Without deeply diving into what Unity is doing it's hard to know what the issue is WebGL runs in canvas tag in HTML. The canvas is composited with the page. The default is for the canvas to require premultiplied alpha data inside it. This article mostly covers that topic Note that the article mentions |
the article is more abount the canvas with alpha ,{premultipliedAlpha: false}l have already use this , but what l confused is the render result by texture blend with backgroundcolor ( black ,l have clearcolor(0,0,0,1) )in the 2nd test. (webgl.blendEquation(webgl.FUNC_ADD);webgl.blendFunc(webgl.SRC_ALPHA,webgl.ONE);)accroding to this blend setting : in the 2nd linK: -----gl_FragColor=basecolor; in the 1st link:-------- gl_FragColor=vec4(basecolor.rgb *basecolor.a,1.0); accroding to up calculation, 2nd render result should be same with the first one,but the result is not,l don't understand why. |
The issue is this line
You start of with a baseColor of vec4(1, .3, 0, 1)
baseColor is now vec4(2, .6, 0, 2) In the only difference between the 2 shaders is
vs
The first one
The second one
It makes no sense these would be the same in Unity. They are clearly not the same color. |
It is the HDR In Untiy3d that cause the different render result between unity3d and webgl. |
I don't know what the issue is but it's certainly possible there's a bug in Unity. Unity can generate difference shaders depending on the platform and depending on the features of the user's computer as well as whatever material options you choose |
I know this is old but just in case someone else reads this you can add this
in your unity html to see the shaders as unity compiles them. or you can copy and paste this into the devtools console on a running page
To see the shaders as they are used Both are from here |
(1st way) gl_FragData[0]=vec4(tempcolor*tempAlpha,1.0);
(2nd way) gl_FragData[0]=vec4(tempcolor,tempAlpha);
l write a shader, use up shorte words in fragment shader,test the webgl blendequation。
this webgl sets is:
webgl.enable(webgl.BLEND);
webgl.blendEquation(webgl.FUNC_ADD);
webgl.blendFunc(webgl.SRC_ALPHA,webgl.ONE);
l use those shader render one quad,the background is black, texture alphaPremultiply=false.
the rend result is diffrent between two way, but in this enviroment (l set) the render results should be the same, and the 1st way is agree with test result in unity3d。
can you help me abount this ?is there anything wrong l do? Thank you for the first.
----------- here is my fs shader:
uniform sampler2D _MainTex;
uniform mediump vec4 _Main_Color;
varying lowp vec4 v_color;
varying mediump vec2 _maintex_uv;
varying mediump vec2 _mask_uv;
void main()
{
highp vec4 v_color =_Main_Color2.0;
highp vec4 basecolor=texture2D(_MainTex,_maintex_uv);
lowp vec3 tempcolor=v_color.rgbbasecolor.rgb;
lowp float tempAlpha=v_color.a*basecolor.a;
}
The text was updated successfully, but these errors were encountered: