This commit is contained in:
Marianne Gagnon 2014-05-07 19:35:35 -04:00
commit e1a5f8254b
8 changed files with 99 additions and 25 deletions

View File

@ -14,16 +14,26 @@ in vec3 Scale;
in vec3 Position; in vec3 Position;
in vec2 Texcoord; in vec2 Texcoord;
#ifdef VSLayer
out vec2 uv;
#else
out vec2 tc; out vec2 tc;
out int layerId; out int layerId;
#endif
mat4 getWorldMatrix(vec3 translation, vec3 rotation, vec3 scale); mat4 getWorldMatrix(vec3 translation, vec3 rotation, vec3 scale);
mat4 getInverseWorldMatrix(vec3 translation, vec3 rotation, vec3 scale); mat4 getInverseWorldMatrix(vec3 translation, vec3 rotation, vec3 scale);
void main(void) void main(void)
{ {
layerId = gl_InstanceID & 3;
mat4 ModelMatrix = getWorldMatrix(Origin, Orientation, Scale); mat4 ModelMatrix = getWorldMatrix(Origin, Orientation, Scale);
#ifdef VSLayer
gl_Layer = gl_InstanceID & 3;
gl_Position = ShadowViewProjMatrixes[gl_Layer] * ModelMatrix * vec4(Position, 1.);
uv = Texcoord;
#else
layerId = gl_InstanceID & 3;
gl_Position = ShadowViewProjMatrixes[layerId] * ModelMatrix * vec4(Position, 1.); gl_Position = ShadowViewProjMatrixes[layerId] * ModelMatrix * vec4(Position, 1.);
tc = Texcoord; tc = Texcoord;
#endif
} }

View File

@ -1,5 +1,5 @@
layout(triangles) in; layout(triangles) in;
layout(triangle_strip, max_vertices=4) out; layout(triangle_strip, max_vertices=3) out;
in vec2 tc[3]; in vec2 tc[3];
in int layerId[3]; in int layerId[3];

View File

@ -12,12 +12,22 @@ uniform mat4 ModelMatrix;
in vec3 Position; in vec3 Position;
in vec2 Texcoord; in vec2 Texcoord;
#ifdef VSLayer
out vec2 uv;
#else
out vec2 tc; out vec2 tc;
out int layerId; out int layerId;
#endif
void main(void) void main(void)
{ {
#ifdef VSLayer
gl_Layer = gl_InstanceID & 3;
uv = Texcoord;
gl_Position = ShadowViewProjMatrixes[gl_Layer] * ModelMatrix * vec4(Position, 1.);
#else
layerId = gl_InstanceID & 3; layerId = gl_InstanceID & 3;
tc = Texcoord; tc = Texcoord;
gl_Position = ShadowViewProjMatrixes[layerId] * ModelMatrix * vec4(Position, 1.); gl_Position = ShadowViewProjMatrixes[layerId] * ModelMatrix * vec4(Position, 1.);
#endif
} }

View File

@ -237,6 +237,8 @@ GLuint LoadShader(const char * file, unsigned type)
Code += "//" + std::string(file) + "\n"; Code += "//" + std::string(file) + "\n";
if (UserConfigParams::m_ubo_disabled) if (UserConfigParams::m_ubo_disabled)
Code += "#define UBO_DISABLED\n"; Code += "#define UBO_DISABLED\n";
if (irr_driver->hasVSLayerExtension())
Code += "#define VSLayer\n";
if (Stream.is_open()) if (Stream.is_open())
{ {
std::string Line = ""; std::string Line = "";

View File

@ -441,6 +441,14 @@ void IrrDriver::initDevice()
Log::info("IrrDriver", "OPENGL VERSION IS %d.%d", GLMajorVersion, GLMinorVersion); Log::info("IrrDriver", "OPENGL VERSION IS %d.%d", GLMajorVersion, GLMinorVersion);
m_glsl = (GLMajorVersion > 3 || (GLMajorVersion == 3 && GLMinorVersion >= 1)); m_glsl = (GLMajorVersion > 3 || (GLMajorVersion == 3 && GLMinorVersion >= 1));
// Parse extensions
hasVSLayer = false;
const GLubyte *extensions = glGetString(GL_EXTENSIONS);
if (strstr((const char*)extensions, "GL_AMD_vertex_shader_layer") != NULL)
hasVSLayer = true;
// This remaps the window, so it has to be done before the clear to avoid flicker // This remaps the window, so it has to be done before the clear to avoid flicker
m_device->setResizable(false); m_device->setResizable(false);

View File

@ -92,6 +92,7 @@ class IrrDriver : public IEventReceiver, public NoCopy
{ {
private: private:
int GLMajorVersion, GLMinorVersion; int GLMajorVersion, GLMinorVersion;
bool hasVSLayer;
/** The irrlicht device. */ /** The irrlicht device. */
IrrlichtDevice *m_device; IrrlichtDevice *m_device;
/** Irrlicht scene manager. */ /** Irrlicht scene manager. */
@ -171,6 +172,11 @@ public:
return 120; return 120;
} }
bool hasVSLayerExtension() const
{
return hasVSLayer;
}
float getExposure() const float getExposure() const
{ {
return m_exposure; return m_exposure;

View File

@ -1197,7 +1197,7 @@ static void displayCoeff(float *SHCoeff)
} }
// Only for 9 coefficients // Only for 9 coefficients
static void testSH(char *color[6], size_t width, size_t height, static void testSH(unsigned char *color[6], size_t width, size_t height,
float *blueSHCoeff, float *greenSHCoeff, float *redSHCoeff) float *blueSHCoeff, float *greenSHCoeff, float *redSHCoeff)
{ {
float *Y00[6]; float *Y00[6];
@ -1378,9 +1378,9 @@ void IrrDriver::generateSkyboxCubemap()
sh_h = MAX2(sh_h, SphericalHarmonicsTextures[i]->getOriginalSize().Height); sh_h = MAX2(sh_h, SphericalHarmonicsTextures[i]->getOriginalSize().Height);
} }
char *sh_rgba[6]; unsigned char *sh_rgba[6];
for (unsigned i = 0; i < 6; i++) for (unsigned i = 0; i < 6; i++)
sh_rgba[i] = new char[sh_w * sh_h * 4]; sh_rgba[i] = new unsigned char[sh_w * sh_h * 4];
for (unsigned i = 0; i < 6; i++) for (unsigned i = 0; i < 6; i++)
{ {
unsigned idx = texture_permutation[i]; unsigned idx = texture_permutation[i];
@ -1410,10 +1410,10 @@ void IrrDriver::generateSkyboxCubemap()
const video::SColorf& ambientf = irr_driver->getSceneManager()->getAmbientLight(); const video::SColorf& ambientf = irr_driver->getSceneManager()->getAmbientLight();
video::SColor ambient = ambientf.toSColor(); video::SColor ambient = ambientf.toSColor();
char *sh_rgba[6]; unsigned char *sh_rgba[6];
for (unsigned i = 0; i < 6; i++) for (unsigned i = 0; i < 6; i++)
{ {
sh_rgba[i] = new char[sh_w * sh_h * 4]; sh_rgba[i] = new unsigned char[sh_w * sh_h * 4];
for (int j = 0; j < sh_w * sh_h * 4; j+=4) for (int j = 0; j < sh_w * sh_h * 4; j+=4)
{ {

View File

@ -1500,10 +1500,19 @@ namespace MeshShader
attrib_position = -1; attrib_position = -1;
return; return;
} }
Program = LoadProgram( if (irr_driver->hasVSLayerExtension())
GL_VERTEX_SHADER, file_manager->getAsset("shaders/shadow.vert").c_str(), {
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(), Program = LoadProgram(
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/white.frag").c_str()); GL_VERTEX_SHADER, file_manager->getAsset("shaders/shadow.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/white.frag").c_str());
}
else
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/shadow.vert").c_str(),
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/white.frag").c_str());
}
attrib_position = glGetAttribLocation(Program, "Position"); attrib_position = glGetAttribLocation(Program, "Position");
uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
@ -1530,11 +1539,21 @@ namespace MeshShader
attrib_position = -1; attrib_position = -1;
return; return;
} }
Program = LoadProgram( if (irr_driver->hasVSLayerExtension())
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(), {
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanciedshadow.vert").c_str(), Program = LoadProgram(
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(), GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/white.frag").c_str()); GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanciedshadow.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/white.frag").c_str());
}
else
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanciedshadow.vert").c_str(),
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/white.frag").c_str());
}
attrib_position = glGetAttribLocation(Program, "Position"); attrib_position = glGetAttribLocation(Program, "Position");
attrib_origin = glGetAttribLocation(Program, "Origin"); attrib_origin = glGetAttribLocation(Program, "Origin");
attrib_orientation = glGetAttribLocation(Program, "Orientation"); attrib_orientation = glGetAttribLocation(Program, "Orientation");
@ -1562,10 +1581,19 @@ namespace MeshShader
attrib_texcoord = -1; attrib_texcoord = -1;
return; return;
} }
Program = LoadProgram( if (irr_driver->hasVSLayerExtension())
GL_VERTEX_SHADER, file_manager->getAsset("shaders/shadow.vert").c_str(), {
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(), Program = LoadProgram(
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str()); GL_VERTEX_SHADER, file_manager->getAsset("shaders/shadow.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
}
else
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/shadow.vert").c_str(),
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
}
attrib_position = glGetAttribLocation(Program, "Position"); attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
uniform_tex = glGetUniformLocation(Program, "tex"); uniform_tex = glGetUniformLocation(Program, "tex");
@ -1597,11 +1625,21 @@ namespace MeshShader
attrib_texcoord = -1; attrib_texcoord = -1;
return; return;
} }
Program = LoadProgram( if (irr_driver->hasVSLayerExtension())
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(), {
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanciedshadow.vert").c_str(), Program = LoadProgram(
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(), GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str()); GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanciedshadow.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
}
else
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanciedshadow.vert").c_str(),
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
}
attrib_position = glGetAttribLocation(Program, "Position"); attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
attrib_origin = glGetAttribLocation(Program, "Origin"); attrib_origin = glGetAttribLocation(Program, "Origin");