From b3e41db14bbe7928885ab7f2028a7773ba0843ec Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 30 Nov 2018 23:33:30 +0800 Subject: [PATCH] Add EMT_STK_GRASS for GLES2 to draw grass material without vertex color Now EMT_TRANSPARENT_ALPHA_CHANNEL_REF in GLES2 can be used with vertex color --- .../shaders/irrlicht/COGLES2FixedPipeline.fsh | 24 +++++++++++++++---- lib/irrlicht/include/EMaterialTypes.h | 3 +++ .../source/Irrlicht/COGLES2Driver.cpp | 2 +- .../Irrlicht/COGLES2FixedPipelineRenderer.cpp | 3 +++ src/graphics/material.cpp | 5 ++++ 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/data/shaders/irrlicht/COGLES2FixedPipeline.fsh b/data/shaders/irrlicht/COGLES2FixedPipeline.fsh index f6efdf4e2..09285e7f4 100644 --- a/data/shaders/irrlicht/COGLES2FixedPipeline.fsh +++ b/data/shaders/irrlicht/COGLES2FixedPipeline.fsh @@ -12,6 +12,7 @@ precision mediump float; #define TransparentAlphaChannelRef 7 #define TransparentVertexAlpha 8 #define TransparentReflection2Layer 9 +#define StkGrass 10 /* Uniforms */ @@ -101,6 +102,16 @@ vec4 renderTransparent() return Color; } +vec4 renderTransparentVertexColor() +{ + vec4 Color = varVertexColor; + + if(uTextureUsage0) + Color *= texture2D(uTextureUnit0, varTexCoord0); + + return Color; +} + void main () { if (uMaterialType == Solid) @@ -119,11 +130,16 @@ void main () gl_FragColor = renderTransparent(); else if(uMaterialType == TransparentAlphaChannelRef) { - vec4 Color = renderTransparent(); - + vec4 Color = renderTransparentVertexColor(); + if (Color.a < 0.5) + discard; + gl_FragColor = Color; + } + else if(uMaterialType == StkGrass) + { + vec4 Color = renderTransparent(); if (Color.a < 0.5) discard; - gl_FragColor = Color; } else if(uMaterialType == TransparentVertexAlpha) @@ -142,4 +158,4 @@ void main () } else gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); -} \ No newline at end of file +} diff --git a/lib/irrlicht/include/EMaterialTypes.h b/lib/irrlicht/include/EMaterialTypes.h index 086ca3459..a88f50074 100644 --- a/lib/irrlicht/include/EMaterialTypes.h +++ b/lib/irrlicht/include/EMaterialTypes.h @@ -192,6 +192,9 @@ namespace video /** Using only first texture. Generic blending method. */ EMT_ONETEXTURE_BLEND, + //! Alphatest material for grass without using vertex color in stk. */ + EMT_STK_GRASS, + //! This value is not used. It only forces this enumeration to compile to 32 bit. EMT_FORCE_32BIT = 0x7fffffff }; diff --git a/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp b/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp index 87b87b73e..b7fa02d28 100644 --- a/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp +++ b/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp @@ -435,7 +435,7 @@ namespace video addAndDropMaterialRenderer(new COGLES2ParallaxMapRenderer(PMVSData, PMFSData, EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA, this)); addAndDropMaterialRenderer(new COGLES2FixedPipelineRenderer(FPVSData, FPFSData, EMT_ONETEXTURE_BLEND, this)); - + addAndDropMaterialRenderer(new COGLES2FixedPipelineRenderer(FPVSData, FPFSData, EMT_STK_GRASS, this)); delete[] FPVSData; delete[] FPFSData; delete[] NMVSData; diff --git a/lib/irrlicht/source/Irrlicht/COGLES2FixedPipelineRenderer.cpp b/lib/irrlicht/source/Irrlicht/COGLES2FixedPipelineRenderer.cpp index d1393f437..f7ea1a212 100644 --- a/lib/irrlicht/source/Irrlicht/COGLES2FixedPipelineRenderer.cpp +++ b/lib/irrlicht/source/Irrlicht/COGLES2FixedPipelineRenderer.cpp @@ -129,6 +129,9 @@ bool COGLES2FixedPipelineRenderer::OnRender(IMaterialRendererServices* service, case EMT_TRANSPARENT_REFLECTION_2_LAYER: materialType = 9; break; + case EMT_STK_GRASS: + materialType = 10; + break; default: break; } diff --git a/src/graphics/material.cpp b/src/graphics/material.cpp index ffde5d9b4..027a5d6a2 100644 --- a/src/graphics/material.cpp +++ b/src/graphics/material.cpp @@ -819,6 +819,9 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m } else if (m_shader_name == "grass") { +#ifdef USE_GLES2 + m->MaterialType = video::EMT_STK_GRASS; +#else m->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; #ifndef SERVER_ONLY @@ -831,6 +834,8 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m m->EmissiveColor = video::SColor(255, 150, 150, 150); m->SpecularColor = video::SColor(255, 150, 150, 150); } +#endif + #endif }