Port to "unlit" lighting model
parent
b781d7a7c8
commit
daf34b5656
|
@ -10,12 +10,15 @@
|
|||
#include <cassert>
|
||||
#include "asterismrenderer.h"
|
||||
#include "render.h"
|
||||
#include "vecgl.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
AsterismRenderer::AsterismRenderer(const AsterismList *asterisms) :
|
||||
m_asterisms(asterisms)
|
||||
{
|
||||
m_shadprop.texUsage = ShaderProperties::VertexColors;
|
||||
m_shadprop.lightModel = ShaderProperties::UnlitModel;
|
||||
}
|
||||
|
||||
bool AsterismRenderer::sameAsterisms(const AsterismList *asterisms) const
|
||||
|
@ -47,7 +50,7 @@ void AsterismRenderer::render(const Renderer &renderer, const Color &defaultColo
|
|||
}
|
||||
|
||||
prog->use();
|
||||
prog->color = defaultColor.toVector4();
|
||||
glColor(defaultColor);
|
||||
m_vo.draw(GL_LINES, m_vtxTotal);
|
||||
|
||||
assert(m_asterisms->size() == m_vtxCount.size());
|
||||
|
@ -63,7 +66,7 @@ void AsterismRenderer::render(const Renderer &renderer, const Color &defaultColo
|
|||
continue;
|
||||
}
|
||||
|
||||
prog->color = Color(ast->getOverrideColor(), opacity).toVector4();
|
||||
glColor(ast->getOverrideColor(), opacity);
|
||||
m_vo.draw(GL_LINES, m_vtxCount[i], offset);
|
||||
offset += m_vtxCount[i];
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class AsterismRenderer
|
|||
GLfloat* prepare();
|
||||
|
||||
celgl::VertexObject m_vo { GL_ARRAY_BUFFER, 0, GL_STATIC_DRAW };
|
||||
ShaderProperties m_shadprop { ShaderProperties::UniformColor };
|
||||
ShaderProperties m_shadprop;
|
||||
std::vector<GLsizei> m_vtxCount;
|
||||
|
||||
const AsterismList *m_asterisms { nullptr };
|
||||
|
|
|
@ -220,6 +220,8 @@ ArrowReferenceMark::ArrowReferenceMark(const Body& _body) :
|
|||
opacity(1.0f)
|
||||
#endif
|
||||
{
|
||||
shadprop.texUsage = ShaderProperties::VertexColors;
|
||||
shadprop.lightModel = ShaderProperties::UnlitModel;
|
||||
}
|
||||
|
||||
|
||||
|
@ -281,7 +283,7 @@ ArrowReferenceMark::render(Renderer* renderer,
|
|||
if (prog == nullptr)
|
||||
return;
|
||||
prog->use();
|
||||
prog->color = Color(color, opacity).toVector4();
|
||||
glColor(color, opacity);
|
||||
|
||||
auto &vo = renderer->getVertexObject(VOType::AxisArrow, GL_ARRAY_BUFFER, 0, GL_STATIC_DRAW);
|
||||
RenderArrow(vo);
|
||||
|
@ -306,6 +308,8 @@ AxesReferenceMark::AxesReferenceMark(const Body& _body) :
|
|||
opacity(1.0f)
|
||||
#endif
|
||||
{
|
||||
shadprop.texUsage = ShaderProperties::VertexColors;
|
||||
shadprop.lightModel = ShaderProperties::UnlitModel;
|
||||
}
|
||||
|
||||
|
||||
|
@ -388,7 +392,7 @@ AxesReferenceMark::render(Renderer* renderer,
|
|||
// x-axis
|
||||
glPushMatrix();
|
||||
glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
|
||||
prog->color = { 1.0f, 0.0f, 0.0f, opacity };
|
||||
glColor4f(1.0f, 0.0f, 0.0f, opacity);
|
||||
RenderArrow(vo);
|
||||
glTranslatef(0.1f, 0.0f, 0.75f);
|
||||
glScalef(labelScale, labelScale, labelScale);
|
||||
|
@ -398,7 +402,7 @@ AxesReferenceMark::render(Renderer* renderer,
|
|||
// y-axis
|
||||
glPushMatrix();
|
||||
glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
|
||||
prog->color = { 0.0f, 1.0f, 0.0f, opacity };
|
||||
glColor4f(0.0f, 1.0f, 0.0f, opacity);
|
||||
RenderArrow(vo);
|
||||
glTranslatef(0.1f, 0.0f, 0.75f);
|
||||
glScalef(labelScale, labelScale, labelScale);
|
||||
|
@ -408,7 +412,7 @@ AxesReferenceMark::render(Renderer* renderer,
|
|||
// z-axis
|
||||
glPushMatrix();
|
||||
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
|
||||
prog->color = { 0.0f, 0.0f, 1.0f, opacity };
|
||||
glColor4f(0.0f, 0.0f, 1.0f, opacity);
|
||||
RenderArrow(vo);
|
||||
glTranslatef(0.1f, 0.0f, 0.75f);
|
||||
glScalef(labelScale, labelScale, labelScale);
|
||||
|
|
|
@ -49,7 +49,7 @@ class ArrowReferenceMark : public ReferenceMark
|
|||
float size;
|
||||
Color color;
|
||||
float opacity;
|
||||
ShaderProperties shadprop{ ShaderProperties::UniformColor };
|
||||
ShaderProperties shadprop;
|
||||
};
|
||||
|
||||
|
||||
|
@ -80,7 +80,7 @@ class AxesReferenceMark : public ReferenceMark
|
|||
private:
|
||||
float size;
|
||||
float opacity;
|
||||
ShaderProperties shadprop{ ShaderProperties::UniformColor };
|
||||
ShaderProperties shadprop;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <celutil/color.h>
|
||||
#include "boundariesrenderer.h"
|
||||
#include "render.h"
|
||||
#include "vecgl.h"
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
|
@ -20,6 +21,8 @@ using namespace std;
|
|||
BoundariesRenderer::BoundariesRenderer(const ConstellationBoundaries *boundaries) :
|
||||
m_boundaries(boundaries)
|
||||
{
|
||||
m_shadprop.texUsage = ShaderProperties::VertexColors;
|
||||
m_shadprop.lightModel = ShaderProperties::UnlitModel;
|
||||
}
|
||||
|
||||
bool BoundariesRenderer::sameBoundaries(const ConstellationBoundaries *boundaries) const
|
||||
|
@ -48,7 +51,7 @@ void BoundariesRenderer::render(const Renderer &renderer, const Color &color)
|
|||
}
|
||||
|
||||
prog->use();
|
||||
prog->color = color.toVector4();
|
||||
glColor(color);
|
||||
m_vo.draw(GL_LINES, m_vtxTotal);
|
||||
|
||||
glUseProgram(0);
|
||||
|
|
|
@ -34,7 +34,7 @@ class BoundariesRenderer
|
|||
GLshort* prepare();
|
||||
|
||||
celgl::VertexObject m_vo { GL_ARRAY_BUFFER, 0, GL_STATIC_DRAW };
|
||||
ShaderProperties m_shadprop { ShaderProperties::UniformColor };
|
||||
ShaderProperties m_shadprop;
|
||||
const ConstellationBoundaries *m_boundaries { nullptr };
|
||||
GLsizei m_vtxTotal { 0 };
|
||||
};
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "render.h"
|
||||
#include "vertexobject.h"
|
||||
#include "marker.h"
|
||||
#include "vecgl.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
@ -218,7 +219,10 @@ static void initVO(VertexObject& vo)
|
|||
void Renderer::renderMarker(MarkerRepresentation::Symbol symbol, float size, const Color& color)
|
||||
{
|
||||
assert(shaderManager != nullptr);
|
||||
auto* prog = shaderManager->getShader("marker");
|
||||
ShaderProperties shadprop;
|
||||
shadprop.texUsage = ShaderProperties::VertexColors;
|
||||
shadprop.lightModel = ShaderProperties::UnlitModel;
|
||||
auto* prog = shaderManager->getShader(shadprop);
|
||||
if (prog == nullptr)
|
||||
return;
|
||||
|
||||
|
@ -229,8 +233,8 @@ void Renderer::renderMarker(MarkerRepresentation::Symbol symbol, float size, con
|
|||
|
||||
float s = size / 2.0f;
|
||||
prog->use();
|
||||
prog->vec4Param("color") = color.toVector4();
|
||||
prog->floatParam("s") = s;
|
||||
glColor(color);
|
||||
glScalef(s, s, 0);
|
||||
|
||||
switch (symbol)
|
||||
{
|
||||
|
|
|
@ -91,7 +91,10 @@ PlanetographicGrid::render(Renderer* renderer,
|
|||
float discSizeInPixels,
|
||||
double tdb) const
|
||||
{
|
||||
auto *prog = renderer->getShaderManager().getShader("uniform_color");
|
||||
ShaderProperties shadprop;
|
||||
shadprop.texUsage = ShaderProperties::VertexColors;
|
||||
shadprop.lightModel = ShaderProperties::UnlitModel;
|
||||
auto *prog = renderer->getShaderManager().getShader(shadprop);
|
||||
if (prog == nullptr)
|
||||
return;
|
||||
|
||||
|
@ -150,12 +153,12 @@ PlanetographicGrid::render(Renderer* renderer,
|
|||
|
||||
if (latitude == 0.0f)
|
||||
{
|
||||
prog->vec4Param("color") = Renderer::PlanetEquatorColor.toVector4();
|
||||
glColor(Renderer::PlanetEquatorColor);
|
||||
glLineWidth(2.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
prog->vec4Param("color") = Renderer::PlanetographicGridColor.toVector4();
|
||||
glColor(Renderer::PlanetographicGridColor);
|
||||
}
|
||||
glPushMatrix();
|
||||
glTranslatef(0.0f, (float) std::sin(phi), 0.0f);
|
||||
|
|
|
@ -59,7 +59,10 @@ void PointStarVertexBuffer::startSprites()
|
|||
|
||||
void PointStarVertexBuffer::startPoints()
|
||||
{
|
||||
auto *prog = renderer.getShaderManager().getShader(ShaderProperties::PerVertexColor);
|
||||
ShaderProperties shadprop;
|
||||
shadprop.texUsage = ShaderProperties::VertexColors;
|
||||
shadprop.lightModel = ShaderProperties::UnlitModel;
|
||||
auto *prog = renderer.getShaderManager().getShader(shadprop);
|
||||
if (prog == nullptr)
|
||||
return;
|
||||
prog->use();
|
||||
|
|
|
@ -1071,7 +1071,10 @@ void Renderer::renderOrbit(const OrbitPathListEntry& orbitPath,
|
|||
float nearDist,
|
||||
float farDist)
|
||||
{
|
||||
auto *prog = shaderManager->getShader(ShaderProperties::PerVertexColor);
|
||||
ShaderProperties shadprop;
|
||||
shadprop.texUsage = ShaderProperties::VertexColors;
|
||||
shadprop.lightModel = ShaderProperties::UnlitModel;
|
||||
auto *prog = shaderManager->getShader(shadprop);
|
||||
if (prog == nullptr)
|
||||
return;
|
||||
|
||||
|
@ -1773,9 +1776,16 @@ void renderPoint(const Renderer &renderer,
|
|||
{
|
||||
CelestiaGLProgram *prog;
|
||||
if (useSprite)
|
||||
{
|
||||
prog = renderer.getShaderManager().getShader("star");
|
||||
}
|
||||
else
|
||||
prog = renderer.getShaderManager().getShader(ShaderProperties::PerVertexColor);
|
||||
{
|
||||
ShaderProperties shadprop;
|
||||
shadprop.texUsage = ShaderProperties::VertexColors;
|
||||
shadprop.lightModel = ShaderProperties::UnlitModel;
|
||||
prog = renderer.getShaderManager().getShader(shadprop);
|
||||
}
|
||||
if (prog == nullptr)
|
||||
return;
|
||||
|
||||
|
@ -1943,7 +1953,10 @@ void Renderer::renderEllipsoidAtmosphere(const Atmosphere& atmosphere,
|
|||
if (atmosphere.height == 0.0f)
|
||||
return;
|
||||
|
||||
auto *prog = shaderManager->getShader(ShaderProperties::PerVertexColor);
|
||||
ShaderProperties shadprop;
|
||||
shadprop.texUsage = ShaderProperties::VertexColors;
|
||||
shadprop.lightModel = ShaderProperties::UnlitModel;
|
||||
auto *prog = shaderManager->getShader(shadprop);
|
||||
if (prog == nullptr)
|
||||
return;
|
||||
|
||||
|
@ -2250,18 +2263,14 @@ static void renderCloudsUnlit(const RenderInfo& ri,
|
|||
{
|
||||
ShaderProperties shadprop;
|
||||
shadprop.texUsage = ShaderProperties::DiffuseTexture;
|
||||
shadprop.lightModel = ShaderProperties::UnlitModel;
|
||||
|
||||
// Get a shader for the current rendering configuration
|
||||
auto* prog = r->getShaderManager().getShader(shadprop);
|
||||
if (prog == nullptr)
|
||||
return;
|
||||
prog->use();
|
||||
|
||||
prog->textureOffset = cloudTexOffset;
|
||||
// TODO: introduce a new ShaderProperties light model, so those
|
||||
// assignments are not required
|
||||
prog->ambientColor = Color::White.toVector3();
|
||||
prog->opacity = 1.0f;
|
||||
|
||||
g_lodSphere->render(frustum, ri.pixWidth, &cloudTex, 1);
|
||||
|
||||
|
@ -5264,75 +5273,58 @@ bool Renderer::captureFrame(int x, int y, int w, int h, Renderer::PixelFormat fo
|
|||
|
||||
void Renderer::drawRectangle(const Rect &r)
|
||||
{
|
||||
uint32_t p = r.tex == nullptr ? 0 : ShaderProperties::HasTexture;
|
||||
switch (r.nColors)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
p |= ShaderProperties::UniformColor;
|
||||
break;
|
||||
case 4:
|
||||
p |= ShaderProperties::PerVertexColor;
|
||||
break;
|
||||
default:
|
||||
fmt::fprintf(cerr, "Incorrect number of colors: %i\n", r.nColors);
|
||||
}
|
||||
ShaderProperties shadprop;
|
||||
shadprop.lightModel = ShaderProperties::UnlitModel;
|
||||
|
||||
auto prog = getShaderManager().getShader(ShaderProperties(p));
|
||||
if (r.nColors > 0)
|
||||
shadprop.texUsage |= ShaderProperties::VertexColors;
|
||||
if (r.tex != nullptr)
|
||||
shadprop.texUsage |= ShaderProperties::DiffuseTexture;
|
||||
|
||||
auto *prog = getShaderManager().getShader(shadprop);
|
||||
if (prog == nullptr)
|
||||
return;
|
||||
|
||||
constexpr array<short, 8> texels = {0, 1, 1, 1, 1, 0, 0, 0};
|
||||
array<float, 8> vertices = { r.x, r.y, r.x+r.w, r.y, r.x+r.w, r.y+r.h, r.x, r.y+r.h };
|
||||
|
||||
auto s = static_cast<GLsizeiptr>(memsize(vertices) + memsize(texels) + 4*4*sizeof(GLfloat));
|
||||
auto &vo = getVertexObject(VOType::Rectangle, GL_ARRAY_BUFFER, s, GL_STREAM_DRAW);
|
||||
vo.bindWritable();
|
||||
|
||||
if (!vo.initialized())
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, 0, vertices.data());
|
||||
if (r.tex != nullptr)
|
||||
{
|
||||
vo.allocate();
|
||||
vo.setBufferData(texels.data(), memsize(vertices), memsize(texels));
|
||||
vo.setVertices(2, GL_FLOAT);
|
||||
vo.setTextureCoords(2, GL_SHORT, false, 0, memsize(vertices));
|
||||
vo.setColors(4, GL_FLOAT, false, 0, memsize(vertices) + memsize(texels));
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(2, GL_SHORT, 0, texels.data());
|
||||
r.tex->bind();
|
||||
}
|
||||
|
||||
vo.setBufferData(vertices.data(), 0, memsize(vertices));
|
||||
if (r.nColors == 4)
|
||||
{
|
||||
array<Vector4f, 4> ct;
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
ct[i] = r.colors[i].toVector4();
|
||||
vo.setBufferData(ct.data(), memsize(vertices) + memsize(texels), 4*4*sizeof(GLfloat));
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, 0, r.colors.data());
|
||||
}
|
||||
else if (r.nColors == 1)
|
||||
{
|
||||
glColor(r.colors[0]);
|
||||
}
|
||||
|
||||
prog->use();
|
||||
if (r.tex != nullptr)
|
||||
{
|
||||
r.tex->bind();
|
||||
prog->samplerParam("tex") = 0;
|
||||
}
|
||||
|
||||
if (r.nColors == 1)
|
||||
prog->vec4Param("color") = r.colors[0].toVector4();
|
||||
|
||||
if (r.type != Rect::Type::BorderOnly)
|
||||
{
|
||||
vo.draw(GL_TRIANGLE_FAN, 4);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (r.lw != 1.0f)
|
||||
glLineWidth(r.lw);
|
||||
vo.draw(GL_LINE_LOOP, 4);
|
||||
glDrawArrays(GL_LINE_LOOP, 0, 4);
|
||||
if (r.lw != 1.0f)
|
||||
glLineWidth(1.0f);
|
||||
}
|
||||
|
||||
glUseProgram(0);
|
||||
vo.unbind();
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
void Renderer::setRenderRegion(int x, int y, int width, int height, bool withScissor)
|
||||
|
@ -5450,7 +5442,7 @@ Renderer::setShadowMapSize(unsigned size)
|
|||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &t);
|
||||
m_shadowMapSize = clamp(size, 0u, static_cast<unsigned>(t));
|
||||
if (m_shadowFBO != nullptr && m_shadowMapSize == m_shadowFBO->width())
|
||||
return;
|
||||
return;
|
||||
if (m_shadowMapSize == 0)
|
||||
m_shadowFBO = nullptr;
|
||||
else
|
||||
|
|
|
@ -390,7 +390,10 @@ SkyGrid::render(Renderer& renderer,
|
|||
int windowWidth,
|
||||
int windowHeight)
|
||||
{
|
||||
auto *prog = renderer.getShaderManager().getShader("uniform_color");
|
||||
ShaderProperties shadprop;
|
||||
shadprop.texUsage = ShaderProperties::VertexColors;
|
||||
shadprop.lightModel = ShaderProperties::UnlitModel;
|
||||
auto *prog = renderer.getShaderManager().getShader(shadprop);
|
||||
if (prog == nullptr)
|
||||
return;
|
||||
|
||||
|
@ -544,7 +547,7 @@ SkyGrid::render(Renderer& renderer,
|
|||
Quaternionf orientationf = q.cast<float>();
|
||||
|
||||
prog->use();
|
||||
prog->vec4Param("color") = m_lineColor.toVector4();
|
||||
glColor(m_lineColor);
|
||||
|
||||
// Render the parallels
|
||||
glPushMatrix();
|
||||
|
|
|
@ -92,7 +92,10 @@ renderTerminator(Renderer* renderer, const vector<Vector3f>& pos, const Vector4f
|
|||
* Because of this we make calculations on a CPU and stream results to GPU.
|
||||
*/
|
||||
|
||||
auto *prog = renderer->getShaderManager().getShader("uniform_color");
|
||||
ShaderProperties shadprop;
|
||||
shadprop.texUsage = ShaderProperties::VertexColors;
|
||||
shadprop.lightModel = ShaderProperties::UnlitModel;
|
||||
auto *prog = renderer->getShaderManager().getShader(shadprop);
|
||||
if (prog == nullptr)
|
||||
return;
|
||||
|
||||
|
@ -109,10 +112,7 @@ renderTerminator(Renderer* renderer, const vector<Vector3f>& pos, const Vector4f
|
|||
vo.setBufferData(pos.data(), 0, pos.size() * sizeof(Vector3f));
|
||||
|
||||
prog->use();
|
||||
prog->vec4Param("color") = color;
|
||||
Eigen::Matrix4f m = Eigen::Matrix4f::Identity();
|
||||
m.topLeftCorner(3, 3) = qf.conjugate().toRotationMatrix();
|
||||
prog->mat4Param("rotate") = m;
|
||||
glColor(color);
|
||||
|
||||
vo.draw(GL_LINE_LOOP, pos.size());
|
||||
|
||||
|
|
Loading…
Reference in New Issue