From 718ba69e1b81fe8149bdd637379cb37c7394d9c4 Mon Sep 17 00:00:00 2001 From: numzero Date: Sun, 2 Apr 2023 21:06:09 +0300 Subject: [PATCH] OpenGL3: Drop unused fixed-function emulation materials --- media/Shaders/DetailMap.fsh | 72 --------- media/Shaders/LightmapAdd.fsh | 72 --------- media/Shaders/LightmapModulate.fsh | 74 ---------- media/Shaders/Reflection2Layer.fsh | 72 --------- media/Shaders/Reflection2Layer.vsh | 55 ------- media/Shaders/Solid2.vsh | 53 ------- media/Shaders/Solid2Layer.fsh | 74 ---------- media/Shaders/SphereMap.fsh | 64 -------- media/Shaders/SphereMap.vsh | 50 ------- source/Irrlicht/OpenGL/Driver.cpp | 121 ++++------------ source/Irrlicht/OpenGL/Driver.h | 2 + .../Irrlicht/OpenGL/FixedPipelineRenderer.cpp | 137 +----------------- .../Irrlicht/OpenGL/FixedPipelineRenderer.h | 74 +--------- 13 files changed, 31 insertions(+), 889 deletions(-) delete mode 100644 media/Shaders/DetailMap.fsh delete mode 100644 media/Shaders/LightmapAdd.fsh delete mode 100644 media/Shaders/LightmapModulate.fsh delete mode 100644 media/Shaders/Reflection2Layer.fsh delete mode 100644 media/Shaders/Reflection2Layer.vsh delete mode 100644 media/Shaders/Solid2.vsh delete mode 100644 media/Shaders/Solid2Layer.fsh delete mode 100644 media/Shaders/SphereMap.fsh delete mode 100644 media/Shaders/SphereMap.vsh diff --git a/media/Shaders/DetailMap.fsh b/media/Shaders/DetailMap.fsh deleted file mode 100644 index 01c94d7..0000000 --- a/media/Shaders/DetailMap.fsh +++ /dev/null @@ -1,72 +0,0 @@ -#version 100 - -precision mediump float; - -/* Uniforms */ - -uniform int uTextureUsage0; -uniform int uTextureUsage1; -uniform sampler2D uTextureUnit0; -uniform sampler2D uTextureUnit1; -uniform int uFogEnable; -uniform int uFogType; -uniform vec4 uFogColor; -uniform float uFogStart; -uniform float uFogEnd; -uniform float uFogDensity; - -/* Varyings */ - -varying vec2 vTextureCoord0; -varying vec2 vTextureCoord1; -varying vec4 vVertexColor; -varying vec4 vSpecularColor; -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 = vec4(1.0, 1.0, 1.0, 1.0); - vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0); - - if (bool(uTextureUsage0)) - Color0 = texture2D(uTextureUnit0, vTextureCoord0); - - if (bool(uTextureUsage1)) - Color1 = texture2D(uTextureUnit1, vTextureCoord1); - - vec4 FinalColor = vec4(Color0 + (Color1 - 0.5)) * vVertexColor + vSpecularColor; - - if (bool(uFogEnable)) - { - float FogFactor = computeFog(); - vec4 FogColor = uFogColor; - FogColor.a = 1.0; - FinalColor = mix(FogColor, FinalColor, FogFactor); - } - - gl_FragColor = FinalColor; -} diff --git a/media/Shaders/LightmapAdd.fsh b/media/Shaders/LightmapAdd.fsh deleted file mode 100644 index 895625f..0000000 --- a/media/Shaders/LightmapAdd.fsh +++ /dev/null @@ -1,72 +0,0 @@ -#version 100 - -precision mediump float; - -/* Uniforms */ - -uniform int uTextureUsage0; -uniform int uTextureUsage1; -uniform sampler2D uTextureUnit0; -uniform sampler2D uTextureUnit1; -uniform int uFogEnable; -uniform int uFogType; -uniform vec4 uFogColor; -uniform float uFogStart; -uniform float uFogEnd; -uniform float uFogDensity; - -/* Varyings */ - -varying vec2 vTextureCoord0; -varying vec2 vTextureCoord1; -varying vec4 vVertexColor; -varying vec4 vSpecularColor; -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 = vec4(1.0, 1.0, 1.0, 1.0); - vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0); - - if (bool(uTextureUsage0)) - Color0 = texture2D(uTextureUnit0, vTextureCoord0); - - if (bool(uTextureUsage1)) - Color1 = texture2D(uTextureUnit1, vTextureCoord1); - - vec4 FinalColor = (Color0 + Color1) * vVertexColor + vSpecularColor; - - if (bool(uFogEnable)) - { - float FogFactor = computeFog(); - vec4 FogColor = uFogColor; - FogColor.a = 1.0; - FinalColor = mix(FogColor, FinalColor, FogFactor); - } - - gl_FragColor = FinalColor; -} diff --git a/media/Shaders/LightmapModulate.fsh b/media/Shaders/LightmapModulate.fsh deleted file mode 100644 index 74e9df1..0000000 --- a/media/Shaders/LightmapModulate.fsh +++ /dev/null @@ -1,74 +0,0 @@ -#version 100 - -precision mediump float; - -/* Uniforms */ - -uniform float uModulate; -uniform int uTextureUsage0; -uniform int uTextureUsage1; -uniform sampler2D uTextureUnit0; -uniform sampler2D uTextureUnit1; -uniform int uFogEnable; -uniform int uFogType; -uniform vec4 uFogColor; -uniform float uFogStart; -uniform float uFogEnd; -uniform float uFogDensity; - -/* Varyings */ - -varying vec2 vTextureCoord0; -varying vec2 vTextureCoord1; -varying vec4 vVertexColor; -varying vec4 vSpecularColor; -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 = vec4(1.0, 1.0, 1.0, 1.0); - vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0); - - if (bool(uTextureUsage0)) - Color0 = texture2D(uTextureUnit0, vTextureCoord0); - - if (bool(uTextureUsage1)) - Color1 = texture2D(uTextureUnit1, vTextureCoord1); - - vec4 FinalColor = (Color0 * Color1 * uModulate) * vVertexColor; - FinalColor += vSpecularColor; - - if (bool(uFogEnable)) - { - float FogFactor = computeFog(); - vec4 FogColor = uFogColor; - FogColor.a = 1.0; - FinalColor = mix(FogColor, FinalColor, FogFactor); - } - - gl_FragColor = FinalColor; -} diff --git a/media/Shaders/Reflection2Layer.fsh b/media/Shaders/Reflection2Layer.fsh deleted file mode 100644 index bdc3c66..0000000 --- a/media/Shaders/Reflection2Layer.fsh +++ /dev/null @@ -1,72 +0,0 @@ -#version 100 - -precision mediump float; - -/* Uniforms */ - -uniform int uTextureUsage0; -uniform int uTextureUsage1; -uniform sampler2D uTextureUnit0; -uniform sampler2D uTextureUnit1; -uniform int uFogEnable; -uniform int uFogType; -uniform vec4 uFogColor; -uniform float uFogStart; -uniform float uFogEnd; -uniform float uFogDensity; - -/* Varyings */ - -varying vec2 vTextureCoord0; -varying vec2 vTextureCoord1; -varying vec4 vVertexColor; -varying vec4 vSpecularColor; -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 = vec4(1.0, 1.0, 1.0, 1.0); - vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0); - - if (bool(uTextureUsage0)) - Color0 = texture2D(uTextureUnit0, vTextureCoord0); - - if (bool(uTextureUsage1)) - Color1 = texture2D(uTextureUnit1, vTextureCoord1); - - vec4 FinalColor = (Color0 * Color1) * vVertexColor + vSpecularColor; - - if (bool(uFogEnable)) - { - float FogFactor = computeFog(); - vec4 FogColor = uFogColor; - FogColor.a = 1.0; - FinalColor = mix(FogColor, FinalColor, FogFactor); - } - - gl_FragColor = FinalColor; -} diff --git a/media/Shaders/Reflection2Layer.vsh b/media/Shaders/Reflection2Layer.vsh deleted file mode 100644 index aafac22..0000000 --- a/media/Shaders/Reflection2Layer.vsh +++ /dev/null @@ -1,55 +0,0 @@ -#version 100 - -/* Attributes */ - -attribute vec3 inVertexPosition; -attribute vec3 inVertexNormal; -attribute vec4 inVertexColor; -attribute vec2 inTexCoord0; -attribute vec2 inTexCoord1; - -/* Uniforms */ - -uniform mat4 uWVPMatrix; -uniform mat4 uWVMatrix; -uniform mat4 uNMatrix; -uniform mat4 uTMatrix0; - -uniform vec4 uGlobalAmbient; -uniform vec4 uMaterialAmbient; -uniform vec4 uMaterialDiffuse; -uniform vec4 uMaterialEmissive; -uniform vec4 uMaterialSpecular; -uniform float uMaterialShininess; - -uniform float uThickness; - -/* Varyings */ - -varying vec2 vTextureCoord0; -varying vec2 vTextureCoord1; -varying vec4 vVertexColor; -varying vec4 vSpecularColor; -varying float vFogCoord; - -void main() -{ - gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0); - gl_PointSize = uThickness; - - vec4 TextureCoord0 = vec4(inTexCoord0.x, inTexCoord0.y, 1.0, 1.0); - vTextureCoord0 = vec4(uTMatrix0 * TextureCoord0).xy; - - vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz; - vec3 P = normalize(Position); - vec3 N = normalize(vec4(uNMatrix * vec4(inVertexNormal, 0.0)).xyz); - vec3 R = reflect(P, N); - - float V = 2.0 * sqrt(R.x*R.x + R.y*R.y + (R.z+1.0)*(R.z+1.0)); - vTextureCoord1 = vec2(R.x/V + 0.5, R.y/V + 0.5); - - vVertexColor = inVertexColor.bgra; - vSpecularColor = vec4(0.0, 0.0, 0.0, 0.0); - - vFogCoord = length(Position); -} diff --git a/media/Shaders/Solid2.vsh b/media/Shaders/Solid2.vsh deleted file mode 100644 index c49ecfc..0000000 --- a/media/Shaders/Solid2.vsh +++ /dev/null @@ -1,53 +0,0 @@ -#version 100 - -/* Attributes */ - -attribute vec3 inVertexPosition; -attribute vec3 inVertexNormal; -attribute vec4 inVertexColor; -attribute vec2 inTexCoord0; -attribute vec2 inTexCoord1; - -/* Uniforms */ - -uniform mat4 uWVPMatrix; -uniform mat4 uWVMatrix; -uniform mat4 uNMatrix; -uniform mat4 uTMatrix0; -uniform mat4 uTMatrix1; - -uniform vec4 uGlobalAmbient; -uniform vec4 uMaterialAmbient; -uniform vec4 uMaterialDiffuse; -uniform vec4 uMaterialEmissive; -uniform vec4 uMaterialSpecular; -uniform float uMaterialShininess; - -uniform float uThickness; - -/* Varyings */ - -varying vec2 vTextureCoord0; -varying vec2 vTextureCoord1; -varying vec4 vVertexColor; -varying vec4 vSpecularColor; -varying float vFogCoord; - -void main() -{ - gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0); - gl_PointSize = uThickness; - - vec4 TextureCoord0 = vec4(inTexCoord0.x, inTexCoord0.y, 1.0, 1.0); - vTextureCoord0 = vec4(uTMatrix0 * TextureCoord0).xy; - - vec4 TextureCoord1 = vec4(inTexCoord1.x, inTexCoord1.y, 1.0, 1.0); - vTextureCoord1 = vec4(uTMatrix1 * TextureCoord1).xy; - - vVertexColor = inVertexColor.bgra; - vSpecularColor = vec4(0.0, 0.0, 0.0, 0.0); - - vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz; - - vFogCoord = length(Position); -} diff --git a/media/Shaders/Solid2Layer.fsh b/media/Shaders/Solid2Layer.fsh deleted file mode 100644 index 3c8a39d..0000000 --- a/media/Shaders/Solid2Layer.fsh +++ /dev/null @@ -1,74 +0,0 @@ -#version 100 - -precision mediump float; - -/* Uniforms */ - -uniform int uTextureUsage0; -uniform int uTextureUsage1; -uniform sampler2D uTextureUnit0; -uniform sampler2D uTextureUnit1; -uniform int uFogEnable; -uniform int uFogType; -uniform vec4 uFogColor; -uniform float uFogStart; -uniform float uFogEnd; -uniform float uFogDensity; - -/* Varyings */ - -varying vec2 vTextureCoord0; -varying vec2 vTextureCoord1; -varying vec4 vVertexColor; -varying vec4 vSpecularColor; -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 = vec4(1.0, 1.0, 1.0, 1.0); - vec4 Color1 = vec4(1.0, 1.0, 1.0, 1.0); - - if (bool(uTextureUsage0)) - Color0 = texture2D(uTextureUnit0, vTextureCoord0); - - if (bool(uTextureUsage1)) - Color1 = texture2D(uTextureUnit1, vTextureCoord1); - - vec4 FinalColor = (Color0 * vVertexColor.a + Color1 * (1.0 - vVertexColor.a)) * vVertexColor; - FinalColor += vSpecularColor; - - if (bool(uFogEnable)) - { - float FogFactor = computeFog(); - vec4 FogColor = uFogColor; - FogColor.a = 1.0; - FinalColor = mix(FogColor, FinalColor, FogFactor); - } - - gl_FragColor = FinalColor; - -} diff --git a/media/Shaders/SphereMap.fsh b/media/Shaders/SphereMap.fsh deleted file mode 100644 index df1010e..0000000 --- a/media/Shaders/SphereMap.fsh +++ /dev/null @@ -1,64 +0,0 @@ -#version 100 - -precision mediump float; - -/* Uniforms */ - -uniform int uTextureUsage0; -uniform sampler2D uTextureUnit0; -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 vec4 vSpecularColor; -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 Color = vVertexColor; - - if (bool(uTextureUsage0)) - Color *= texture2D(uTextureUnit0, vTextureCoord0); - Color += vSpecularColor; - - if (bool(uFogEnable)) - { - float FogFactor = computeFog(); - vec4 FogColor = uFogColor; - FogColor.a = 1.0; - Color = mix(FogColor, Color, FogFactor); - } - - gl_FragColor = Color; -} diff --git a/media/Shaders/SphereMap.vsh b/media/Shaders/SphereMap.vsh deleted file mode 100644 index 5062d79..0000000 --- a/media/Shaders/SphereMap.vsh +++ /dev/null @@ -1,50 +0,0 @@ -#version 100 - -/* Attributes */ - -attribute vec3 inVertexPosition; -attribute vec3 inVertexNormal; -attribute vec4 inVertexColor; -attribute vec2 inTexCoord0; -attribute vec2 inTexCoord1; - -/* Uniforms */ - -uniform mat4 uWVPMatrix; -uniform mat4 uWVMatrix; -uniform mat4 uNMatrix; - -uniform vec4 uGlobalAmbient; -uniform vec4 uMaterialAmbient; -uniform vec4 uMaterialDiffuse; -uniform vec4 uMaterialEmissive; -uniform vec4 uMaterialSpecular; -uniform float uMaterialShininess; - -uniform float uThickness; - -/* Varyings */ - -varying vec2 vTextureCoord0; -varying vec4 vVertexColor; -varying vec4 vSpecularColor; -varying float vFogCoord; - -void main() -{ - gl_Position = uWVPMatrix * vec4(inVertexPosition, 1.0); - gl_PointSize = uThickness; - - vec3 Position = (uWVMatrix * vec4(inVertexPosition, 1.0)).xyz; - vec3 P = normalize(Position); - vec3 N = normalize(vec4(uNMatrix * vec4(inVertexNormal, 0.0)).xyz); - vec3 R = reflect(P, N); - - float V = 2.0 * sqrt(R.x*R.x + R.y*R.y + (R.z+1.0)*(R.z+1.0)); - vTextureCoord0 = vec2(R.x/V + 0.5, R.y/V + 0.5); - - vVertexColor = inVertexColor.bgra; - vSpecularColor = vec4(0.0, 0.0, 0.0, 0.0); - - vFogCoord = length(Position); -} diff --git a/source/Irrlicht/OpenGL/Driver.cpp b/source/Irrlicht/OpenGL/Driver.cpp index 641536f..6dec58f 100644 --- a/source/Irrlicht/OpenGL/Driver.cpp +++ b/source/Irrlicht/OpenGL/Driver.cpp @@ -317,140 +317,73 @@ COpenGL3DriverBase::~COpenGL3DriverBase() fsFile->drop(); } + void COpenGL3DriverBase::addDummyMaterial(E_MATERIAL_TYPE type) { + auto index = addMaterialRenderer(getMaterialRenderer(EMT_SOLID), "DUMMY"); + assert(index == type); + } + void COpenGL3DriverBase::createMaterialRenderers() { // Create callbacks. COpenGL3MaterialSolidCB* SolidCB = new COpenGL3MaterialSolidCB(); - COpenGL3MaterialSolid2CB* Solid2LayerCB = new COpenGL3MaterialSolid2CB(); - COpenGL3MaterialLightmapCB* LightmapCB = new COpenGL3MaterialLightmapCB(1.f); - COpenGL3MaterialLightmapCB* LightmapAddCB = new COpenGL3MaterialLightmapCB(1.f); - COpenGL3MaterialLightmapCB* LightmapM2CB = new COpenGL3MaterialLightmapCB(2.f); - COpenGL3MaterialLightmapCB* LightmapM4CB = new COpenGL3MaterialLightmapCB(4.f); - COpenGL3MaterialLightmapCB* LightmapLightingCB = new COpenGL3MaterialLightmapCB(1.f); - COpenGL3MaterialLightmapCB* LightmapLightingM2CB = new COpenGL3MaterialLightmapCB(2.f); - COpenGL3MaterialLightmapCB* LightmapLightingM4CB = new COpenGL3MaterialLightmapCB(4.f); - COpenGL3MaterialSolid2CB* DetailMapCB = new COpenGL3MaterialSolid2CB(); - COpenGL3MaterialReflectionCB* SphereMapCB = new COpenGL3MaterialReflectionCB(); - COpenGL3MaterialReflectionCB* Reflection2LayerCB = new COpenGL3MaterialReflectionCB(); - COpenGL3MaterialSolidCB* TransparentAddColorCB = new COpenGL3MaterialSolidCB(); COpenGL3MaterialSolidCB* TransparentAlphaChannelCB = new COpenGL3MaterialSolidCB(); COpenGL3MaterialSolidCB* TransparentAlphaChannelRefCB = new COpenGL3MaterialSolidCB(); COpenGL3MaterialSolidCB* TransparentVertexAlphaCB = new COpenGL3MaterialSolidCB(); - COpenGL3MaterialReflectionCB* TransparentReflection2LayerCB = new COpenGL3MaterialReflectionCB(); COpenGL3MaterialOneTextureBlendCB* OneTextureBlendCB = new COpenGL3MaterialOneTextureBlendCB(); // Create built-in materials. + // The addition order must be the same as in the E_MATERIAL_TYPE enumeration. Thus the + // addDummyMaterial calls for materials no longer supported. - core::stringc VertexShader = OGLES2ShaderPath + "Solid.vsh"; + const core::stringc VertexShader = OGLES2ShaderPath + "Solid.vsh"; + + // EMT_SOLID core::stringc FragmentShader = OGLES2ShaderPath + "Solid.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, SolidCB, EMT_SOLID, 0); - VertexShader = OGLES2ShaderPath + "Solid2.vsh"; - FragmentShader = OGLES2ShaderPath + "Solid2Layer.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, Solid2LayerCB, EMT_SOLID, 0); - - VertexShader = OGLES2ShaderPath + "Solid2.vsh"; - FragmentShader = OGLES2ShaderPath + "LightmapModulate.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, LightmapCB, EMT_SOLID, 0); - - FragmentShader = OGLES2ShaderPath + "LightmapAdd.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, LightmapAddCB, EMT_SOLID, 0); - - FragmentShader = OGLES2ShaderPath + "LightmapModulate.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, LightmapM2CB, EMT_SOLID, 0); - - 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, LightmapM4CB, EMT_SOLID, 0); - - 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, LightmapLightingCB, EMT_SOLID, 0); - - 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, LightmapLightingM2CB, EMT_SOLID, 0); - - 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, LightmapLightingM4CB, EMT_SOLID, 0); - - VertexShader = OGLES2ShaderPath + "Solid2.vsh"; - FragmentShader = OGLES2ShaderPath + "DetailMap.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, DetailMapCB, EMT_SOLID, 0); - - VertexShader = OGLES2ShaderPath + "SphereMap.vsh"; - FragmentShader = OGLES2ShaderPath + "SphereMap.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, SphereMapCB, EMT_SOLID, 0); - - VertexShader = OGLES2ShaderPath + "Reflection2Layer.vsh"; - FragmentShader = OGLES2ShaderPath + "Reflection2Layer.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, Reflection2LayerCB, EMT_SOLID, 0); - - VertexShader = OGLES2ShaderPath + "Solid.vsh"; - FragmentShader = OGLES2ShaderPath + "Solid.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, TransparentAddColorCB, EMT_TRANSPARENT_ADD_COLOR, 0); + addDummyMaterial(EMT_SOLID_2_LAYER); + addDummyMaterial(EMT_LIGHTMAP); + addDummyMaterial(EMT_LIGHTMAP_ADD); + addDummyMaterial(EMT_LIGHTMAP_M2); + addDummyMaterial(EMT_LIGHTMAP_M4); + addDummyMaterial(EMT_LIGHTMAP_LIGHTING); + addDummyMaterial(EMT_LIGHTMAP_LIGHTING_M2); + addDummyMaterial(EMT_LIGHTMAP_LIGHTING_M4); + addDummyMaterial(EMT_DETAIL_MAP); + addDummyMaterial(EMT_SPHERE_MAP); + addDummyMaterial(EMT_REFLECTION_2_LAYER); + addDummyMaterial(EMT_TRANSPARENT_ADD_COLOR); + // EMT_TRANSPARENT_ALPHA_CHANNEL FragmentShader = OGLES2ShaderPath + "TransparentAlphaChannel.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, TransparentAlphaChannelCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0); + // EMT_TRANSPARENT_ALPHA_CHANNEL_REF FragmentShader = OGLES2ShaderPath + "TransparentAlphaChannelRef.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, TransparentAlphaChannelRefCB, EMT_SOLID, 0); + // EMT_TRANSPARENT_VERTEX_ALPHA FragmentShader = OGLES2ShaderPath + "TransparentVertexAlpha.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, TransparentVertexAlphaCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0); - VertexShader = OGLES2ShaderPath + "Reflection2Layer.vsh"; - FragmentShader = OGLES2ShaderPath + "Reflection2Layer.fsh"; + addDummyMaterial(EMT_TRANSPARENT_REFLECTION_2_LAYER); - 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, TransparentReflection2LayerCB, EMT_TRANSPARENT_ALPHA_CHANNEL, 0); - - VertexShader = OGLES2ShaderPath + "Solid.vsh"; + // EMT_ONETEXTURE_BLEND FragmentShader = OGLES2ShaderPath + "OneTextureBlend.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); // Drop callbacks. SolidCB->drop(); - Solid2LayerCB->drop(); - LightmapCB->drop(); - LightmapAddCB->drop(); - LightmapM2CB->drop(); - LightmapM4CB->drop(); - LightmapLightingCB->drop(); - LightmapLightingM2CB->drop(); - LightmapLightingM4CB->drop(); - DetailMapCB->drop(); - SphereMapCB->drop(); - Reflection2LayerCB->drop(); - TransparentAddColorCB->drop(); TransparentAlphaChannelCB->drop(); TransparentAlphaChannelRefCB->drop(); TransparentVertexAlphaCB->drop(); - TransparentReflection2LayerCB->drop(); OneTextureBlendCB->drop(); // Create 2D material renderers diff --git a/source/Irrlicht/OpenGL/Driver.h b/source/Irrlicht/OpenGL/Driver.h index 06907b7..c91ccfe 100644 --- a/source/Irrlicht/OpenGL/Driver.h +++ b/source/Irrlicht/OpenGL/Driver.h @@ -384,6 +384,8 @@ private: IContextManager* ContextManager; + void addDummyMaterial(E_MATERIAL_TYPE type); + std::vector QuadsIndices; void initQuadsIndices(int max_vertex_count = 65536); diff --git a/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp b/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp index 2922470..421788a 100644 --- a/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp +++ b/source/Irrlicht/OpenGL/FixedPipelineRenderer.cpp @@ -1,3 +1,4 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy // Copyright (C) 2014 Patryk Nadrowski // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in Irrlicht.h @@ -137,142 +138,6 @@ void COpenGL3MaterialSolidCB::OnSetConstants(IMaterialRendererServices* services services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); } -// EMT_SOLID_2_LAYER + EMT_DETAIL_MAP - -COpenGL3MaterialSolid2CB::COpenGL3MaterialSolid2CB() : - FirstUpdate(true), TMatrix0ID(-1), TMatrix1ID(-1), TextureUsage0ID(-1), TextureUsage1ID(-1), TextureUnit0ID(-1), TextureUnit1ID(-1), - TextureUsage0(0), TextureUsage1(0), TextureUnit0(0), TextureUnit1(1) -{ -} - -void COpenGL3MaterialSolid2CB::OnSetMaterial(const SMaterial& material) -{ - COpenGL3MaterialBaseCB::OnSetMaterial(material); - - TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; - TextureUsage1 = (material.TextureLayer[1].Texture) ? 1 : 0; -} - -void COpenGL3MaterialSolid2CB::OnSetConstants(IMaterialRendererServices* services, s32 userData) -{ - COpenGL3MaterialBaseCB::OnSetConstants(services, userData); - - IVideoDriver* driver = services->getVideoDriver(); - - if (FirstUpdate) - { - TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); - TMatrix1ID = services->getVertexShaderConstantID("uTMatrix1"); - TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); - TextureUsage1ID = services->getVertexShaderConstantID("uTextureUsage1"); - TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); - TextureUnit1ID = services->getVertexShaderConstantID("uTextureUnit1"); - - FirstUpdate = false; - } - - core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); - services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); - - Matrix = driver->getTransform(E_TRANSFORMATION_STATE(ETS_TEXTURE_0 + 1)); - services->setPixelShaderConstant(TMatrix1ID, Matrix.pointer(), 16); - - services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); - services->setPixelShaderConstant(TextureUsage1ID, &TextureUsage1, 1); - services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); - services->setPixelShaderConstant(TextureUnit1ID, &TextureUnit1, 1); -} - -// EMT_LIGHTMAP + EMT_LIGHTMAP_ADD + EMT_LIGHTMAP_M2 + EMT_LIGHTMAP_M4 - -COpenGL3MaterialLightmapCB::COpenGL3MaterialLightmapCB(float modulate) : - FirstUpdate(true), TMatrix0ID(-1), TMatrix1ID(-1), ModulateID(-1), TextureUsage0ID(-1), TextureUsage1ID(-1), TextureUnit0ID(-1), TextureUnit1ID(-1), - Modulate(modulate), TextureUsage0(0), TextureUsage1(0), TextureUnit0(0), TextureUnit1(1) -{ -} - -void COpenGL3MaterialLightmapCB::OnSetMaterial(const SMaterial& material) -{ - COpenGL3MaterialBaseCB::OnSetMaterial(material); - - TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; - TextureUsage1 = (material.TextureLayer[1].Texture) ? 1 : 0; -} - -void COpenGL3MaterialLightmapCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) -{ - COpenGL3MaterialBaseCB::OnSetConstants(services, userData); - - IVideoDriver* driver = services->getVideoDriver(); - - if (FirstUpdate) - { - TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); - TMatrix1ID = services->getVertexShaderConstantID("uTMatrix1"); - ModulateID = services->getVertexShaderConstantID("uModulate"); - TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); - TextureUsage1ID = services->getVertexShaderConstantID("uTextureUsage1"); - TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); - TextureUnit1ID = services->getVertexShaderConstantID("uTextureUnit1"); - - FirstUpdate = false; - } - - core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); - services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); - - Matrix = driver->getTransform(E_TRANSFORMATION_STATE(ETS_TEXTURE_0 + 1)); - services->setPixelShaderConstant(TMatrix1ID, Matrix.pointer(), 16); - - services->setPixelShaderConstant(ModulateID, &Modulate, 1); - services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); - services->setPixelShaderConstant(TextureUsage1ID, &TextureUsage1, 1); - services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); - services->setPixelShaderConstant(TextureUnit1ID, &TextureUnit1, 1); -} - -// EMT_SPHERE_MAP + EMT_REFLECTION_2_LAYER + EMT_TRANSPARENT_REFLECTION_2_LAYER - -COpenGL3MaterialReflectionCB::COpenGL3MaterialReflectionCB() : - FirstUpdate(true), TMatrix0ID(-1), TextureUsage0ID(-1), TextureUsage1ID(-1), TextureUnit0ID(-1), TextureUnit1ID(-1), - TextureUsage0(0), TextureUsage1(0), TextureUnit0(0), TextureUnit1(1) -{ -} - -void COpenGL3MaterialReflectionCB::OnSetMaterial(const SMaterial& material) -{ - COpenGL3MaterialBaseCB::OnSetMaterial(material); - - TextureUsage0 = (material.TextureLayer[0].Texture) ? 1 : 0; - TextureUsage1 = (material.TextureLayer[1].Texture) ? 1 : 0; -} - -void COpenGL3MaterialReflectionCB::OnSetConstants(IMaterialRendererServices* services, s32 userData) -{ - COpenGL3MaterialBaseCB::OnSetConstants(services, userData); - - IVideoDriver* driver = services->getVideoDriver(); - - if (FirstUpdate) - { - TMatrix0ID = services->getVertexShaderConstantID("uTMatrix0"); - TextureUsage0ID = services->getVertexShaderConstantID("uTextureUsage0"); - TextureUsage1ID = services->getVertexShaderConstantID("uTextureUsage1"); - TextureUnit0ID = services->getVertexShaderConstantID("uTextureUnit0"); - TextureUnit1ID = services->getVertexShaderConstantID("uTextureUnit1"); - - FirstUpdate = false; - } - - core::matrix4 Matrix = driver->getTransform(ETS_TEXTURE_0); - services->setPixelShaderConstant(TMatrix0ID, Matrix.pointer(), 16); - - services->setPixelShaderConstant(TextureUsage0ID, &TextureUsage0, 1); - services->setPixelShaderConstant(TextureUsage1ID, &TextureUsage1, 1); - services->setPixelShaderConstant(TextureUnit0ID, &TextureUnit0, 1); - services->setPixelShaderConstant(TextureUnit1ID, &TextureUnit1, 1); -} - // EMT_ONETEXTURE_BLEND COpenGL3MaterialOneTextureBlendCB::COpenGL3MaterialOneTextureBlendCB() : diff --git a/source/Irrlicht/OpenGL/FixedPipelineRenderer.h b/source/Irrlicht/OpenGL/FixedPipelineRenderer.h index aea935f..cfbb3b6 100644 --- a/source/Irrlicht/OpenGL/FixedPipelineRenderer.h +++ b/source/Irrlicht/OpenGL/FixedPipelineRenderer.h @@ -1,3 +1,4 @@ +// Copyright (C) 2023 Vitaliy Lobachevskiy // Copyright (C) 2014 Patryk Nadrowski // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in Irrlicht.h @@ -82,79 +83,6 @@ protected: s32 TextureUnit0; }; -class COpenGL3MaterialSolid2CB : public COpenGL3MaterialBaseCB -{ -public: - COpenGL3MaterialSolid2CB(); - - virtual void OnSetMaterial(const SMaterial& material); - virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); - -protected: - bool FirstUpdate; - - s32 TMatrix0ID; - s32 TMatrix1ID; - s32 TextureUsage0ID; - s32 TextureUsage1ID; - s32 TextureUnit0ID; - s32 TextureUnit1ID; - - s32 TextureUsage0; - s32 TextureUsage1; - s32 TextureUnit0; - s32 TextureUnit1; -}; - -class COpenGL3MaterialLightmapCB : public COpenGL3MaterialBaseCB -{ -public: - COpenGL3MaterialLightmapCB(float modulate); - - virtual void OnSetMaterial(const SMaterial& material); - virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); - -protected: - bool FirstUpdate; - - s32 TMatrix0ID; - s32 TMatrix1ID; - s32 ModulateID; - s32 TextureUsage0ID; - s32 TextureUsage1ID; - s32 TextureUnit0ID; - s32 TextureUnit1ID; - - f32 Modulate; - s32 TextureUsage0; - s32 TextureUsage1; - s32 TextureUnit0; - s32 TextureUnit1; -}; - -class COpenGL3MaterialReflectionCB : public COpenGL3MaterialBaseCB -{ -public: - COpenGL3MaterialReflectionCB(); - - virtual void OnSetMaterial(const SMaterial& material); - virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData); - -protected: - bool FirstUpdate; - - s32 TMatrix0ID; - s32 TextureUsage0ID; - s32 TextureUsage1ID; - s32 TextureUnit0ID; - s32 TextureUnit1ID; - - s32 TextureUsage0; - s32 TextureUsage1; - s32 TextureUnit0; - s32 TextureUnit1; -}; - class COpenGL3MaterialOneTextureBlendCB : public COpenGL3MaterialBaseCB { public: