Add back normal map renderer for legacy opengl
Fixed transparent issue
This commit is contained in:
parent
f853255204
commit
a52c4699a1
@ -187,6 +187,7 @@ source/Irrlicht/CZipReader.cpp
|
|||||||
source/Irrlicht/Irrlicht.cpp
|
source/Irrlicht/Irrlicht.cpp
|
||||||
source/Irrlicht/irrXML.cpp
|
source/Irrlicht/irrXML.cpp
|
||||||
source/Irrlicht/os.cpp
|
source/Irrlicht/os.cpp
|
||||||
|
source/Irrlicht/COpenGLNormalMapRenderer.cpp
|
||||||
source/Irrlicht/BuiltInFont.h
|
source/Irrlicht/BuiltInFont.h
|
||||||
source/Irrlicht/CAnimatedMeshSceneNode.h
|
source/Irrlicht/CAnimatedMeshSceneNode.h
|
||||||
source/Irrlicht/CAttributeImpl.h
|
source/Irrlicht/CAttributeImpl.h
|
||||||
@ -339,6 +340,7 @@ source/Irrlicht/S4DVertex.h
|
|||||||
source/Irrlicht/SoftwareDriver2_compile_config.h
|
source/Irrlicht/SoftwareDriver2_compile_config.h
|
||||||
source/Irrlicht/SoftwareDriver2_helper.h
|
source/Irrlicht/SoftwareDriver2_helper.h
|
||||||
source/Irrlicht/wglext.h
|
source/Irrlicht/wglext.h
|
||||||
|
source/Irrlicht/COpenGLNormalMapRenderer.h
|
||||||
|
|
||||||
include/aabbox3d.h
|
include/aabbox3d.h
|
||||||
include/CDynamicMeshBuffer.h
|
include/CDynamicMeshBuffer.h
|
||||||
|
@ -700,17 +700,20 @@ namespace video
|
|||||||
//! normal map lookup 32 bit version
|
//! normal map lookup 32 bit version
|
||||||
inline f32 nml32(int x, int y, int pitch, int height, s32 *p) const
|
inline f32 nml32(int x, int y, int pitch, int height, s32 *p) const
|
||||||
{
|
{
|
||||||
if (x < 0) x = pitch-1; if (x >= pitch) x = 0;
|
if (x < 0) x = pitch-1;
|
||||||
if (y < 0) y = height-1; if (y >= height) y = 0;
|
if (x >= pitch) x = 0;
|
||||||
|
if (y < 0) y = height-1;
|
||||||
|
if (y >= height) y = 0;
|
||||||
return (f32)(((p[(y * pitch) + x])>>16) & 0xff);
|
return (f32)(((p[(y * pitch) + x])>>16) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! normal map lookup 16 bit version
|
//! normal map lookup 16 bit version
|
||||||
inline f32 nml16(int x, int y, int pitch, int height, s16 *p) const
|
inline f32 nml16(int x, int y, int pitch, int height, s16 *p) const
|
||||||
{
|
{
|
||||||
if (x < 0) x = pitch-1; if (x >= pitch) x = 0;
|
if (x < 0) x = pitch-1;
|
||||||
if (y < 0) y = height-1; if (y >= height) y = 0;
|
if (x >= pitch) x = 0;
|
||||||
|
if (y < 0) y = height-1;
|
||||||
|
if (y >= height) y = 0;
|
||||||
return (f32) getAverage ( p[(y * pitch) + x] );
|
return (f32) getAverage ( p[(y * pitch) + x] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ extern bool GLContextDebugBit;
|
|||||||
#include "COpenGLMaterialRenderer.h"
|
#include "COpenGLMaterialRenderer.h"
|
||||||
#include "COpenGLShaderMaterialRenderer.h"
|
#include "COpenGLShaderMaterialRenderer.h"
|
||||||
#include "COpenGLSLMaterialRenderer.h"
|
#include "COpenGLSLMaterialRenderer.h"
|
||||||
|
#include "COpenGLNormalMapRenderer.h"
|
||||||
#include "COpenGLParallaxMapRenderer.h"
|
#include "COpenGLParallaxMapRenderer.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ namespace irr
|
|||||||
{
|
{
|
||||||
namespace video
|
namespace video
|
||||||
{
|
{
|
||||||
bool useCoreContext;
|
bool useCoreContext;
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// WINDOWS CONSTRUCTOR
|
// WINDOWS CONSTRUCTOR
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@ -85,107 +86,107 @@ static PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs_ARB;
|
|||||||
|
|
||||||
static HGLRC getMeAGLContext(HDC HDc, bool force_legacy_context)
|
static HGLRC getMeAGLContext(HDC HDc, bool force_legacy_context)
|
||||||
{
|
{
|
||||||
if (!force_legacy_context)
|
if (!force_legacy_context)
|
||||||
{
|
{
|
||||||
useCoreContext = true;
|
useCoreContext = true;
|
||||||
HGLRC hrc = 0;
|
HGLRC hrc = 0;
|
||||||
int ctx44debug[] =
|
int ctx44debug[] =
|
||||||
{
|
{
|
||||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
|
||||||
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
|
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
|
||||||
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
|
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
|
||||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
int ctx44[] =
|
int ctx44[] =
|
||||||
{
|
{
|
||||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
|
||||||
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
|
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
|
||||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx44debug : ctx44);
|
hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx44debug : ctx44);
|
||||||
if (hrc)
|
if (hrc)
|
||||||
return hrc;
|
return hrc;
|
||||||
|
|
||||||
int ctx40debug[] =
|
int ctx40debug[] =
|
||||||
{
|
{
|
||||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
|
||||||
WGL_CONTEXT_MINOR_VERSION_ARB, 0,
|
WGL_CONTEXT_MINOR_VERSION_ARB, 0,
|
||||||
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
|
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
|
||||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
int ctx40[] =
|
int ctx40[] =
|
||||||
{
|
{
|
||||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
|
||||||
WGL_CONTEXT_MINOR_VERSION_ARB, 0,
|
WGL_CONTEXT_MINOR_VERSION_ARB, 0,
|
||||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx40debug : ctx40);
|
hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx40debug : ctx40);
|
||||||
if (hrc)
|
if (hrc)
|
||||||
return hrc;
|
return hrc;
|
||||||
|
|
||||||
int ctx33debug[] =
|
int ctx33debug[] =
|
||||||
{
|
{
|
||||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||||
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
|
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
|
||||||
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
|
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
|
||||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
int ctx33[] =
|
int ctx33[] =
|
||||||
{
|
{
|
||||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||||
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
|
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
|
||||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx33debug : ctx33);
|
hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx33debug : ctx33);
|
||||||
if (hrc)
|
if (hrc)
|
||||||
return hrc;
|
return hrc;
|
||||||
|
|
||||||
int ctx31debug[] =
|
int ctx31debug[] =
|
||||||
{
|
{
|
||||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||||
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
|
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
|
||||||
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
|
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
|
||||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
int ctx31[] =
|
int ctx31[] =
|
||||||
{
|
{
|
||||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||||
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
|
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
|
||||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx31debug : ctx31);
|
hrc = wglCreateContextAttribs_ARB(HDc, 0, GLContextDebugBit ? ctx31debug : ctx31);
|
||||||
if (hrc)
|
if (hrc)
|
||||||
return hrc;
|
return hrc;
|
||||||
} // if (!force_legacy_context)
|
} // if (!force_legacy_context)
|
||||||
|
|
||||||
useCoreContext = false;
|
useCoreContext = false;
|
||||||
int legacyctx[] =
|
int legacyctx[] =
|
||||||
{
|
{
|
||||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 2,
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 2,
|
||||||
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
|
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
HGLRC hrc = wglCreateContextAttribs_ARB(HDc, 0, legacyctx);
|
HGLRC hrc = wglCreateContextAttribs_ARB(HDc, 0, legacyctx);
|
||||||
if (hrc)
|
if (hrc)
|
||||||
return hrc;
|
return hrc;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! inits the open gl driver
|
//! inits the open gl driver
|
||||||
@ -513,8 +514,8 @@ bool COpenGLDriver::initDriver(CIrrDeviceWin32* device)
|
|||||||
#ifdef WGL_ARB_create_context
|
#ifdef WGL_ARB_create_context
|
||||||
if (wglCreateContextAttribs_ARB)
|
if (wglCreateContextAttribs_ARB)
|
||||||
{
|
{
|
||||||
hrc = getMeAGLContext(HDc, Params.ForceLegacyDevice);
|
hrc = getMeAGLContext(HDc, Params.ForceLegacyDevice);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
hrc=wglCreateContext(HDc);
|
hrc=wglCreateContext(HDc);
|
||||||
@ -797,11 +798,11 @@ bool COpenGLDriver::genericDriverInit()
|
|||||||
|
|
||||||
setAmbientLight(SColorf(0.0f,0.0f,0.0f,0.0f));
|
setAmbientLight(SColorf(0.0f,0.0f,0.0f,0.0f));
|
||||||
#ifdef GL_EXT_separate_specular_color
|
#ifdef GL_EXT_separate_specular_color
|
||||||
if (FeatureAvailable[IRR_EXT_separate_specular_color] && !useCoreContext)
|
if (FeatureAvailable[IRR_EXT_separate_specular_color] && !useCoreContext)
|
||||||
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
|
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
|
||||||
#endif
|
#endif
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
||||||
|
|
||||||
Params.HandleSRGB &= ((FeatureAvailable[IRR_ARB_framebuffer_sRGB] || FeatureAvailable[IRR_EXT_framebuffer_sRGB]) &&
|
Params.HandleSRGB &= ((FeatureAvailable[IRR_ARB_framebuffer_sRGB] || FeatureAvailable[IRR_EXT_framebuffer_sRGB]) &&
|
||||||
FeatureAvailable[IRR_EXT_texture_sRGB]);
|
FeatureAvailable[IRR_EXT_texture_sRGB]);
|
||||||
@ -820,8 +821,8 @@ bool COpenGLDriver::genericDriverInit()
|
|||||||
// glEnable(GL_RESCALE_NORMAL_EXT);
|
// glEnable(GL_RESCALE_NORMAL_EXT);
|
||||||
|
|
||||||
glClearDepth(1.0);
|
glClearDepth(1.0);
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||||
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
||||||
glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST);
|
glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST);
|
||||||
glDepthFunc(GL_LEQUAL);
|
glDepthFunc(GL_LEQUAL);
|
||||||
@ -837,8 +838,8 @@ bool COpenGLDriver::genericDriverInit()
|
|||||||
// set the renderstates
|
// set the renderstates
|
||||||
setRenderStates3DMode();
|
setRenderStates3DMode();
|
||||||
|
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glAlphaFunc(GL_GREATER, 0.f);
|
glAlphaFunc(GL_GREATER, 0.f);
|
||||||
|
|
||||||
// set fog mode
|
// set fog mode
|
||||||
setFog(FogColor, FogType, FogStart, FogEnd, FogDensity, PixelFog, RangeFog);
|
setFog(FogColor, FogType, FogStart, FogEnd, FogDensity, PixelFog, RangeFog);
|
||||||
@ -885,6 +886,15 @@ void COpenGLDriver::createMaterialRenderers()
|
|||||||
// add normal map renderers
|
// add normal map renderers
|
||||||
s32 tmp = 0;
|
s32 tmp = 0;
|
||||||
video::IMaterialRenderer* renderer = 0;
|
video::IMaterialRenderer* renderer = 0;
|
||||||
|
if (!useCoreContext)
|
||||||
|
{
|
||||||
|
renderer = new COpenGLNormalMapRenderer(this, tmp, MaterialRenderers[EMT_SOLID].Renderer);
|
||||||
|
renderer->drop();
|
||||||
|
renderer = new COpenGLNormalMapRenderer(this, tmp, MaterialRenderers[EMT_TRANSPARENT_ADD_COLOR].Renderer);
|
||||||
|
renderer->drop();
|
||||||
|
renderer = new COpenGLNormalMapRenderer(this, tmp, MaterialRenderers[EMT_TRANSPARENT_VERTEX_ALPHA].Renderer);
|
||||||
|
renderer->drop();
|
||||||
|
}
|
||||||
|
|
||||||
// add parallax map renderers
|
// add parallax map renderers
|
||||||
renderer = new COpenGLParallaxMapRenderer(this, tmp, MaterialRenderers[EMT_SOLID].Renderer);
|
renderer = new COpenGLParallaxMapRenderer(this, tmp, MaterialRenderers[EMT_SOLID].Renderer);
|
||||||
@ -1025,29 +1035,31 @@ void COpenGLDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matri
|
|||||||
case ETS_WORLD:
|
case ETS_WORLD:
|
||||||
{
|
{
|
||||||
// OpenGL only has a model matrix, view and world is not existent. so lets fake these two.
|
// OpenGL only has a model matrix, view and world is not existent. so lets fake these two.
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
// first load the viewing transformation for user clip planes
|
// first load the viewing transformation for user clip planes
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glLoadMatrixf((Matrices[ETS_VIEW]).pointer());
|
glLoadMatrixf((Matrices[ETS_VIEW]).pointer());
|
||||||
|
|
||||||
// we have to update the clip planes to the latest view matrix
|
// we have to update the clip planes to the latest view matrix
|
||||||
for (u32 i=0; i<MaxUserClipPlanes; ++i)
|
for (u32 i=0; i<MaxUserClipPlanes; ++i)
|
||||||
|
{
|
||||||
if (UserClipPlanes[i].Enabled)
|
if (UserClipPlanes[i].Enabled)
|
||||||
uploadClipPlane(i);
|
uploadClipPlane(i);
|
||||||
|
}
|
||||||
|
|
||||||
// now the real model-view matrix
|
// now the real model-view matrix
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glMultMatrixf(Matrices[ETS_WORLD].pointer());
|
glMultMatrixf(Matrices[ETS_WORLD].pointer());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ETS_PROJECTION:
|
case ETS_PROJECTION:
|
||||||
{
|
{
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glLoadMatrixf(mat.pointer());
|
glLoadMatrixf(mat.pointer());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ETS_COUNT:
|
case ETS_COUNT:
|
||||||
@ -1063,9 +1075,9 @@ void COpenGLDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matri
|
|||||||
if (MultiTextureExtension)
|
if (MultiTextureExtension)
|
||||||
extGlActiveTexture(GL_TEXTURE0_ARB + i);
|
extGlActiveTexture(GL_TEXTURE0_ARB + i);
|
||||||
|
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glMatrixMode(GL_TEXTURE);
|
glMatrixMode(GL_TEXTURE);
|
||||||
if (!isRTT && mat.isIdentity() && !useCoreContext)
|
if (!isRTT && mat.isIdentity() && !useCoreContext)
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1074,8 +1086,8 @@ void COpenGLDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matri
|
|||||||
getGLTextureMatrix(glmat, mat * TextureFlipMatrix);
|
getGLTextureMatrix(glmat, mat * TextureFlipMatrix);
|
||||||
else
|
else
|
||||||
getGLTextureMatrix(glmat, mat);
|
getGLTextureMatrix(glmat, mat);
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glLoadMatrixf(glmat);
|
glLoadMatrixf(glmat);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1846,8 +1858,8 @@ void COpenGLDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCo
|
|||||||
if (!primitiveCount || !vertexCount)
|
if (!primitiveCount || !vertexCount)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (useCoreContext)
|
if (useCoreContext)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!checkPrimitiveCount(primitiveCount))
|
if (!checkPrimitiveCount(primitiveCount))
|
||||||
return;
|
return;
|
||||||
@ -2526,23 +2538,23 @@ bool COpenGLDriver::setActiveTexture(u32 stage, const video::ITexture* texture)
|
|||||||
|
|
||||||
if (!texture)
|
if (!texture)
|
||||||
{
|
{
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (texture->getDriverType() != EDT_OPENGL)
|
if (texture->getDriverType() != EDT_OPENGL)
|
||||||
{
|
{
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
CurrentTexture.set(stage, 0);
|
CurrentTexture.set(stage, 0);
|
||||||
os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR);
|
os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D,
|
glBindTexture(GL_TEXTURE_2D,
|
||||||
static_cast<const COpenGLTexture*>(texture)->getOpenGLTextureName());
|
static_cast<const COpenGLTexture*>(texture)->getOpenGLTextureName());
|
||||||
}
|
}
|
||||||
@ -2658,20 +2670,20 @@ void COpenGLDriver::setRenderStates3DMode()
|
|||||||
{
|
{
|
||||||
// Reset Texture Stages
|
// Reset Texture Stages
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glDisable(GL_ALPHA_TEST);
|
glDisable(GL_ALPHA_TEST);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
// switch back the matrices
|
// switch back the matrices
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer());
|
glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer());
|
||||||
|
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glLoadMatrixf(Matrices[ETS_PROJECTION].pointer());
|
glLoadMatrixf(Matrices[ETS_PROJECTION].pointer());
|
||||||
|
|
||||||
ResetRenderStates = true;
|
ResetRenderStates = true;
|
||||||
#ifdef GL_EXT_clip_volume_hint
|
#ifdef GL_EXT_clip_volume_hint
|
||||||
@ -2838,27 +2850,27 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
|
|||||||
glDisable(GL_COLOR_MATERIAL);
|
glDisable(GL_COLOR_MATERIAL);
|
||||||
break;
|
break;
|
||||||
case ECM_DIFFUSE:
|
case ECM_DIFFUSE:
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
|
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
|
||||||
break;
|
break;
|
||||||
case ECM_AMBIENT:
|
case ECM_AMBIENT:
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
|
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
|
||||||
break;
|
break;
|
||||||
case ECM_EMISSIVE:
|
case ECM_EMISSIVE:
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION);
|
glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION);
|
||||||
break;
|
break;
|
||||||
case ECM_SPECULAR:
|
case ECM_SPECULAR:
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
|
glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
|
||||||
break;
|
break;
|
||||||
case ECM_DIFFUSE_AND_AMBIENT:
|
case ECM_DIFFUSE_AND_AMBIENT:
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (material.ColorMaterial != ECM_NONE && !useCoreContext)
|
if (material.ColorMaterial != ECM_NONE && !useCoreContext)
|
||||||
glEnable(GL_COLOR_MATERIAL);
|
glEnable(GL_COLOR_MATERIAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2879,8 +2891,8 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
|
|||||||
color[1] = material.AmbientColor.getGreen() * inv;
|
color[1] = material.AmbientColor.getGreen() * inv;
|
||||||
color[2] = material.AmbientColor.getBlue() * inv;
|
color[2] = material.AmbientColor.getBlue() * inv;
|
||||||
color[3] = material.AmbientColor.getAlpha() * inv;
|
color[3] = material.AmbientColor.getAlpha() * inv;
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((material.ColorMaterial != video::ECM_DIFFUSE) &&
|
if ((material.ColorMaterial != video::ECM_DIFFUSE) &&
|
||||||
@ -2890,8 +2902,8 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
|
|||||||
color[1] = material.DiffuseColor.getGreen() * inv;
|
color[1] = material.DiffuseColor.getGreen() * inv;
|
||||||
color[2] = material.DiffuseColor.getBlue() * inv;
|
color[2] = material.DiffuseColor.getBlue() * inv;
|
||||||
color[3] = material.DiffuseColor.getAlpha() * inv;
|
color[3] = material.DiffuseColor.getAlpha() * inv;
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (material.ColorMaterial != video::ECM_EMISSIVE)
|
if (material.ColorMaterial != video::ECM_EMISSIVE)
|
||||||
@ -2900,8 +2912,8 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
|
|||||||
color[1] = material.EmissiveColor.getGreen() * inv;
|
color[1] = material.EmissiveColor.getGreen() * inv;
|
||||||
color[2] = material.EmissiveColor.getBlue() * inv;
|
color[2] = material.EmissiveColor.getBlue() * inv;
|
||||||
color[3] = material.EmissiveColor.getAlpha() * inv;
|
color[3] = material.EmissiveColor.getAlpha() * inv;
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2913,14 +2925,14 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
|
|||||||
GLfloat color[4]={0.f,0.f,0.f,1.f};
|
GLfloat color[4]={0.f,0.f,0.f,1.f};
|
||||||
const f32 inv = 1.0f / 255.0f;
|
const f32 inv = 1.0f / 255.0f;
|
||||||
|
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.Shininess);
|
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.Shininess);
|
||||||
// disable Specular colors if no shininess is set
|
// disable Specular colors if no shininess is set
|
||||||
if ((material.Shininess != 0.0f) &&
|
if ((material.Shininess != 0.0f) &&
|
||||||
(material.ColorMaterial != video::ECM_SPECULAR))
|
(material.ColorMaterial != video::ECM_SPECULAR))
|
||||||
{
|
{
|
||||||
#ifdef GL_EXT_separate_specular_color
|
#ifdef GL_EXT_separate_specular_color
|
||||||
if (FeatureAvailable[IRR_EXT_separate_specular_color] && !useCoreContext)
|
if (FeatureAvailable[IRR_EXT_separate_specular_color] && !useCoreContext)
|
||||||
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
|
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
|
||||||
#endif
|
#endif
|
||||||
color[0] = material.SpecularColor.getRed() * inv;
|
color[0] = material.SpecularColor.getRed() * inv;
|
||||||
@ -2929,11 +2941,11 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
|
|||||||
color[3] = material.SpecularColor.getAlpha() * inv;
|
color[3] = material.SpecularColor.getAlpha() * inv;
|
||||||
}
|
}
|
||||||
#ifdef GL_EXT_separate_specular_color
|
#ifdef GL_EXT_separate_specular_color
|
||||||
else if (FeatureAvailable[IRR_EXT_separate_specular_color] && !useCoreContext)
|
else if (FeatureAvailable[IRR_EXT_separate_specular_color] && !useCoreContext)
|
||||||
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
|
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
|
||||||
#endif
|
#endif
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
|
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texture filter
|
// Texture filter
|
||||||
@ -2987,18 +2999,18 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
|
|||||||
// shademode
|
// shademode
|
||||||
if (resetAllRenderStates || (lastmaterial.GouraudShading != material.GouraudShading))
|
if (resetAllRenderStates || (lastmaterial.GouraudShading != material.GouraudShading))
|
||||||
{
|
{
|
||||||
if (material.GouraudShading && !useCoreContext)
|
if (material.GouraudShading && !useCoreContext)
|
||||||
glShadeModel(GL_SMOOTH);
|
glShadeModel(GL_SMOOTH);
|
||||||
else if (!useCoreContext)
|
else if (!useCoreContext)
|
||||||
glShadeModel(GL_FLAT);
|
glShadeModel(GL_FLAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// lighting
|
// lighting
|
||||||
if (resetAllRenderStates || (lastmaterial.Lighting != material.Lighting))
|
if (resetAllRenderStates || (lastmaterial.Lighting != material.Lighting))
|
||||||
{
|
{
|
||||||
if (material.Lighting && !useCoreContext)
|
if (material.Lighting && !useCoreContext)
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
else if (!useCoreContext)
|
else if (!useCoreContext)
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3079,18 +3091,18 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater
|
|||||||
// fog
|
// fog
|
||||||
if (resetAllRenderStates || lastmaterial.FogEnable != material.FogEnable)
|
if (resetAllRenderStates || lastmaterial.FogEnable != material.FogEnable)
|
||||||
{
|
{
|
||||||
if (material.FogEnable && !useCoreContext)
|
if (material.FogEnable && !useCoreContext)
|
||||||
glEnable(GL_FOG);
|
glEnable(GL_FOG);
|
||||||
else if (!useCoreContext)
|
else if (!useCoreContext)
|
||||||
glDisable(GL_FOG);
|
glDisable(GL_FOG);
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalization
|
// normalization
|
||||||
if (resetAllRenderStates || lastmaterial.NormalizeNormals != material.NormalizeNormals)
|
if (resetAllRenderStates || lastmaterial.NormalizeNormals != material.NormalizeNormals)
|
||||||
{
|
{
|
||||||
if (material.NormalizeNormals && !useCoreContext)
|
if (material.NormalizeNormals && !useCoreContext)
|
||||||
glEnable(GL_NORMALIZE);
|
glEnable(GL_NORMALIZE);
|
||||||
else if (!useCoreContext)
|
else if (!useCoreContext)
|
||||||
glDisable(GL_NORMALIZE);
|
glDisable(GL_NORMALIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3470,9 +3482,11 @@ const wchar_t* COpenGLDriver::getName() const
|
|||||||
//! deletes all dynamic lights there are
|
//! deletes all dynamic lights there are
|
||||||
void COpenGLDriver::deleteAllDynamicLights()
|
void COpenGLDriver::deleteAllDynamicLights()
|
||||||
{
|
{
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
for (s32 i=0; i<MaxLights; ++i)
|
{
|
||||||
glDisable(GL_LIGHT0 + i);
|
for (s32 i=0; i<MaxLights; ++i)
|
||||||
|
glDisable(GL_LIGHT0 + i);
|
||||||
|
}
|
||||||
|
|
||||||
RequestedLights.clear();
|
RequestedLights.clear();
|
||||||
|
|
||||||
@ -3645,8 +3659,8 @@ u32 COpenGLDriver::getMaximalDynamicLightAmount() const
|
|||||||
void COpenGLDriver::setAmbientLight(const SColorf& color)
|
void COpenGLDriver::setAmbientLight(const SColorf& color)
|
||||||
{
|
{
|
||||||
GLfloat data[4] = {color.r, color.g, color.b, color.a};
|
GLfloat data[4] = {color.r, color.g, color.b, color.a};
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, data);
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -3877,42 +3891,42 @@ void COpenGLDriver::setFog(SColor c, E_FOG_TYPE fogType, f32 start,
|
|||||||
{
|
{
|
||||||
CNullDriver::setFog(c, fogType, start, end, density, pixelFog, rangeFog);
|
CNullDriver::setFog(c, fogType, start, end, density, pixelFog, rangeFog);
|
||||||
|
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glFogf(GL_FOG_MODE, GLfloat((fogType==EFT_FOG_LINEAR)? GL_LINEAR : (fogType==EFT_FOG_EXP)?GL_EXP:GL_EXP2));
|
glFogf(GL_FOG_MODE, GLfloat((fogType==EFT_FOG_LINEAR)? GL_LINEAR : (fogType==EFT_FOG_EXP)?GL_EXP:GL_EXP2));
|
||||||
|
|
||||||
#ifdef GL_EXT_fog_coord
|
#ifdef GL_EXT_fog_coord
|
||||||
if (FeatureAvailable[IRR_EXT_fog_coord] && !useCoreContext)
|
if (FeatureAvailable[IRR_EXT_fog_coord] && !useCoreContext)
|
||||||
glFogi(GL_FOG_COORDINATE_SOURCE, GL_FRAGMENT_DEPTH);
|
glFogi(GL_FOG_COORDINATE_SOURCE, GL_FRAGMENT_DEPTH);
|
||||||
#endif
|
#endif
|
||||||
#ifdef GL_NV_fog_distance
|
#ifdef GL_NV_fog_distance
|
||||||
if (FeatureAvailable[IRR_NV_fog_distance])
|
if (FeatureAvailable[IRR_NV_fog_distance])
|
||||||
{
|
{
|
||||||
if (rangeFog && !useCoreContext)
|
if (rangeFog && !useCoreContext)
|
||||||
glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV);
|
glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV);
|
||||||
else if (!useCoreContext)
|
else if (!useCoreContext)
|
||||||
glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
|
glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fogType==EFT_FOG_LINEAR)
|
if (fogType==EFT_FOG_LINEAR)
|
||||||
{
|
{
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glFogf(GL_FOG_START, start);
|
glFogf(GL_FOG_START, start);
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glFogf(GL_FOG_END, end);
|
glFogf(GL_FOG_END, end);
|
||||||
}
|
}
|
||||||
else if (!useCoreContext)
|
else if (!useCoreContext)
|
||||||
glFogf(GL_FOG_DENSITY, density);
|
glFogf(GL_FOG_DENSITY, density);
|
||||||
|
|
||||||
if (pixelFog && !useCoreContext)
|
if (pixelFog && !useCoreContext)
|
||||||
glHint(GL_FOG_HINT, GL_NICEST);
|
glHint(GL_FOG_HINT, GL_NICEST);
|
||||||
else if (!useCoreContext)
|
else if (!useCoreContext)
|
||||||
glHint(GL_FOG_HINT, GL_FASTEST);
|
glHint(GL_FOG_HINT, GL_FASTEST);
|
||||||
|
|
||||||
SColorf color(c);
|
SColorf color(c);
|
||||||
GLfloat data[4] = {color.r, color.g, color.b, color.a};
|
GLfloat data[4] = {color.r, color.g, color.b, color.a};
|
||||||
if (!useCoreContext)
|
if (!useCoreContext)
|
||||||
glFogfv(GL_FOG_COLOR, data);
|
glFogfv(GL_FOG_COLOR, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
291
lib/irrlicht/source/Irrlicht/COpenGLNormalMapRenderer.cpp
Normal file
291
lib/irrlicht/source/Irrlicht/COpenGLNormalMapRenderer.cpp
Normal file
@ -0,0 +1,291 @@
|
|||||||
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
||||||
|
// This file is part of the "Irrlicht Engine".
|
||||||
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
||||||
|
|
||||||
|
#include "IrrCompileConfig.h"
|
||||||
|
#ifdef _IRR_COMPILE_WITH_OPENGL_
|
||||||
|
|
||||||
|
#include "COpenGLNormalMapRenderer.h"
|
||||||
|
#include "IGPUProgrammingServices.h"
|
||||||
|
#include "IShaderConstantSetCallBack.h"
|
||||||
|
#include "IVideoDriver.h"
|
||||||
|
#include "os.h"
|
||||||
|
#include "COpenGLDriver.h"
|
||||||
|
|
||||||
|
namespace irr
|
||||||
|
{
|
||||||
|
namespace video
|
||||||
|
{
|
||||||
|
|
||||||
|
// Irrlicht Engine OpenGL render path normal map vertex shader
|
||||||
|
// I guess it could be optimized a lot, because I wrote it in D3D ASM and
|
||||||
|
// transferred it 1:1 to OpenGL
|
||||||
|
const char OPENGL_NORMAL_MAP_VSH[] =
|
||||||
|
"!!ARBvp1.0\n"\
|
||||||
|
"#input\n"\
|
||||||
|
"# 0-3: transposed world matrix;\n"\
|
||||||
|
"#;12: Light01 position \n"\
|
||||||
|
"#;13: x,y,z: Light01 color; .w: 1/LightRadius^2 \n"\
|
||||||
|
"#;14: Light02 position \n"\
|
||||||
|
"#;15: x,y,z: Light02 color; .w: 1/LightRadius^2 \n"\
|
||||||
|
"\n"\
|
||||||
|
"ATTRIB InPos = vertex.position;\n"\
|
||||||
|
"ATTRIB InColor = vertex.color;\n"\
|
||||||
|
"ATTRIB InNormal = vertex.normal;\n"\
|
||||||
|
"ATTRIB InTexCoord = vertex.texcoord[0];\n"\
|
||||||
|
"ATTRIB InTangent = vertex.texcoord[1];\n"\
|
||||||
|
"ATTRIB InBinormal = vertex.texcoord[2];\n"\
|
||||||
|
"\n"\
|
||||||
|
"#output\n"\
|
||||||
|
"OUTPUT OutPos = result.position;\n"\
|
||||||
|
"OUTPUT OutLightColor1 = result.color.primary;\n"\
|
||||||
|
"OUTPUT OutLightColor2 = result.color.secondary;\n"\
|
||||||
|
"OUTPUT OutTexCoord = result.texcoord[0];\n"\
|
||||||
|
"OUTPUT OutLightVector1 = result.texcoord[1];\n"\
|
||||||
|
"OUTPUT OutLightVector2 = result.texcoord[2];\n"\
|
||||||
|
"\n"\
|
||||||
|
"PARAM MVP[4] = { state.matrix.mvp }; # modelViewProjection matrix.\n"\
|
||||||
|
"TEMP Temp;\n"\
|
||||||
|
"TEMP TempColor;\n"\
|
||||||
|
"TEMP TempLightVector1;\n"\
|
||||||
|
"TEMP TempLightVector2;\n"\
|
||||||
|
"TEMP TempTransLightV1;\n"\
|
||||||
|
"TEMP TempTransLightV2;\n"\
|
||||||
|
"\n"\
|
||||||
|
"# transform position to clip space \n"\
|
||||||
|
"DP4 OutPos.x, MVP[0], InPos;\n"\
|
||||||
|
"DP4 OutPos.y, MVP[1], InPos;\n"\
|
||||||
|
"DP4 Temp.z, MVP[2], InPos;\n"\
|
||||||
|
"DP4 OutPos.w, MVP[3], InPos;\n"\
|
||||||
|
"MOV OutPos.z, Temp.z;\n"\
|
||||||
|
"MOV result.fogcoord.x, Temp.z;\n"\
|
||||||
|
"\n"\
|
||||||
|
"# vertex - lightpositions \n"\
|
||||||
|
"SUB TempLightVector1, program.local[12], InPos; \n"\
|
||||||
|
"SUB TempLightVector2, program.local[14], InPos; \n"\
|
||||||
|
"\n"\
|
||||||
|
"# transform the light vector 1 with U, V, W \n"\
|
||||||
|
"DP3 TempTransLightV1.x, InTangent, TempLightVector1; \n"\
|
||||||
|
"DP3 TempTransLightV1.y, InBinormal, TempLightVector1; \n"\
|
||||||
|
"DP3 TempTransLightV1.z, InNormal, TempLightVector1; \n"\
|
||||||
|
"\n"\
|
||||||
|
"# transform the light vector 2 with U, V, W \n"\
|
||||||
|
"DP3 TempTransLightV2.x, InTangent, TempLightVector2; \n"\
|
||||||
|
"DP3 TempTransLightV2.y, InBinormal, TempLightVector2; \n"\
|
||||||
|
"DP3 TempTransLightV2.z, InNormal, TempLightVector2; \n"\
|
||||||
|
"\n"\
|
||||||
|
"# normalize light vector 1 \n"\
|
||||||
|
"DP3 TempTransLightV1.w, TempTransLightV1, TempTransLightV1; \n"\
|
||||||
|
"RSQ TempTransLightV1.w, TempTransLightV1.w; \n"\
|
||||||
|
"MUL TempTransLightV1, TempTransLightV1, TempTransLightV1.w;\n"\
|
||||||
|
"\n"\
|
||||||
|
"# normalize light vector 2 \n"\
|
||||||
|
"DP3 TempTransLightV2.w, TempTransLightV2, TempTransLightV2; \n"\
|
||||||
|
"RSQ TempTransLightV2.w, TempTransLightV2.w; \n"\
|
||||||
|
"MUL TempTransLightV2, TempTransLightV2, TempTransLightV2.w;\n"\
|
||||||
|
"\n"\
|
||||||
|
"\n"\
|
||||||
|
"# move light vectors out\n"\
|
||||||
|
"MAD OutLightVector1, TempTransLightV1, {0.5,0.5,0.5,0.5}, {0.5,0.5,0.5,0.5}; \n"\
|
||||||
|
"MAD OutLightVector2, TempTransLightV2, {0.5,0.5,0.5,0.5}, {0.5,0.5,0.5,0.5}; \n"\
|
||||||
|
"\n"\
|
||||||
|
"# calculate attenuation of light 1\n"\
|
||||||
|
"MOV TempLightVector1.w, {0,0,0,0}; \n"\
|
||||||
|
"DP3 TempLightVector1.x, TempLightVector1, TempLightVector1; \n"\
|
||||||
|
"MUL TempLightVector1.x, TempLightVector1.x, program.local[13].w; \n"\
|
||||||
|
"RSQ TempLightVector1, TempLightVector1.x; \n"\
|
||||||
|
"MUL OutLightColor1, TempLightVector1, program.local[13]; # resulting light color = lightcolor * attenuation \n"\
|
||||||
|
"\n"\
|
||||||
|
"# calculate attenuation of light 2\n"\
|
||||||
|
"MOV TempLightVector2.w, {0,0,0,0}; \n"\
|
||||||
|
"DP3 TempLightVector2.x, TempLightVector2, TempLightVector2; \n"\
|
||||||
|
"MUL TempLightVector2.x, TempLightVector2.x, program.local[15].w; \n"\
|
||||||
|
"RSQ TempLightVector2, TempLightVector2.x; \n"\
|
||||||
|
"MUL OutLightColor2, TempLightVector2, program.local[15]; # resulting light color = lightcolor * attenuation \n"\
|
||||||
|
"\n"\
|
||||||
|
"# move out texture coordinates and original alpha value\n"\
|
||||||
|
"MOV OutTexCoord, InTexCoord; \n"\
|
||||||
|
"MOV OutLightColor1.w, InColor.w; \n"\
|
||||||
|
"\n"\
|
||||||
|
"END\n";
|
||||||
|
|
||||||
|
// Irrlicht Engine OpenGL render path normal map pixel shader
|
||||||
|
// I guess it could be optimized a bit, because I wrote it in D3D ASM and
|
||||||
|
// transfered it 1:1 to OpenGL
|
||||||
|
const char OPENGL_NORMAL_MAP_PSH[] =
|
||||||
|
"!!ARBfp1.0\n"\
|
||||||
|
"#_IRR_FOG_MODE_\n"\
|
||||||
|
"\n"\
|
||||||
|
"#Input\n"\
|
||||||
|
"ATTRIB inTexCoord = fragment.texcoord[0]; \n"\
|
||||||
|
"ATTRIB light1Vector = fragment.texcoord[1]; \n"\
|
||||||
|
"ATTRIB light2Vector = fragment.texcoord[2]; \n"\
|
||||||
|
"ATTRIB light1Color = fragment.color.primary; \n"\
|
||||||
|
"ATTRIB light2Color = fragment.color.secondary; \n"\
|
||||||
|
"\n"\
|
||||||
|
"#Output\n"\
|
||||||
|
"OUTPUT outColor = result.color;\n"\
|
||||||
|
"TEMP temp;\n"\
|
||||||
|
"TEMP temp2;\n"\
|
||||||
|
"TEMP colorMapColor;\n"\
|
||||||
|
"TEMP normalMapColor;\n"\
|
||||||
|
"\n"\
|
||||||
|
"# fetch color and normal map; \n"\
|
||||||
|
"TXP colorMapColor, inTexCoord, texture[0], 2D; \n"\
|
||||||
|
"TXP normalMapColor, inTexCoord, texture[1], 2D; \n"\
|
||||||
|
"\n"\
|
||||||
|
"# calculate color of light1; \n"\
|
||||||
|
"MAD normalMapColor, normalMapColor, {2,2,2,2}, {-1,-1,-1,-1}; \n"\
|
||||||
|
"MAD temp, light1Vector, {2,2,2,2}, {-1,-1,-1,-1}; \n"\
|
||||||
|
"DP3_SAT temp, normalMapColor, temp; \n"\
|
||||||
|
"MUL temp, light1Color, temp; \n"\
|
||||||
|
"\n"\
|
||||||
|
"# calculate color of light2; \n"\
|
||||||
|
"MAD temp2, light2Vector, {2,2,2,2}, {-1,-1,-1,-1}; \n"\
|
||||||
|
"DP3_SAT temp2, normalMapColor, temp2; \n"\
|
||||||
|
"MAD temp, light2Color, temp2, temp; \n"\
|
||||||
|
"\n"\
|
||||||
|
"# luminance * base color; \n"\
|
||||||
|
"MUL outColor, temp, colorMapColor; \n"\
|
||||||
|
"MOV outColor.a, light1Color.a; #write interpolated vertex alpha value\n"\
|
||||||
|
"\n"\
|
||||||
|
"END\n";
|
||||||
|
|
||||||
|
//! Constructor
|
||||||
|
COpenGLNormalMapRenderer::COpenGLNormalMapRenderer(video::COpenGLDriver* driver,
|
||||||
|
s32& outMaterialTypeNr, IMaterialRenderer* baseMaterial)
|
||||||
|
: COpenGLShaderMaterialRenderer(driver, 0, baseMaterial), CompiledShaders(true)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
setDebugName("COpenGLNormalMapRenderer");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// set this as callback. We could have done this in
|
||||||
|
// the initialization list, but some compilers don't like it.
|
||||||
|
|
||||||
|
CallBack = this;
|
||||||
|
|
||||||
|
// basically, this thing simply compiles the hardcoded shaders if the
|
||||||
|
// hardware is able to do them, otherwise it maps to the base material
|
||||||
|
|
||||||
|
if (!driver->queryFeature(video::EVDF_ARB_FRAGMENT_PROGRAM_1) ||
|
||||||
|
!driver->queryFeature(video::EVDF_ARB_VERTEX_PROGRAM_1))
|
||||||
|
{
|
||||||
|
// this hardware is not able to do shaders. Fall back to
|
||||||
|
// base material.
|
||||||
|
outMaterialTypeNr = driver->addMaterialRenderer(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if already compiled normal map shaders are there.
|
||||||
|
|
||||||
|
video::IMaterialRenderer* renderer = driver->getMaterialRenderer(EMT_NORMAL_MAP_SOLID);
|
||||||
|
|
||||||
|
if (renderer)
|
||||||
|
{
|
||||||
|
// use the already compiled shaders
|
||||||
|
video::COpenGLNormalMapRenderer* nmr = reinterpret_cast<video::COpenGLNormalMapRenderer*>(renderer);
|
||||||
|
CompiledShaders = false;
|
||||||
|
|
||||||
|
VertexShader = nmr->VertexShader;
|
||||||
|
PixelShader = nmr->PixelShader;
|
||||||
|
|
||||||
|
outMaterialTypeNr = driver->addMaterialRenderer(this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// compile shaders on our own
|
||||||
|
init(outMaterialTypeNr, OPENGL_NORMAL_MAP_VSH, OPENGL_NORMAL_MAP_PSH, EVT_TANGENTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback if compilation has failed
|
||||||
|
if (-1==outMaterialTypeNr)
|
||||||
|
outMaterialTypeNr = driver->addMaterialRenderer(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Destructor
|
||||||
|
COpenGLNormalMapRenderer::~COpenGLNormalMapRenderer()
|
||||||
|
{
|
||||||
|
if (CallBack == this)
|
||||||
|
CallBack = 0;
|
||||||
|
|
||||||
|
if (!CompiledShaders)
|
||||||
|
{
|
||||||
|
// prevent this from deleting shaders we did not create
|
||||||
|
VertexShader = 0;
|
||||||
|
PixelShader.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Returns the render capability of the material.
|
||||||
|
s32 COpenGLNormalMapRenderer::getRenderCapability() const
|
||||||
|
{
|
||||||
|
if (Driver->queryFeature(video::EVDF_ARB_FRAGMENT_PROGRAM_1) &&
|
||||||
|
Driver->queryFeature(video::EVDF_ARB_VERTEX_PROGRAM_1))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Called by the engine when the vertex and/or pixel shader constants for an
|
||||||
|
//! material renderer should be set.
|
||||||
|
void COpenGLNormalMapRenderer::OnSetConstants(IMaterialRendererServices* services, s32 userData)
|
||||||
|
{
|
||||||
|
video::IVideoDriver* driver = services->getVideoDriver();
|
||||||
|
|
||||||
|
// set transposed world matrix
|
||||||
|
const core::matrix4& tWorld = driver->getTransform(video::ETS_WORLD).getTransposed();
|
||||||
|
services->setVertexShaderConstant(tWorld.pointer(), 0, 4);
|
||||||
|
|
||||||
|
// set transposed worldViewProj matrix
|
||||||
|
core::matrix4 worldViewProj(driver->getTransform(video::ETS_PROJECTION));
|
||||||
|
worldViewProj *= driver->getTransform(video::ETS_VIEW);
|
||||||
|
worldViewProj *= driver->getTransform(video::ETS_WORLD);
|
||||||
|
core::matrix4 tr(worldViewProj.getTransposed());
|
||||||
|
services->setVertexShaderConstant(tr.pointer(), 8, 4);
|
||||||
|
|
||||||
|
// here we fetch the fixed function lights from the driver
|
||||||
|
// and set them as constants
|
||||||
|
|
||||||
|
u32 cnt = driver->getDynamicLightCount();
|
||||||
|
|
||||||
|
// Load the inverse world matrix.
|
||||||
|
core::matrix4 invWorldMat;
|
||||||
|
driver->getTransform(video::ETS_WORLD).getInverse(invWorldMat);
|
||||||
|
|
||||||
|
for (u32 i=0; i<2; ++i)
|
||||||
|
{
|
||||||
|
video::SLight light;
|
||||||
|
|
||||||
|
if (i<cnt)
|
||||||
|
light = driver->getDynamicLight(i);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
light.DiffuseColor.set(0,0,0); // make light dark
|
||||||
|
light.Radius = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
light.DiffuseColor.a = 1.0f/(light.Radius*light.Radius); // set attenuation
|
||||||
|
|
||||||
|
// Transform the light by the inverse world matrix to get it into object space.
|
||||||
|
invWorldMat.transformVect(light.Position);
|
||||||
|
|
||||||
|
services->setVertexShaderConstant(
|
||||||
|
reinterpret_cast<const f32*>(&light.Position), 12+(i*2), 1);
|
||||||
|
|
||||||
|
services->setVertexShaderConstant(
|
||||||
|
reinterpret_cast<const f32*>(&light.DiffuseColor), 13+(i*2), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // end namespace video
|
||||||
|
} // end namespace irr
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
49
lib/irrlicht/source/Irrlicht/COpenGLNormalMapRenderer.h
Normal file
49
lib/irrlicht/source/Irrlicht/COpenGLNormalMapRenderer.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
||||||
|
// This file is part of the "Irrlicht Engine".
|
||||||
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
||||||
|
|
||||||
|
#ifndef __C_OPENGL_NORMAL_MAP_RENDERER_H_INCLUDED__
|
||||||
|
#define __C_OPENGL_NORMAL_MAP_RENDERER_H_INCLUDED__
|
||||||
|
|
||||||
|
#include "IrrCompileConfig.h"
|
||||||
|
#ifdef _IRR_COMPILE_WITH_OPENGL_
|
||||||
|
|
||||||
|
#include "COpenGLShaderMaterialRenderer.h"
|
||||||
|
#include "IShaderConstantSetCallBack.h"
|
||||||
|
|
||||||
|
namespace irr
|
||||||
|
{
|
||||||
|
namespace video
|
||||||
|
{
|
||||||
|
|
||||||
|
//! Class for rendering normal maps with OpenGL
|
||||||
|
class COpenGLNormalMapRenderer : public COpenGLShaderMaterialRenderer, public IShaderConstantSetCallBack
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Constructor
|
||||||
|
COpenGLNormalMapRenderer(video::COpenGLDriver* driver,
|
||||||
|
s32& outMaterialTypeNr, IMaterialRenderer* baseMaterial);
|
||||||
|
|
||||||
|
//! Destructor
|
||||||
|
~COpenGLNormalMapRenderer();
|
||||||
|
|
||||||
|
//! Called by the engine when the vertex and/or pixel shader constants for an
|
||||||
|
//! material renderer should be set.
|
||||||
|
virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData);
|
||||||
|
|
||||||
|
//! Returns the render capability of the material.
|
||||||
|
virtual s32 getRenderCapability() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
bool CompiledShaders;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // end namespace video
|
||||||
|
} // end namespace irr
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
@ -521,14 +521,6 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
|
|||||||
m_node->setMaterialTexture(0, material->getTexture());
|
m_node->setMaterialTexture(0, material->getTexture());
|
||||||
|
|
||||||
mat0.ZWriteEnable = !material->isTransparent(); // disable z-buffer writes if material is transparent
|
mat0.ZWriteEnable = !material->isTransparent(); // disable z-buffer writes if material is transparent
|
||||||
|
|
||||||
// fallback for old render engine
|
|
||||||
if (material->getShaderType() == Material::SHADERTYPE_ADDITIVE)
|
|
||||||
mat0.MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
|
|
||||||
else if (material->getShaderType() == Material::SHADERTYPE_ALPHA_BLEND)
|
|
||||||
mat0.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
|
||||||
else if (material->getShaderType() == Material::SHADERTYPE_ALPHA_TEST)
|
|
||||||
mat0.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user