Skip to content

Commit

Permalink
#5893: Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Feb 19, 2022
1 parent 58aa213 commit da6adb2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 107 deletions.
16 changes: 9 additions & 7 deletions install/gl/cubemap_fp.glsl
@@ -1,17 +1,19 @@

// Sampler bound to texture unit 0
uniform samplerCube u_cubemap;
uniform vec3 u_view_origin;

varying vec3 var_dummy;
// The view origin as set by the C++ code
uniform vec3 u_view_origin;

void main()
// The texture coordinate as calculated in the vertex program
varying vec3 var_cubeMapTexCoord;

void main()
{
// Swap Y and Z coordinates
vec3 texcoord = vec3(var_dummy.x, var_dummy.z, var_dummy.y);
vec3 texcoord = vec3(var_cubeMapTexCoord.x, var_cubeMapTexCoord.z, var_cubeMapTexCoord.y);

// Look up the fragment using the cube map sampler
gl_FragColor = texture(u_cubemap, texcoord);

// compute final color
//gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);
}

20 changes: 8 additions & 12 deletions install/gl/cubemap_vp.glsl
@@ -1,21 +1,17 @@

attribute vec4 attr_TexCoord0;
attribute vec3 attr_Tangent;
attribute vec3 attr_Bitangent;
attribute vec3 attr_Normal;
// The view origin as set by the C++ code
uniform vec3 u_view_origin;

uniform vec3 u_view_origin;
// The texture coordinate for this vertex, will be used in the fragment shader
varying vec3 var_cubeMapTexCoord;

varying vec3 var_dummy;

void main()
void main()
{
var_dummy = gl_Vertex.xyz - u_view_origin;
var_cubeMapTexCoord = gl_Vertex.xyz - u_view_origin;

// transform vertex position into homogenous clip-space
gl_Position = ftransform();
// transform vertex position into homogenous clip-space
gl_Position = ftransform();

// Pass through vertex colour
gl_FrontColor = gl_Color;
}

32 changes: 0 additions & 32 deletions radiantcore/rendersystem/backend/OpenGLShaderPass.cpp
Expand Up @@ -216,35 +216,6 @@ void OpenGLShaderPass::applyAllTextures(OpenGLState& current,
}
}

// Set up cube map
void OpenGLShaderPass::setUpCubeMapAndTexGen(OpenGLState& current,
unsigned requiredState,
const Vector3& viewer)
{
#if 0
if (requiredState & RENDER_TEXTURE_CUBEMAP)
{
// Copy cubemap mode enum to current state object
current.cubeMapMode = _glState.cubeMapMode;

// Apply axis transformation (swap Y and Z coordinates)
Matrix4 transform = Matrix4::byRows(
1, 0, 0, 0,
0, 0, 1, 0,
0, 1, 0, 0,
0, 0, 0, 1
);

// Subtract the viewer position
transform.translateBy(-viewer);
// Apply to the texture matrix
glMatrixMode(GL_TEXTURE);
glLoadMatrixd(transform);
glMatrixMode(GL_MODELVIEW);
}
#endif
}

// Apply own state to current state object
void OpenGLShaderPass::applyState(OpenGLState& current,
unsigned int globalStateMask,
Expand Down Expand Up @@ -473,9 +444,6 @@ void OpenGLShaderPass::applyState(OpenGLState& current,
current.setColour(_glState.getColour());
debug::assertNoGlErrors();

// Set up the cubemap and texgen parameters
setUpCubeMapAndTexGen(current, requiredState, viewer);

if(requiredState & RENDER_BLEND
&& (_glState.m_blend_src != current.m_blend_src || _glState.m_blend_dst != current.m_blend_dst))
{
Expand Down
5 changes: 0 additions & 5 deletions radiantcore/rendersystem/backend/OpenGLShaderPass.h
Expand Up @@ -96,11 +96,6 @@ class OpenGLShaderPass
// Apply all OpenGLState textures to texture units
void applyAllTextures(OpenGLState& current, unsigned requiredState);

// Set up the cube map texture matrix if necessary
void setUpCubeMapAndTexGen(OpenGLState& current,
unsigned requiredState,
const Vector3& viewer);

virtual void activateShaderProgram(OpenGLState& current);
virtual void deactivateShaderProgram(OpenGLState& current);

Expand Down
56 changes: 5 additions & 51 deletions radiantcore/rendersystem/backend/glprogram/GLSLCubeMapProgram.cpp
Expand Up @@ -31,31 +31,14 @@ void GLSLCubeMapProgram::create()
glLinkProgram(_programObj);
debug::assertNoGlErrors();

// Set the uniform locations to the correct bound values
// Get a grip of the uniform declared in the fragment shader
_locViewOrigin = glGetUniformLocation(_programObj, "u_view_origin");

glUseProgram(_programObj);
debug::assertNoGlErrors();

GLint samplerLoc;

//samplerLoc = glGetUniformLocation(_programObj, "u_diffusemap");
//glUniform1i(samplerLoc, 0);
//
//samplerLoc = glGetUniformLocation(_programObj, "u_bumpmap");
//glUniform1i(samplerLoc, 1);
//
//samplerLoc = glGetUniformLocation(_programObj, "u_specularmap");
//glUniform1i(samplerLoc, 2);
//
//samplerLoc = glGetUniformLocation(_programObj, "u_attenuationmap_xy");
//glUniform1i(samplerLoc, 3);
//
//samplerLoc = glGetUniformLocation(_programObj, "u_attenuationmap_z");
//glUniform1i(samplerLoc, 4);

// Texture 0 => cubemap
samplerLoc = glGetUniformLocation(_programObj, "u_cubemap");
// Set the cube map sampler to texture unit 0
auto samplerLoc = glGetUniformLocation(_programObj, "u_cubemap");
glUniform1i(samplerLoc, 0);

debug::assertNoGlErrors();
Expand Down Expand Up @@ -88,44 +71,15 @@ void GLSLCubeMapProgram::disable()
debug::assertNoGlErrors();
}

void GLSLCubeMapProgram::applyRenderParams(const Vector3& viewer,
const Matrix4& objectToWorld,
const Params& parms)
void GLSLCubeMapProgram::applyRenderParams(const Vector3& viewer, const Matrix4&, const Params&)
{
#if 0
debug::assertNoGlErrors();

Matrix4 worldToObject(objectToWorld);
worldToObject.invert();

// Calculate the light origin in object space
Vector3 localLight = worldToObject.transformPoint(parms.lightOrigin);

Matrix4 local2light(parms.world2Light);
local2light.multiplyBy(objectToWorld); // local->world->light
#endif
// Set lighting parameters in the shader
// Pass the current viewer origin to the shader
glUniform3f(_locViewOrigin,
static_cast<float>(viewer.x()),
static_cast<float>(viewer.y()),
static_cast<float>(viewer.z())
);
debug::assertNoGlErrors();
#if 0
glUniform1i(_locAmbientLight, parms.isAmbientLight);

// Set vertex colour parameters
glUniform1i(_locInvertVCol, parms.invertVertexColour);

glActiveTexture(GL_TEXTURE3);
glClientActiveTexture(GL_TEXTURE3);

glMatrixMode(GL_TEXTURE);
glLoadMatrixd(local2light);
glMatrixMode(GL_MODELVIEW);

debug::assertNoGlErrors();
#endif
}

}

0 comments on commit da6adb2

Please sign in to comment.