Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperLicht
custom shader for transparent object

beber
Registered User
Quote
2012-02-09 15:08:33

hello,

I try to make a transparent cube, but when I change the alpha of the cube, the opacity does not change.
I would like to know how to use createNewMaterialType () to make an object transparent.

thank



this.scene.getRootSceneNode().addChild(this.cube);

//pas d'espace apres les "\"
var vertex_shader = " \
uniform mat4 worldviewproj; \
attribute vec4 vPosition; \
attribute vec4 vNormal; \
void main() { \
gl_Position = worldviewproj * vPosition;\
}";

var fragment_shader = " \
precision mediump float;\
void main() { \
vec4 Color = vec4(0,1,0,0.5);\
gl_FragColor = vec4(Color.rgb, Color.a);\
}";

// creer un nouveau shader pour rendre le cube transparent
var newMaterialType = this.engine.getRenderer().createMaterialType(vertex_shader,
fragment_shader,
true,
this.engine.getRenderer().getWebGL().SRC_ALPHA,
this.engine.getRenderer().getWebGL().ONE);


if (newMaterialType != -1){
this.cube.getMaterial(0).Type = newMaterialType;
}else{
alert('Le shader n\'a pas pu être créer');
}



erik
Registered User
Quote
2012-02-09 16:11:29

Hi,
you don't need to write a shader for this, you can simply set the material type of your cube to EMT_TRANSPARENT_ALPHA_CHANNEL, instead of the default EMT_SOLID. That should be one line of code :)


beber
Registered User
Quote
2012-02-09 16:41:06

I had already tried, but when I did, I don't know where to change the color and alpha of the cube.

When i use EMT_TRANSPARENT_ALPHA_CHANNEL, i get a red cube whereas i don't set the color or the alpha.


niko
Moderator
Quote
2012-02-10 07:41:47

It takes the alpha channel of the texture then as alpha channel. Just for testing, you could for example take any .png file with transparencies from the www just to try out.


beber
Registered User
Quote
2012-02-10 11:21:09

its good, thanks :-}


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "In?ernational" (you are not logged in)


Text:

 

  

Possible 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


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact