Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name:  Password:
Ambiera Forum > CopperCube > Feature requests and bug reports
Shader using additional blending conflicts with alphaed geometry (webGL)
Author Text

2021-02-16 18:23:00

Playing with shaders, I've noticed when using additional blendmode 12, (look-trough-ish brightening), all grass and leaves behind the shader-textured mesh are disappearing.
Not useful except for some kind of agent-orange goggles.

Does anyone know a solution to this problem?

Registered User
2021-02-16 22:58:14

Hello Dieter,

Perhaps that you could try the Irrlicht shader 26 (Transparent Alpha Channel).

Settings in this screen capture uploaded on my OneDrive
(secured and anonymous access) :!AjokN1FU3jK1...

2021-02-17 03:40:07

Thanks, no, unfort. that didn't fix it. Have a look at the shader I posted in showcase, you attach it to a cube as a behavior. It's a funny shader, but it also shows this problem.

Registered User
2021-02-17 11:34:40

Dieter, I indeed visited your thread relative to a webgl shader posted in showcase.
I tested it and I may say that it is an interesting one.

The parameters (pulse) defining the shader constant 'pulse' may be replaced by rgba values.

You can find an example in this thread :
(glsl shaders for projects running in Windows mode).

2021-02-17 22:04:08

Thanks Marc,
pulse is given to the shader as vec4 array, I knew about rgba, but alpha has no impact, as v_fragColor seems to ignore it.

Also, I was wondering whether there is any way to access the pixel under the current fragment, or, say access to the framebuffer, and not just the texturebuffer of the material?

Registered User
2021-02-17 23:20:35

Dieter, you are too kind because I'm afraid I couldn't help you.

About applying custom-made shaders inside CCB I have thrown in the towel.
It is too complicated for my little brain.

However a few weeks ago I was able to create some interesting shaders for the animated soldier.

They are based on some original ones found on GLSL tutorials published on the web.

In this topic
I posted a comment with a link to my shared CCB tests uploaded on my OneDrive.

In the subfolder SPACE key UP DOWN Demo, I included this shader :


var vertexShader =

"varying vec3 normal;\n" +
"varying vec3 vpos;\n" +

"void main()\n" +

"{\n" +
" // vertex normal\n" +
" normal = normalize(gl_NormalMatrix * gl_Normal);\n" +
" // vertex position\n" +
" vpos = vec3(gl_ModelViewMatrix * gl_Vertex);\n" +
" // vertex position\n" +
" gl_Position = ftransform();\n" +
" gl_TexCoord[0] = gl_TextureMatrix[0,1] * gl_MultiTexCoord0;\n" +
" gl_TexCoord[1] = gl_TextureMatrix[0,1] * gl_MultiTexCoord0;\n" +


var fragmentShader =

"uniform sampler2D tex01;\n" +
"varying vec3 normal;\n" +
"varying vec3 vpos;\n" +
"uniform float shininess;\n" +
"void main()\n" +

"{\n" +
"float shininess = 10;\n" +
" vec4 color01 = texture2D(tex01, vec2(gl_TexCoord[0])); \n" +
" vec4 color02 = texture2D(tex01, vec2(gl_TexCoord[1])); \n" +
" vec3 n = normalize(normal);\n" +
" vec4 diffuse = vec4(0.0);\n" +
" vec4 specular = vec4(0.0);\n" +
" // the material properties are embedded in the shader (for now)\n" +
" vec4 mat_ambient = vec4(0.5, 0.5, 0.5, 0.5);\n" +
" vec4 mat_diffuse = vec4(0.5, 0.5, 0.5, 0.5);\n" +
" vec4 mat_specular = vec4(1.0, 1.0, 1.0, 0.5);\n" +
" // ambient term\n" +
" vec4 ambient = mat_ambient * gl_LightSource[0].ambient;\n" +
" // diffuse color\n" +
" vec4 kd = mat_diffuse * gl_LightSource[0].diffuse;\n" +
" // specular color\n" +
" vec4 ks = mat_specular * gl_LightSource[0].specular;\n" +
" // diffuse term\n" +
" vec3 lightDir = normalize(gl_LightSource[0] - vpos);\n" +
" float NdotL = dot(n, lightDir);\n" +
" if (NdotL > 0.0)\n" +
" diffuse = kd * NdotL;\n" +
" // specular term\n" +
" vec3 rVector = normalize(2.0 * n * dot(n, lightDir) - lightDir);\n" +
" vec3 viewVector = normalize(-vpos);\n" +
" float RdotV = dot(rVector, viewVector);\n" +
" if (RdotV > 0.0)\n" +
" specular = ks * pow(RdotV, shininess);\n" +

" gl_FragColor = color01*(ambient + diffuse + specular);\n" +

var newMaterial = ccbCreateMaterial(vertexShader, fragmentShader, 0, null);

var soldier = ccbGetSceneNodeFromName('soldier');
ccbSetSceneNodeMaterialProperty(soldier, 0, 'Type', newMaterial);
ccbSetSceneNodeMaterialProperty(soldier, 1, 'Type', newMaterial);
ccbSetSceneNodeMaterialProperty(soldier, 2, 'Type', newMaterial);
ccbSetSceneNodeMaterialProperty(soldier, 4, 'Type', newMaterial);

While testing the GLSL shaders, I noticed that some of them activate the possibility to apply a normal map to the animated meshes (example : the soldier) while the CCB doc mentions that it is not possible (reference : normal map -> limitations).

You made a nice job with your behavior to apply custom-made shader. Thank you for teaching your skills with this community. It is quite helpful.

About the shaders, for the purpose of real-time testing, I prefer having the possibility to edit them inside an 'action -> Execute Java Script'.


Registered User
2021-02-18 00:30:34

Dieter, may I suggest you to try this :
Deselect the parameter "ZwriteEnable" for the selected node in the IrrLicht properties pane.

2021-02-19 23:29:58

Thank you guys, appreciate it.
ZWriteEnable off gives a weird effect, in which all alpha geometry, the grass and leaves, are in front of the shaded object, which is a mesh attached to the camera, like a filter, so it looks as if the terrain has a shader, but also everything else, except for alpha material meshes. Interesting, but something completely diffrent.

The doc doesn't say much about the modes:
base material type: usually 0 for the solid material. (2 for lightmap, 12 for additive transparency).
So I tried them, 0 and 2 are solid when used with one texture, 12 is additive, just with the problem described initially.

I then tried lots of numbers and found:
the blendmode is solid below 30, except for 12.
It is additive above 29, showing that it could blend correctly with the grass in place, but now the shader is not doing anything anymore (no animation).
I keep on hacking...

2021-02-20 22:13:17

Note, some related findings I posted here:

Create reply:

Posted by: (you are not logged in)

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




Forum Codes

Feature Code
Link [url] [/url]
Bold [b]bold text[/b]
Image [img][/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]