ambiera home ambiera home

Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name:  Password:
Ambiera Forum > CopperLicht
Enable Alpha test
Author Text

codemastermike
Registered User
Quote
2011-10-21 11:51:48

To get transparancy to work for my 3d objects, I use a shader, and I have to use a alpha test to avoid writing the pixles that should be transparent.

But according to some sites Ive been reading there are some OpenGL functions that can set this alpha check directly, so I dont have to do it in the shader, mainly the functions glAlphaFunc() and glEnable().

Are there a way to access these functions, or similar functions within Copperlicht? i know you can get some things from the getWebGL() function, but I got a error message when trying to use the above functions with it.


niko
Moderator
Quote
2011-10-21 13:56:15

When you create your own material, you can specify the blend function yourself. The renderer::createMaterialType() function acccepts the following parameters:

createMaterialType(vertexShaderSource, fragmentShaderSource, blendenabled, blendsfactor, blenddfactor)


For addititve blending for example, set the last three parametersto this:
true, gl.ONE, gl.ONE_MINUS_SRC_COLOR

(Where 'gl' is the webgl object, you can get it using renderer.getWebGL())

See the 'Custom materials and shaders' tutorial in the documentation for details.


codemastermike
Registered User
Quote
2011-10-21 14:16:11

Yes, that I have already done, and using a shader works fine. Thats not the problem. When I create the shader material, Im using gl.SRC_ALPHA and gl.ONE_MINUS_SRC_ALPHA for my. But it doesnt blend out the black pixles in the texture.

But, if I add:


if(FirstTex.a < 0.5)
discard;


into the shader it does the blending. And as far as I read on the internet, this is because of the depth buffer in OpenGL. And to save the trouble of the shader call above, it says you can use glAlphaFunc() and glEnable() like so:


glAlphaFunc(GL_GREATER,0.1f);
glEnable(GL_ALPHA_TEST);


so I was wondering if there was a way to use the glAlphaFun and glEnable in Copperlicht.


niko
Moderator
Quote
2011-10-21 14:23:04

Ah, sorry for the misunderstanding. As far as I know, WebGL doesn't support glalphaFunc, so what you are doing is right.


codemastermike
Registered User
Quote
2011-10-21 14:30:09

okey, then I know! well, then I will keep running the alpha-test from the shader until further notice! :-)


douwedabbe
Registered User
Quote
2019-06-10 10:50:26

want to know if it is possible to modify transparancy of an png image attached to a 2D mesh through js scripting/actions etc.

2D_Overlay meshes do have the "Alpha" property but i cant use them, as my image and 2d Mesh are to large (approx 10x device.width)

feature needed for the android platform.

thanks


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internatio?al" (you are not logged in)


Text:

 

  

Forum Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   





Software: Ambiera Light Forum. © 2008-2019 Nikolaus Gebhardt, Ambiera e.U.