(OK)Irrlicht 1.8, shaders and alpha?

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

(OK)Irrlicht 1.8, shaders and alpha?

Post by christianclavet »

Hi, I got a strange problem since I updated to 1.8.0 when I use then ocean shader that Andres made for the project.

Here what Irrlicht is running on:
Irrlicht Engine version 1.8.0
Microsoft Windows 7 Home Premium Edition Service Pack 1 (Build 7601)
Using renderer: OpenGL 4.2.0
GeForce GTX 460/PCIe/SSE2: NVIDIA Corporation
OpenGL driver version is 1.2 or better.
GLSL version: 4.2
Resizing window (1280 720)
irrKlang sound library version 1.4.0
Loaded plugin: ikpflac.dll
Loaded plugin: ikpmp3.dll
Using DirectSound8 driver
Here is a pic:
Image

The terrain is made of tiles, and one of the tile has it's alpha failing (it become full opaque, and the foliage of the tree was affected)
This only happen at certain camera angles. If I move|rotate the camera, it come back normal.

This is the rendering of a GLSL shader. Here is what I have now, I forced it to use a specific alpha now to be sure (0.5 value)
Just look at the last line...

Code: Select all

uniform sampler2D oceanNormalMap;
uniform sampler2D oceanReflection;
 
uniform float waterTime;
 
uniform vec4 AmbientLight;
 
varying float posY;
uniform int terrainScale;
 
void main()
{
    float scale = terrainScale * 0.145;
    vec2 texCoord = vec2(gl_TexCoord[0]);
    
    vec4 tex0    = texture2D( oceanNormalMap, vec2(texCoord.x*5.0 + waterTime,texCoord.y*3.0));
    vec4 tex1    = texture2D( oceanReflection, texCoord.xy*2.0 + tex0.r*0.5 );
    
    tex1.a = (-posY/scale)-(0.1)*3.0;
    
    vec4 finalColor = tex1 * AmbientLight;
    float pAlpha = finalColor.a;
 
    float fog = (gl_Fog.end - gl_FogFragCoord) * gl_Fog.scale;
    finalColor = mix(gl_Fog.color,finalColor, fog);
 
    //gl_FragColor = vec4(finalColor.r,finalColor.g,finalColor.b,pAlpha);
    gl_FragColor = vec4(finalColor.r,finalColor.g,finalColor.b,0.5);
}

In case you would like to see the vertex shader:

Code: Select all

varying float posY;
uniform int terrainScale;
 
void main(void)
{
    float scale = (terrainScale * 0.05);
            
    posY = gl_Vertex.y;
    
    //gl_Vertex.y = -scale;
    
    gl_TexCoord[0] = gl_MultiTexCoord0;
    
    //gl_Position = ftransform();
    vec4 vertex = gl_Vertex;
    vertex.y = -scale;
    gl_Position = gl_ModelViewProjectionMatrix * vertex;
 
    gl_FogFragCoord = gl_Position.z;
}
Could Irrlicht would have somewhat affected the parameters in the shader and in some specific camera angle change/fail the alpha transparency in rendering?!
Last edited by christianclavet on Wed Dec 12, 2012 12:58 am, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Irrlicht 1.8, shaders and alpha?

Post by hybrid »

Did you switch on alpha blending in the base material?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Irrlicht 1.8, shaders and alpha?

Post by hendu »

Unrelated, but you're doing unnecessary work in both shaders:

float scale = (terrainScale * 0.05);
float scale = terrainScale * 0.145;

Save yourself a few million multiplies per frame, and pass those two premultiplied on the cpu (vertterrainscale, fragterrainscale etc).
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Irrlicht 1.8, shaders and alpha?

Post by christianclavet »

Thanks Hendu, I'll use what you propose... This will surely help a little!

Thanks Hybrid, From your answer checked the SDK and used this:

Code: Select all

ocean->setMaterialFlag(EMF_BLEND_OPERATION,true);
It seem to have fixed the problem. I was not able to replicate the problem once that was in place.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: (OK)Irrlicht 1.8, shaders and alpha?

Post by hybrid »

Yeah, sorry for the inconveniences. When I started with that change, I was pretty sure that we can have the correct settings for each material as defaults in each situation. Hence, the change would be transparent to the user and only add some new features. However, either the change itself or the material attribute tracking in the drivers did not work out as expected. So now you have to make sure that this flag is properly set, otherwise there can be situations where the blend settings are not correctly working.
Post Reply