- Improved EMT_ONETEXTURE_BLEND material for OpenGL ES2.0 driver (it solve issue with black volume light in example no. 08).
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@4903 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
b36a92de2e
commit
12a9df7e82
|
@ -0,0 +1,73 @@
|
|||
precision mediump float;
|
||||
|
||||
/* Uniforms */
|
||||
|
||||
uniform int uTextureUsage0;
|
||||
uniform sampler2D uTextureUnit0;
|
||||
uniform int uBlendType;
|
||||
uniform int uFogEnable;
|
||||
uniform int uFogType;
|
||||
uniform vec4 uFogColor;
|
||||
uniform float uFogStart;
|
||||
uniform float uFogEnd;
|
||||
uniform float uFogDensity;
|
||||
|
||||
/* Varyings */
|
||||
|
||||
varying vec2 vTextureCoord0;
|
||||
varying vec4 vVertexColor;
|
||||
varying float vFogCoord;
|
||||
|
||||
float computeFog()
|
||||
{
|
||||
const float LOG2 = 1.442695;
|
||||
float FogFactor = 0.0;
|
||||
|
||||
if (uFogType == 0) // Exp
|
||||
{
|
||||
FogFactor = exp2(-uFogDensity * vFogCoord * LOG2);
|
||||
}
|
||||
else if (uFogType == 1) // Linear
|
||||
{
|
||||
float Scale = 1.0 / (uFogEnd - uFogStart);
|
||||
FogFactor = (uFogEnd - vFogCoord) * Scale;
|
||||
}
|
||||
else if (uFogType == 2) // Exp2
|
||||
{
|
||||
FogFactor = exp2(-uFogDensity * uFogDensity * vFogCoord * vFogCoord * LOG2);
|
||||
}
|
||||
|
||||
FogFactor = clamp(FogFactor, 0.0, 1.0);
|
||||
|
||||
return FogFactor;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 Color0 = vVertexColor;
|
||||
vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
if (bool(uTextureUsage0))
|
||||
Color1 = texture2D(uTextureUnit0, vTextureCoord0);
|
||||
|
||||
vec4 FinalColor = Color0 * Color1;
|
||||
|
||||
if (uBlendType == 1)
|
||||
{
|
||||
FinalColor.w = Color0.w;
|
||||
}
|
||||
else if (uBlendType == 2)
|
||||
{
|
||||
FinalColor.w = Color1.w;
|
||||
}
|
||||
|
||||
if (bool(uFogEnable))
|
||||
{
|
||||
float FogFactor = computeFog();
|
||||
vec4 FogColor = uFogColor;
|
||||
FogColor.a = 1.0;
|
||||
FinalColor = mix(FogColor, FinalColor, FogFactor);
|
||||
}
|
||||
|
||||
gl_FragColor = FinalColor;
|
||||
}
|
|
@ -297,7 +297,7 @@ COGLES2Driver::~COGLES2Driver()
|
|||
COGLES2MaterialParallaxMapCB* ParallaxMapCB = new COGLES2MaterialParallaxMapCB();
|
||||
COGLES2MaterialParallaxMapCB* ParallaxMapAddColorCB = new COGLES2MaterialParallaxMapCB();
|
||||
COGLES2MaterialParallaxMapCB* ParallaxMapVertexAlphaCB = new COGLES2MaterialParallaxMapCB();
|
||||
COGLES2MaterialSolidCB* OneTextureBlendCB = new COGLES2MaterialSolidCB();
|
||||
COGLES2MaterialOneTextureBlendCB* OneTextureBlendCB = new COGLES2MaterialOneTextureBlendCB();
|
||||
|
||||
// Create built-in materials.
|
||||
|
||||
|
@ -409,7 +409,7 @@ COGLES2Driver::~COGLES2Driver()
|
|||
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, ParallaxMapVertexAlphaCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0, EGSL_DEFAULT);
|
||||
|
||||
VertexShader = OGLES2ShaderPath + "COGLES2Solid.vsh";
|
||||
FragmentShader = OGLES2ShaderPath + "COGLES2Solid.fsh";
|
||||
FragmentShader = OGLES2ShaderPath + "COGLES2OneTextureBlend.fsh";
|
||||
|
||||
addHighLevelShaderMaterialFromFiles(VertexShader, "main", EVST_VS_2_0, FragmentShader, "main", EPST_PS_2_0, "", "main",
|
||||
EGST_GS_4_0, scene::EPT_TRIANGLES, scene::EPT_TRIANGLE_STRIP, 0, OneTextureBlendCB, EMT_ONETEXTURE_BLEND, 0, EGSL_DEFAULT);
|
||||
|
|
|
@ -160,7 +160,7 @@ void COGLES2MaterialBaseCB::OnSetConstants(IMaterialRendererServices* services,
|
|||
}
|
||||
}
|
||||
|
||||
// EMT_SOLID + EMT_TRANSPARENT_ADD_COLOR + EMT_TRANSPARENT_ALPHA_CHANNEL + EMT_TRANSPARENT_VERTEX_ALPHA + EMT_ONETEXTURE_BLEND
|
||||
// EMT_SOLID + EMT_TRANSPARENT_ADD_COLOR + EMT_TRANSPARENT_ALPHA_CHANNEL + EMT_TRANSPARENT_VERTEX_ALPHA
|
||||
|
||||
COGLES2MaterialSolidCB::COGLES2MaterialSolidCB() :
|
||||
FirstUpdate(true), TMatrix0ID(-1), AlphaRefID(-1), TextureUsage0ID(-1), TextureUnit0ID(-1), AlphaRef(0.5f), TextureUsage0(0), TextureUnit0(0)
|
||||
|
@ -335,6 +335,63 @@ void COGLES2MaterialReflectionCB::OnSetConstants(IMaterialRendererServices* serv
|
|||
services->setPixelShaderConstant(TextureUnit1ID, &TextureUnit1, 1);
|
||||
}
|
||||
|
||||
// EMT_ONETEXTURE_BLEND
|
||||
|
||||
COGLES2MaterialOneTextureBlendCB::COGLES2MaterialOneTextureBlendCB() :
|
||||
FirstUpdate(true), TMatrix0ID(-1), BlendTypeID(-1), TextureUsage0ID(-1), TextureUnit0ID(-1), BlendType(0), TextureUsage0(0), TextureUnit0(0)
|
||||
{
|
||||
}
|
||||
|
||||
void COGLES2MaterialOneTextureBlendCB::OnSetMaterial(const SMaterial& material)
|
||||
{
|
||||
COGLES2MaterialBaseCB::OnSetMaterial(material);
|
||||
|
||||
BlendType = 0;
|
||||
|
||||
E_BLEND_FACTOR srcRGBFact,dstRGBFact,srcAlphaFact,dstAlphaFact;
|
||||
E_MODULATE_FUNC modulate;
|
||||
u32 alphaSource;
|
||||
unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulate, alphaSource, material.MaterialTypeParam);
|
||||
|
||||
if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) || textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact))
|
||||
{
|
||||
if (alphaSource == EAS_VERTEX_COLOR)
|
||||
{
|
||||
BlendType = 1;
|
||||
}
|
||||
else if (alphaSource == EAS_TEXTURE)
|
||||
{
|
||||
BlendType = 2;
|
||||
}
|
||||
}
|
||||
|
||||
TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0;
|
||||
}
|
||||
|
||||
void COGLES2MaterialOneTextureBlendCB::OnSetConstants(IMaterialRendererServices* services, s32 userData)
|
||||
{
|
||||
COGLES2MaterialBaseCB::OnSetConstants(services, userData);
|
||||
|
||||
IVideoDriver* driver = services->getVideoDriver();
|
||||
|
||||
if (FirstUpdate)
|
||||
{
|
||||
TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0");
|
||||
BlendTypeID = services->getVertexShaderConstantID("uBlendType");
|
||||
TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0");
|
||||
TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0");
|
||||
|
||||
FirstUpdate = false;
|
||||
}
|
||||
|
||||
core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0);
|
||||
services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16);
|
||||
|
||||
services->setPixelShaderConstant(BlendTypeID, &BlendType, 1);
|
||||
services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1);
|
||||
services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -169,6 +169,27 @@ protected:
|
|||
s32 TextureUnit1;
|
||||
};
|
||||
|
||||
class COGLES2MaterialOneTextureBlendCB : public COGLES2MaterialBaseCB
|
||||
{
|
||||
public:
|
||||
COGLES2MaterialOneTextureBlendCB();
|
||||
|
||||
virtual void OnSetMaterial(const SMaterial& material);
|
||||
virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData);
|
||||
|
||||
protected:
|
||||
bool FirstUpdate;
|
||||
|
||||
s32 TMatrix0ID;
|
||||
s32 BlendTypeID;
|
||||
s32 TextureUsage0ID;
|
||||
s32 TextureUnit0ID;
|
||||
|
||||
s32 BlendType;
|
||||
s32 TextureUsage0;
|
||||
s32 TextureUnit0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue