I am working now on a solution that involves a second mesh primitive, which is rendered differntly in order to mimic multi pass rendering.
Inspired by https://groups.google.com/forum/#!topic/cesium-dev/wIxwpak4ft8, I also define a second primitive in my meshes, which have a translucent texture.
The second primitive shares the same attributes and indices as the first one, but has a different material with different rendering modes and fragment shader.
The idea is to first draw the mesh with blending mode on in order to render the window panes correctly represented by the translucent parts of the texture.
The technique for the first draw uses BLEND mode and PRE_MULTIPLIED_ALPHA_BLEND functions.
The second draw is with blending mode off in order to render the parts of the texture representing building walls as fully opaque areas.
The fragment shader used for this pass is configured to discard fragments with alpha values < 0.9 so that the window parts will not be rendered at all (color and depth buffer)
This way my buildings are rendered very nicely. However, I limit this approach to meshes which have PNG or TIFF textures that actually have transparent or translucent pixels (alpha < 255).
Otherwise the default approach with only one pass is used.
I hope that the overhead introduced by a second mesh primitive is kept within a reasonable limit. However, I would prefer actual two pass rendering defined within the GLTF Technique.
Parts of my GLTF below
Arne
ID106 fragment shader:
precision highp float;
varying vec2 v_texcoord0;
uniform sampler2D u_diffuse;
void main(void) {
vec4 color = texture2D(u_diffuse, v_texcoord0);
gl_FragColor = color;
}
ID116 Fragment shader:
precision highp float;
varying vec2 v_texcoord0;
uniform sampler2D u_diffuse;
void main(void) {
vec4 color = texture2D(u_diffuse, v_texcoord0);
if(color.a < 0.9)
discard;
gl_FragColor = color;
}
{
“programs”: {
“ID120”: {
“attributes”: [“a_texcoord0”],
“fragmentShader”: “ID116”,
“vertexShader”: “ID118”
},
“ID110”: {
“attributes”: [“a_texcoord0”],
“fragmentShader”: “ID106”,
“vertexShader”: “ID108”
}
},
"techniques": {
"ID105": {
"attributes": {
"a_batchId": "batchId",
"a_texcoord0": "texcoord0",
"a_position": "position"
},
"parameters": {
"projectionMatrix": {
"semantic": "PROJECTION",
"type": 35676
},
"texcoord0": {
"semantic": "TEXCOORD_0",
"type": 35664
},
"position": {
"semantic": "POSITION",
"type": 35665
},
"diffuse": {
"type": 35678
},
"batchId": {
"semantic": "BATCHID",
"type": 5126
},
"modelViewMatrix": {
"semantic": "CESIUM_RTC_MODELVIEW",
"type": 35676
}
},
"program": "ID110",
"states": {
"enable": [2929, 3042],
"functions": {
"blendColor": [0.0, 0.0, 0.0, 0.0],
"blendEquationSeparate": [32774, 32774],
"blendFuncSeparate": [1, 771, 1, 771],
"colorMask": [true, true, true, true],
"cullFace": [1029],
"depthFunc": [513],
"depthMask": [true],
"depthRange": [0.0, 1.0],
"frontFace": [2305],
"lineWidth": [1.0],
"polygonOffset": [0.0, 0.0],
"scissor": [0.0, 0.0, 0.0, 0.0]
}
},
"uniforms": {
"u_modelViewMatrix": "modelViewMatrix",
"u_projectionMatrix": "projectionMatrix",
"u_diffuse": "diffuse"
}
},
"ID115": {
"attributes": {
"a_batchId": "batchId",
"a_texcoord0": "texcoord0",
"a_position": "position"
},
"parameters": {
"projectionMatrix": {
"semantic": "PROJECTION",
"type": 35676
},
"texcoord0": {
"semantic": "TEXCOORD_0",
"type": 35664
},
"position": {
"semantic": "POSITION",
"type": 35665
},
"diffuse": {
"type": 35678
},
"batchId": {
"semantic": "BATCHID",
"type": 5126
},
"modelViewMatrix": {
"semantic": "CESIUM_RTC_MODELVIEW",
"type": 35676
}
},
"program": "ID120",
"states": {
"enable": [2929],
"functions": {
"blendColor": [0.0, 0.0, 0.0, 0.0],
"blendEquationSeparate": [32774, 32774],
"blendFuncSeparate": [1, 1, 0, 0],
"colorMask": [true, true, true, true],
"cullFace": [1029],
"depthFunc": [513],
"depthMask": [true],
"depthRange": [0.0, 1.0],
"frontFace": [2305],
"lineWidth": [1.0],
"polygonOffset": [0.0, 0.0],
"scissor": [0.0, 0.0, 0.0, 0.0]
}
},
"uniforms": {
"u_modelViewMatrix": "modelViewMatrix",
"u_projectionMatrix": "projectionMatrix",
"u_diffuse": "diffuse"
}
}
},
"materials": {
"ID142": {
"name": "M_ID142",
"technique": "ID105",
"values": {
"diffuse": "ID143"
}
},
"ID146": {
"name": "M_ID142_opaque",
"technique": "ID115",
"values": {
"diffuse": "ID143"
}
}
},
"meshes": {
"ID147": {
"name": "TA_ID147",
"primitives": [{
"attributes": {
"BATCHID": "ID150",
"POSITION": "ID149",
"TEXCOORD_0": "ID148"
},
"indices": "ID151",
"material": "ID142",
"mode": 4
}, {
"attributes": {
"BATCHID": "ID150",
"POSITION": "ID149",
"TEXCOORD_0": "ID148"
},
"indices": "ID151",
"material": "ID146",
"mode": 4
}]
}
}
}