Hi everyone,
I have searched, how to make a top small viewport transparent (I mean the drawn models to be transparent), so we can see the top small viewport transparent and as background the main full screen viewport.
I found questions and answers to this question, suggestion was made that do not use clear command in the render path. That does not make drawn models transparent.
I came up with the following render path as a solution:
<renderpath>
<rendertarget name="scene_to_target" sizemultiplier="1 1" format="rgba" filter="true" />
<command type="clear" color="0.0 0.0 0.0 0.0" depth="1.0" output="scene_to_target" />
<command type="scenepass" pass="base" output="scene_to_target" />
<command type="quad" vs="transparency_src" ps="transparency_src" blend="multiply" output="viewport">
<parameter name="transparency" value="0.7 0.7 0.7 0.7" />
</command>
<command type="quad" vs="transparency_des" ps="transparency_des" blend="add" output="viewport">
<texture unit="diffuse" name="scene_to_target" />
<parameter name="transparency" value="0.3 0.3 0.3 0.3" />
</command>
</renderpath>
So, with this render path, we use a render target, we draw the scene on the render target.
then we draw a quad with blend multiply and transparency 0.7
then we made another draw of a quad with blend add and transparency 0.3
now I believe the following equation for each pixel has been full-filled
Final_clr = Src_clr * 0.7 + Des_clr * 0.3
And thus I simulated transparency with linear blending.
Now to my surprise, it is not working, i get solid none-transparent result.
If I use simply this render path:
<renderpath>
<command type="quad" vs="transparency_src" ps="transparency_src" blend="multiply" output="viewport" >
<parameter name = "transparency" value="0.7 0.7 0.7 0.7" />
</command>
</renderpath>
I get transparent small viewport, which is one color, but it full-fills the first part of the equation:
Src_clr * 0.7
Here are the shaders, pretty simply:
-------- transparency_src
#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"
#include "ScreenPos.glsl"
uniform vec4 cTransparency;
void VS()
{
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);
gl_Position = GetClipPos(worldPos);
}
void PS()
{
gl_FragColor = cTransparency;
}
-------- transparency_des
#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"
#include "ScreenPos.glsl"
varying vec2 vScreenPos;
uniform vec4 cTransparency;
void VS()
{
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);
gl_Position = GetClipPos(worldPos);
vScreenPos = GetScreenPosPreDiv(gl_Position);
}
void PS()
{
gl_FragColor = texture2D(sDiffMap, vScreenPos) * cTransparency;
}
Why when in the second quad command, with blend add I get all solid colors?
I cannot explain why i get such results.