Always use gl_PointSize in shader to set point size
parent
3ece44ff2a
commit
e2b9598f17
|
@ -1,4 +1,4 @@
|
|||
attribute vec3 in_Position;
|
||||
attribute vec2 in_Position;
|
||||
attribute vec2 in_TexCoord0;
|
||||
|
||||
uniform float pointWidth;
|
||||
|
@ -11,6 +11,6 @@ void main(void)
|
|||
{
|
||||
texCoord = in_TexCoord0.st;
|
||||
set_vp(vec4(center, 1.0));
|
||||
vec2 transformed = vec2((in_TexCoord0.x - 0.5) * pointWidth, (in_TexCoord0.y - 0.5) * pointHeight);
|
||||
vec2 transformed = vec2(in_Position.x * pointWidth, in_Position.y * pointHeight);
|
||||
gl_Position.xy += transformed * gl_Position.w;
|
||||
}
|
||||
|
|
|
@ -136,6 +136,7 @@ ModelGeometry::render(RenderContext& rc, double /* t */)
|
|||
for (unsigned int groupIndex = 0; groupIndex < mesh->getGroupCount(); ++groupIndex)
|
||||
{
|
||||
const Mesh::PrimitiveGroup* group = mesh->getGroup(groupIndex);
|
||||
rc.updateShader(mesh->getVertexDescription(), group->prim);
|
||||
|
||||
// Set up the material
|
||||
const Material* material = nullptr;
|
||||
|
|
|
@ -101,7 +101,7 @@ void Nebula::render(const Vector3f& /*offset*/,
|
|||
getOrientation());
|
||||
|
||||
GLSLUnlit_RenderContext rc(renderer, getRadius());
|
||||
rc.setPointScale(2.0f * getRadius() / pixelSize);
|
||||
rc.setPointScale(2.0f * getRadius() / pixelSize * renderer->getScreenDpi() / 96.0f);
|
||||
rc.setProjectionMatrix(m.projection);
|
||||
rc.setModelViewMatrix(&mv);
|
||||
g->render(rc);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "texture.h"
|
||||
#include "pointstarvertexbuffer.h"
|
||||
|
||||
PointStarVertexBuffer* PointStarVertexBuffer::current = nullptr;
|
||||
|
||||
PointStarVertexBuffer::PointStarVertexBuffer(const Renderer& _renderer,
|
||||
unsigned int _capacity) :
|
||||
|
@ -32,80 +33,25 @@ PointStarVertexBuffer::~PointStarVertexBuffer()
|
|||
|
||||
void PointStarVertexBuffer::startSprites()
|
||||
{
|
||||
auto *prog = renderer.getShaderManager().getShader("star");
|
||||
if (prog == nullptr)
|
||||
return;
|
||||
prog->use();
|
||||
prog->setMVPMatrices(renderer.getProjectionMatrix(), renderer.getModelViewMatrix());
|
||||
prog->samplerParam("starTex") = 0;
|
||||
|
||||
unsigned int stride = sizeof(StarVertex);
|
||||
glEnableVertexAttribArray(CelestiaGLProgram::VertexCoordAttributeIndex);
|
||||
glVertexAttribPointer(CelestiaGLProgram::VertexCoordAttributeIndex,
|
||||
3, GL_FLOAT, GL_FALSE,
|
||||
stride, &vertices[0].position);
|
||||
glEnableVertexAttribArray(CelestiaGLProgram::ColorAttributeIndex);
|
||||
glVertexAttribPointer(CelestiaGLProgram::ColorAttributeIndex,
|
||||
4, GL_UNSIGNED_BYTE, GL_TRUE,
|
||||
stride, &vertices[0].color);
|
||||
|
||||
glEnableVertexAttribArray(CelestiaGLProgram::PointSizeAttributeIndex);
|
||||
glVertexAttribPointer(CelestiaGLProgram::PointSizeAttributeIndex,
|
||||
1, GL_FLOAT, GL_FALSE,
|
||||
stride, &vertices[0].size);
|
||||
|
||||
#ifndef GL_ES
|
||||
glEnable(GL_POINT_SPRITE);
|
||||
#endif
|
||||
|
||||
useSprites = true;
|
||||
program = renderer.getShaderManager().getShader("star");
|
||||
pointSizeFromVertex = true;
|
||||
}
|
||||
|
||||
void PointStarVertexBuffer::startPoints()
|
||||
void PointStarVertexBuffer::startBasicPoints()
|
||||
{
|
||||
ShaderProperties shadprop;
|
||||
shadprop.texUsage = ShaderProperties::VertexColors;
|
||||
shadprop.texUsage = ShaderProperties::VertexColors | ShaderProperties::StaticPointSize;
|
||||
shadprop.lightModel = ShaderProperties::UnlitModel;
|
||||
auto *prog = renderer.getShaderManager().getShader(shadprop);
|
||||
if (prog == nullptr)
|
||||
return;
|
||||
prog->use();
|
||||
prog->setMVPMatrices(renderer.getProjectionMatrix(), renderer.getModelViewMatrix());
|
||||
|
||||
unsigned int stride = sizeof(StarVertex);
|
||||
glEnableVertexAttribArray(CelestiaGLProgram::VertexCoordAttributeIndex);
|
||||
glVertexAttribPointer(CelestiaGLProgram::VertexCoordAttributeIndex,
|
||||
3, GL_FLOAT, GL_FALSE,
|
||||
stride, &vertices[0].position);
|
||||
glEnableVertexAttribArray(CelestiaGLProgram::ColorAttributeIndex);
|
||||
glVertexAttribPointer(CelestiaGLProgram::ColorAttributeIndex,
|
||||
4, GL_UNSIGNED_BYTE, GL_TRUE,
|
||||
stride, &vertices[0].color);
|
||||
|
||||
// An option to control the size of the stars would be helpful.
|
||||
// Which size looks best depends a lot on the resolution and the
|
||||
// type of display device.
|
||||
// glPointSize(2.0f);
|
||||
// glEnable(GL_POINT_SMOOTH);
|
||||
useSprites = false;
|
||||
program = renderer.getShaderManager().getShader(shadprop);
|
||||
pointSizeFromVertex = false;
|
||||
}
|
||||
|
||||
void PointStarVertexBuffer::render()
|
||||
{
|
||||
if (nStars != 0)
|
||||
{
|
||||
makeCurrent();
|
||||
unsigned int stride = sizeof(StarVertex);
|
||||
#ifndef GL_ES
|
||||
if (useSprites)
|
||||
{
|
||||
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
glPointSize(1.0f);
|
||||
}
|
||||
#endif
|
||||
glVertexAttribPointer(CelestiaGLProgram::VertexCoordAttributeIndex,
|
||||
3, GL_FLOAT, GL_FALSE,
|
||||
stride, &vertices[0].position);
|
||||
|
@ -113,12 +59,10 @@ void PointStarVertexBuffer::render()
|
|||
4, GL_UNSIGNED_BYTE, GL_TRUE,
|
||||
stride, &vertices[0].color);
|
||||
|
||||
if (useSprites)
|
||||
{
|
||||
if (pointSizeFromVertex)
|
||||
glVertexAttribPointer(CelestiaGLProgram::PointSizeAttributeIndex,
|
||||
1, GL_FLOAT, GL_FALSE,
|
||||
stride, &vertices[0].size);
|
||||
}
|
||||
|
||||
if (texture != nullptr)
|
||||
texture->bind();
|
||||
|
@ -127,22 +71,60 @@ void PointStarVertexBuffer::render()
|
|||
}
|
||||
}
|
||||
|
||||
void PointStarVertexBuffer::makeCurrent()
|
||||
{
|
||||
if (current == this || program == nullptr)
|
||||
return;
|
||||
|
||||
program->use();
|
||||
program->setMVPMatrices(renderer.getProjectionMatrix(), renderer.getModelViewMatrix());
|
||||
if (pointSizeFromVertex)
|
||||
{
|
||||
program->samplerParam("starTex") = 0;
|
||||
glEnableVertexAttribArray(CelestiaGLProgram::PointSizeAttributeIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
program->pointScale = pointScale;
|
||||
glVertexAttrib1f(CelestiaGLProgram::PointSizeAttributeIndex, 1.0f);
|
||||
}
|
||||
|
||||
glEnableVertexAttribArray(CelestiaGLProgram::VertexCoordAttributeIndex);
|
||||
glEnableVertexAttribArray(CelestiaGLProgram::ColorAttributeIndex);
|
||||
current = this;
|
||||
}
|
||||
|
||||
void PointStarVertexBuffer::finish()
|
||||
{
|
||||
render();
|
||||
glDisableVertexAttribArray(CelestiaGLProgram::ColorAttributeIndex);
|
||||
glDisableVertexAttribArray(CelestiaGLProgram::VertexCoordAttributeIndex);
|
||||
|
||||
if (useSprites)
|
||||
{
|
||||
if (pointSizeFromVertex)
|
||||
glDisableVertexAttribArray(CelestiaGLProgram::PointSizeAttributeIndex);
|
||||
}
|
||||
|
||||
void PointStarVertexBuffer::enable()
|
||||
{
|
||||
#ifndef GL_ES
|
||||
glDisable(GL_POINT_SPRITE);
|
||||
glEnable(GL_POINT_SPRITE);
|
||||
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PointStarVertexBuffer::disable()
|
||||
{
|
||||
#ifndef GL_ES
|
||||
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
glDisable(GL_POINT_SPRITE);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void PointStarVertexBuffer::setTexture(Texture* _texture)
|
||||
{
|
||||
texture = _texture;
|
||||
texture = _texture;
|
||||
}
|
||||
|
||||
void PointStarVertexBuffer::setPointScale(float pointSize)
|
||||
{
|
||||
pointScale = pointSize;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
class Color;
|
||||
class Renderer;
|
||||
class Texture;
|
||||
class CelestiaGLProgram;
|
||||
|
||||
// PointStarVertexBuffer is used when hardware supports point sprites.
|
||||
class PointStarVertexBuffer
|
||||
|
@ -30,12 +31,16 @@ public:
|
|||
PointStarVertexBuffer& operator=(const PointStarVertexBuffer&) = delete;
|
||||
PointStarVertexBuffer& operator=(PointStarVertexBuffer&&) = delete;
|
||||
|
||||
void startPoints();
|
||||
void startBasicPoints();
|
||||
void startSprites();
|
||||
void render();
|
||||
void finish();
|
||||
inline void addStar(const Eigen::Vector3f& pos, const Color&, float);
|
||||
void setTexture(Texture* /*_texture*/);
|
||||
void setPointScale(float);
|
||||
|
||||
static void enable();
|
||||
static void disable();
|
||||
|
||||
private:
|
||||
struct StarVertex
|
||||
|
@ -49,10 +54,16 @@ private:
|
|||
const Renderer& renderer;
|
||||
capacity_t capacity;
|
||||
|
||||
capacity_t nStars { 0 };
|
||||
StarVertex* vertices { nullptr };
|
||||
Texture* texture { nullptr };
|
||||
bool useSprites { false };
|
||||
capacity_t nStars { 0 };
|
||||
StarVertex* vertices { nullptr };
|
||||
Texture* texture { nullptr };
|
||||
bool pointSizeFromVertex { false };
|
||||
float pointScale { 1.0f };
|
||||
CelestiaGLProgram* program { nullptr };
|
||||
|
||||
static PointStarVertexBuffer* current;
|
||||
|
||||
void makeCurrent();
|
||||
};
|
||||
|
||||
inline void PointStarVertexBuffer::addStar(const Eigen::Vector3f& pos,
|
||||
|
|
|
@ -162,8 +162,10 @@ RenderContext::drawGroup(const Mesh::PrimitiveGroup& group)
|
|||
return;
|
||||
}
|
||||
|
||||
if (group.prim == Mesh::SpriteList)
|
||||
if (group.prim == Mesh::SpriteList || group.prim == Mesh::PointList)
|
||||
{
|
||||
if (group.prim == Mesh::PointList)
|
||||
glVertexAttrib1f(CelestiaGLProgram::PointSizeAttributeIndex, 1.0f);
|
||||
#ifndef GL_ES
|
||||
glEnable(GL_POINT_SPRITE);
|
||||
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
|
@ -176,7 +178,7 @@ RenderContext::drawGroup(const Mesh::PrimitiveGroup& group)
|
|||
GL_UNSIGNED_INT,
|
||||
group.indices);
|
||||
#ifndef GL_ES
|
||||
if (group.prim == Mesh::SpriteList)
|
||||
if (group.prim == Mesh::SpriteList || group.prim == Mesh::PointList)
|
||||
{
|
||||
glDisable(GL_POINT_SPRITE);
|
||||
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
|
@ -191,7 +193,11 @@ RenderContext::setVertexArrays(const Mesh::VertexDescription& desc,
|
|||
{
|
||||
setStandardVertexArrays(desc, vertexData);
|
||||
setExtendedVertexArrays(desc, vertexData);
|
||||
}
|
||||
|
||||
void
|
||||
RenderContext::updateShader(const cmod::Mesh::VertexDescription& desc, Mesh::PrimitiveGroupType primType)
|
||||
{
|
||||
// Normally, the shader that will be used depends only on the material.
|
||||
// But the presence of point size and normals can also affect the
|
||||
// shader, so force an update of the material if those attributes appear
|
||||
|
@ -200,13 +206,16 @@ RenderContext::setVertexArrays(const Mesh::VertexDescription& desc,
|
|||
bool useNormalsNow = (desc.getAttribute(Mesh::Normal).format == Mesh::Float3);
|
||||
bool useColorsNow = (desc.getAttribute(Mesh::Color0).format != Mesh::InvalidFormat);
|
||||
bool useTexCoordsNow = (desc.getAttribute(Mesh::Texture0).format != Mesh::InvalidFormat);
|
||||
bool useStaticPointSizeNow = primType == Mesh::PointList;
|
||||
|
||||
if (usePointSizeNow != usePointSize ||
|
||||
useNormalsNow != useNormals ||
|
||||
useColorsNow != useColors ||
|
||||
useTexCoordsNow != useTexCoords)
|
||||
if (usePointSizeNow != usePointSize ||
|
||||
useStaticPointSizeNow != useStaticPointSize ||
|
||||
useNormalsNow != useNormals ||
|
||||
useColorsNow != useColors ||
|
||||
useTexCoordsNow != useTexCoords)
|
||||
{
|
||||
usePointSize = usePointSizeNow;
|
||||
useStaticPointSize = useStaticPointSizeNow;
|
||||
useNormals = useNormalsNow;
|
||||
useColors = useColorsNow;
|
||||
useTexCoords = useTexCoordsNow;
|
||||
|
@ -537,6 +546,9 @@ GLSL_RenderContext::makeCurrent(const Material& m)
|
|||
|
||||
if (usePointSize)
|
||||
shaderProps.texUsage |= ShaderProperties::PointSprite;
|
||||
else if (useStaticPointSize)
|
||||
shaderProps.texUsage |= ShaderProperties::StaticPointSize;
|
||||
|
||||
if (useColors)
|
||||
shaderProps.texUsage |= ShaderProperties::VertexColors;
|
||||
|
||||
|
@ -615,10 +627,14 @@ GLSL_RenderContext::makeCurrent(const Material& m)
|
|||
disableDepthWriteOnBlend = false;
|
||||
}
|
||||
|
||||
if ((shaderProps.texUsage & ShaderProperties::PointSprite) != 0)
|
||||
if (usePointSize)
|
||||
{
|
||||
prog->pointScale = getPointScale();
|
||||
}
|
||||
else if (useStaticPointSize)
|
||||
{
|
||||
prog->pointScale = renderer->getScreenDpi() / 96.0f;
|
||||
}
|
||||
|
||||
// Ring shadow parameters
|
||||
if ((shaderProps.texUsage & ShaderProperties::RingShadowTexture) != 0)
|
||||
|
@ -762,6 +778,9 @@ GLSLUnlit_RenderContext::makeCurrent(const Material& m)
|
|||
|
||||
if (usePointSize)
|
||||
shaderProps.texUsage |= ShaderProperties::PointSprite;
|
||||
else if (useStaticPointSize)
|
||||
shaderProps.texUsage |= ShaderProperties::StaticPointSize;
|
||||
|
||||
if (useColors)
|
||||
shaderProps.texUsage |= ShaderProperties::VertexColors;
|
||||
|
||||
|
@ -787,10 +806,14 @@ GLSLUnlit_RenderContext::makeCurrent(const Material& m)
|
|||
#endif
|
||||
prog->opacity = m.opacity;
|
||||
|
||||
if ((shaderProps.texUsage & ShaderProperties::PointSprite) != 0)
|
||||
if (usePointSize)
|
||||
{
|
||||
prog->pointScale = getPointScale();
|
||||
}
|
||||
else if (useStaticPointSize)
|
||||
{
|
||||
prog->pointScale = renderer->getScreenDpi() / 96.0f;
|
||||
}
|
||||
|
||||
Material::BlendMode newBlendMode = Material::InvalidBlend;
|
||||
if (m.opacity != 1.0f ||
|
||||
|
|
|
@ -29,6 +29,7 @@ class RenderContext
|
|||
virtual void makeCurrent(const cmod::Material&) = 0;
|
||||
virtual void setVertexArrays(const cmod::Mesh::VertexDescription& desc,
|
||||
const void* vertexData);
|
||||
virtual void updateShader(const cmod::Mesh::VertexDescription& desc, cmod::Mesh::PrimitiveGroupType primType);
|
||||
virtual void drawGroup(const cmod::Mesh::PrimitiveGroup& group);
|
||||
|
||||
const cmod::Material* getMaterial() const;
|
||||
|
@ -65,6 +66,7 @@ class RenderContext
|
|||
protected:
|
||||
Renderer* renderer { nullptr };
|
||||
bool usePointSize{ false };
|
||||
bool useStaticPointSize{ false };
|
||||
bool useNormals{ true };
|
||||
bool useColors{ false };
|
||||
bool useTexCoords{ true };
|
||||
|
|
|
@ -1851,15 +1851,14 @@ void renderPoint(const Renderer &renderer,
|
|||
3, GL_FLOAT, GL_FALSE, sizeof(position), position.data());
|
||||
|
||||
glVertexAttrib(CelestiaGLProgram::ColorAttributeIndex, color);
|
||||
glVertexAttrib1f(CelestiaGLProgram::PointSizeAttributeIndex, useSprite ? size : 1.0f);
|
||||
glVertexAttrib1f(CelestiaGLProgram::PointSizeAttributeIndex, useSprite ? size : renderer.getScreenDpi() / 96.0f);
|
||||
|
||||
glDrawArrays(GL_POINTS, 0, 1);
|
||||
|
||||
glDisableVertexAttribArray(CelestiaGLProgram::VertexCoordAttributeIndex);
|
||||
|
||||
#ifndef GL_ES
|
||||
if (useSprite)
|
||||
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
glDisable(GL_POINT_SPRITE);
|
||||
#endif
|
||||
}
|
||||
|
@ -1888,18 +1887,18 @@ void renderLargePoint(Renderer &renderer,
|
|||
if (!vo.initialized())
|
||||
{
|
||||
const float texCoords[] = {
|
||||
// texCoords
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
||||
// offset // texCoords
|
||||
-0.5f, 0.5f, 0.0f, 0.0f,
|
||||
-0.5f, -0.5f, 0.0f, 1.0f,
|
||||
0.5f, -0.5f, 1.0f, 1.0f,
|
||||
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f, 1.0f
|
||||
-0.5f, 0.5f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, 1.0f, 1.0f,
|
||||
0.5f, 0.5f, 1.0f, 0.0f,
|
||||
};
|
||||
vo.allocate(sizeof(texCoords), texCoords);
|
||||
vo.setVertices(3, GL_FLOAT, false, 5 * sizeof(float), 0); // Vertices are useless, but required to set somehow on Mac...
|
||||
vo.setTextureCoords(2, GL_FLOAT, false, 5 * sizeof(float), 3 * sizeof(float));
|
||||
vo.setVertices(2, GL_FLOAT, false, 4 * sizeof(float), 0);
|
||||
vo.setTextureCoords(2, GL_FLOAT, false, 4 * sizeof(float), 2 * sizeof(float));
|
||||
}
|
||||
|
||||
vo.draw(GL_TRIANGLES, 6);
|
||||
|
@ -2772,13 +2771,13 @@ void Renderer::renderObject(const Vector3f& pos,
|
|||
{
|
||||
geometryScale = obj.radius;
|
||||
scaleFactors = obj.radius * obj.semiAxes;
|
||||
ri.pointScale = 2.0f * obj.radius / pixelSize;
|
||||
ri.pointScale = 2.0f * obj.radius / pixelSize * screenDpi / 96.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
geometryScale = obj.geometryScale;
|
||||
scaleFactors = Vector3f::Constant(geometryScale);
|
||||
ri.pointScale = 2.0f * geometryScale / pixelSize;
|
||||
ri.pointScale = 2.0f * geometryScale / pixelSize * screenDpi / 96.0f;
|
||||
}
|
||||
// Apply the modelview transform for the object
|
||||
Affine3f transform = Translation3f(pos) * obj.orientation.conjugate() * Scaling(scaleFactors);
|
||||
|
@ -4599,11 +4598,14 @@ void Renderer::renderPointStars(const StarDatabase& starDB,
|
|||
|
||||
gaussianDiscTex->bind();
|
||||
starRenderer.starVertexBuffer->setTexture(gaussianDiscTex);
|
||||
starRenderer.starVertexBuffer->setPointScale(screenDpi / 96.0f);
|
||||
starRenderer.glareVertexBuffer->setTexture(gaussianGlareTex);
|
||||
starRenderer.glareVertexBuffer->setPointScale(screenDpi / 96.0f);
|
||||
|
||||
PointStarVertexBuffer::enable();
|
||||
starRenderer.glareVertexBuffer->startSprites();
|
||||
if (starStyle == PointStars)
|
||||
starRenderer.starVertexBuffer->startPoints();
|
||||
starRenderer.starVertexBuffer->startBasicPoints();
|
||||
else
|
||||
starRenderer.starVertexBuffer->startSprites();
|
||||
|
||||
|
@ -4628,6 +4630,7 @@ void Renderer::renderPointStars(const StarDatabase& starDB,
|
|||
starRenderer.glareVertexBuffer->render();
|
||||
starRenderer.starVertexBuffer->finish();
|
||||
starRenderer.glareVertexBuffer->finish();
|
||||
PointStarVertexBuffer::disable();
|
||||
|
||||
#ifndef GL_ES
|
||||
if (toggleAA)
|
||||
|
|
|
@ -295,6 +295,12 @@ ShaderProperties::usesTangentSpaceLighting() const
|
|||
}
|
||||
|
||||
|
||||
bool ShaderProperties::usePointSize() const
|
||||
{
|
||||
return (texUsage & (PointSprite | StaticPointSize)) != 0;
|
||||
}
|
||||
|
||||
|
||||
bool operator<(const ShaderProperties& p0, const ShaderProperties& p1)
|
||||
{
|
||||
if (p0.texUsage < p1.texUsage)
|
||||
|
@ -1653,6 +1659,15 @@ TextureCoordDeclarations(const ShaderProperties& props)
|
|||
return source;
|
||||
}
|
||||
|
||||
string
|
||||
PointSizeDeclaration()
|
||||
{
|
||||
string source;
|
||||
source += DeclareVarying("pointFade", Shader_Float);
|
||||
source += DeclareUniform("pointScale", Shader_Float);
|
||||
source += DeclareAttribute("in_PointSize", Shader_Float);
|
||||
return source;
|
||||
}
|
||||
|
||||
string
|
||||
PointSizeCalculation()
|
||||
|
@ -1665,6 +1680,15 @@ PointSizeCalculation()
|
|||
return source;
|
||||
}
|
||||
|
||||
string
|
||||
StaticPointSize()
|
||||
{
|
||||
string source;
|
||||
source += "pointFade = 1.0;\n";
|
||||
source += "gl_PointSize = in_PointSize * pointScale;\n";
|
||||
return source;
|
||||
}
|
||||
|
||||
static string
|
||||
CalculateShadow()
|
||||
{
|
||||
|
@ -1729,12 +1753,8 @@ ShaderManager::buildVertexShader(const ShaderProperties& props)
|
|||
source += ScatteringConstantDeclarations(props);
|
||||
}
|
||||
|
||||
if (props.texUsage & ShaderProperties::PointSprite)
|
||||
{
|
||||
source += DeclareUniform("pointScale", Shader_Float);
|
||||
source += DeclareAttribute("in_PointSize", Shader_Float);
|
||||
source += DeclareVarying("pointFade", Shader_Float);
|
||||
}
|
||||
if (props.usePointSize())
|
||||
source += PointSizeDeclaration();
|
||||
|
||||
if (props.usesTangentSpaceLighting())
|
||||
{
|
||||
|
@ -2048,8 +2068,10 @@ ShaderManager::buildVertexShader(const ShaderProperties& props)
|
|||
source += "position_obj = in_Position.xyz;\n";
|
||||
}
|
||||
|
||||
if ((props.texUsage & ShaderProperties::PointSprite) != 0)
|
||||
if (props.texUsage & ShaderProperties::PointSprite)
|
||||
source += PointSizeCalculation();
|
||||
else if (props.texUsage & ShaderProperties::StaticPointSize)
|
||||
source += StaticPointSize();
|
||||
|
||||
if (props.hasShadowMap())
|
||||
source += "shadowTexCoord0 = ShadowMatrix0 * vec4(in_Position.xyz, 1.0);\n";
|
||||
|
@ -2230,10 +2252,8 @@ ShaderManager::buildFragmentShader(const ShaderProperties& props)
|
|||
source += "varying vec2 " + CloudShadowTexCoord(i) + ";\n";
|
||||
}
|
||||
|
||||
if (props.texUsage & ShaderProperties::PointSprite)
|
||||
{
|
||||
if (props.usePointSize())
|
||||
source += DeclareVarying("pointFade", Shader_Float);
|
||||
}
|
||||
|
||||
if (props.hasShadowMap())
|
||||
{
|
||||
|
@ -2423,7 +2443,7 @@ ShaderManager::buildFragmentShader(const ShaderProperties& props)
|
|||
|
||||
if (props.texUsage & ShaderProperties::DiffuseTexture)
|
||||
{
|
||||
if (props.texUsage & ShaderProperties::PointSprite)
|
||||
if (props.usePointSize())
|
||||
source += "color = texture2D(diffTex, gl_PointCoord);\n";
|
||||
else
|
||||
source += "color = texture2D(diffTex, " + diffTexCoord + ".st);\n";
|
||||
|
@ -2434,7 +2454,7 @@ ShaderManager::buildFragmentShader(const ShaderProperties& props)
|
|||
}
|
||||
|
||||
#if POINT_FADE
|
||||
if (props.texUsage & ShaderProperties::PointSprite)
|
||||
if (props.usePointSize())
|
||||
{
|
||||
source += "color.a *= pointFade;\n";
|
||||
}
|
||||
|
@ -2941,12 +2961,8 @@ ShaderManager::buildEmissiveVertexShader(const ShaderProperties& props)
|
|||
source += string("uniform struct {\n vec3 diffuse;\n} lights[1];\n");
|
||||
#endif
|
||||
|
||||
if (props.texUsage & ShaderProperties::PointSprite)
|
||||
{
|
||||
source += "uniform float pointScale;\n";
|
||||
source += "attribute float in_PointSize;\n";
|
||||
source += "varying float pointFade;\n";
|
||||
}
|
||||
if (props.usePointSize())
|
||||
source += PointSizeDeclaration();
|
||||
|
||||
source += DeclareVarying("v_Color", Shader_Vector4);
|
||||
source += DeclareVarying("v_TexCoord0", Shader_Vector2);
|
||||
|
@ -2962,7 +2978,7 @@ ShaderManager::buildEmissiveVertexShader(const ShaderProperties& props)
|
|||
// Optional texture coordinates (generated automatically for point
|
||||
// sprites.)
|
||||
if ((props.texUsage & ShaderProperties::DiffuseTexture) &&
|
||||
!(props.texUsage & ShaderProperties::PointSprite))
|
||||
!props.usePointSize())
|
||||
{
|
||||
source += " v_TexCoord0.st = " + TexCoord2D(0) + ";\n";
|
||||
}
|
||||
|
@ -2977,8 +2993,10 @@ ShaderManager::buildEmissiveVertexShader(const ShaderProperties& props)
|
|||
source += " v_Color = vec4(" + colorSource + ", opacity);\n";
|
||||
|
||||
// Optional point size
|
||||
if ((props.texUsage & ShaderProperties::PointSprite) != 0)
|
||||
if (props.texUsage & ShaderProperties::PointSprite)
|
||||
source += PointSizeCalculation();
|
||||
else if (props.texUsage & ShaderProperties::StaticPointSize)
|
||||
source += StaticPointSize();
|
||||
|
||||
source += VertexPosition;
|
||||
source += "}\n";
|
||||
|
@ -3002,7 +3020,7 @@ ShaderManager::buildEmissiveFragmentShader(const ShaderProperties& props)
|
|||
source += "uniform sampler2D diffTex;\n";
|
||||
}
|
||||
|
||||
if (props.texUsage & ShaderProperties::PointSprite)
|
||||
if (props.usePointSize())
|
||||
{
|
||||
source += "varying float pointFade;\n";
|
||||
}
|
||||
|
@ -3015,7 +3033,7 @@ ShaderManager::buildEmissiveFragmentShader(const ShaderProperties& props)
|
|||
source += "{\n";
|
||||
|
||||
string colorSource = "v_Color";
|
||||
if (props.texUsage & ShaderProperties::PointSprite)
|
||||
if (props.usePointSize())
|
||||
{
|
||||
source += " vec4 color = v_Color;\n";
|
||||
#if POINT_FADE
|
||||
|
@ -3026,7 +3044,7 @@ ShaderManager::buildEmissiveFragmentShader(const ShaderProperties& props)
|
|||
|
||||
if (props.texUsage & ShaderProperties::DiffuseTexture)
|
||||
{
|
||||
if (props.texUsage & ShaderProperties::PointSprite)
|
||||
if (props.usePointSize())
|
||||
source += " gl_FragColor = " + colorSource + " * texture2D(diffTex, gl_PointCoord);\n";
|
||||
else
|
||||
source += " gl_FragColor = " + colorSource + " * texture2D(diffTex, v_TexCoord0.st);\n";
|
||||
|
@ -3066,12 +3084,8 @@ ShaderManager::buildParticleVertexShader(const ShaderProperties& props)
|
|||
|
||||
// TODO: scattering constants
|
||||
|
||||
if (props.texUsage & ShaderProperties::PointSprite)
|
||||
{
|
||||
source << "uniform float pointScale;\n";
|
||||
source << "attribute float in_PointSize;\n";
|
||||
source << DeclareVarying("pointFade", Shader_Float);
|
||||
}
|
||||
if (props.usePointSize())
|
||||
source << PointSizeDeclaration();
|
||||
|
||||
source << DeclareVarying("v_Color", Shader_Vector4);
|
||||
|
||||
|
@ -3113,8 +3127,10 @@ ShaderManager::buildParticleVertexShader(const ShaderProperties& props)
|
|||
source << " v_Color = in_Color * brightness;\n";
|
||||
|
||||
// Optional point size
|
||||
if ((props.texUsage & ShaderProperties::PointSprite) != 0)
|
||||
if (props.texUsage & ShaderProperties::PointSprite)
|
||||
source << PointSizeCalculation();
|
||||
else if (props.texUsage & ShaderProperties::StaticPointSize)
|
||||
source << StaticPointSize();
|
||||
|
||||
source << VertexPosition;
|
||||
source << "}\n";
|
||||
|
@ -3140,7 +3156,7 @@ ShaderManager::buildParticleFragmentShader(const ShaderProperties& props)
|
|||
source << "uniform sampler2D diffTex;\n";
|
||||
}
|
||||
|
||||
if (props.texUsage & ShaderProperties::PointSprite)
|
||||
if (props.usePointSize())
|
||||
{
|
||||
source << DeclareVarying("pointFade", Shader_Float);
|
||||
}
|
||||
|
@ -3274,7 +3290,7 @@ ShaderManager::buildProgram(const ShaderProperties& props)
|
|||
"in_Tangent");
|
||||
}
|
||||
|
||||
if (props.texUsage & ShaderProperties::PointSprite)
|
||||
if (props.usePointSize())
|
||||
{
|
||||
glBindAttribLocation(prog->getID(),
|
||||
CelestiaGLProgram::PointSizeAttributeIndex,
|
||||
|
@ -3573,7 +3589,7 @@ CelestiaGLProgram::initParameters()
|
|||
lunarLambert = floatParam("lunarLambert");
|
||||
}
|
||||
|
||||
if ((props.texUsage & ShaderProperties::PointSprite) != 0)
|
||||
if (props.usePointSize())
|
||||
{
|
||||
pointScale = floatParam("pointScale");
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ class ShaderProperties
|
|||
bool usesShadows() const;
|
||||
bool usesFragmentLighting() const;
|
||||
bool usesTangentSpaceLighting() const;
|
||||
bool usePointSize() const;
|
||||
|
||||
unsigned int getEclipseShadowCountForLight(unsigned int lightIndex) const;
|
||||
void setEclipseShadowCountForLight(unsigned int lightIndex, unsigned int shadowCount);
|
||||
|
@ -49,22 +50,23 @@ class ShaderProperties
|
|||
|
||||
enum
|
||||
{
|
||||
DiffuseTexture = 0x01,
|
||||
SpecularTexture = 0x02,
|
||||
NormalTexture = 0x04,
|
||||
NightTexture = 0x08,
|
||||
SpecularInDiffuseAlpha = 0x10,
|
||||
RingShadowTexture = 0x20,
|
||||
OverlayTexture = 0x40,
|
||||
CloudShadowTexture = 0x80,
|
||||
CompressedNormalTexture = 0x100,
|
||||
EmissiveTexture = 0x200,
|
||||
ShadowMapTexture = 0x400,
|
||||
VertexOpacities = 0x800,
|
||||
VertexColors = 0x1000,
|
||||
Scattering = 0x2000,
|
||||
PointSprite = 0x4000,
|
||||
SharedTextureCoords = 0x8000,
|
||||
DiffuseTexture = 0x01,
|
||||
SpecularTexture = 0x02,
|
||||
NormalTexture = 0x04,
|
||||
NightTexture = 0x08,
|
||||
SpecularInDiffuseAlpha = 0x10,
|
||||
RingShadowTexture = 0x20,
|
||||
OverlayTexture = 0x40,
|
||||
CloudShadowTexture = 0x80,
|
||||
CompressedNormalTexture = 0x100,
|
||||
EmissiveTexture = 0x200,
|
||||
ShadowMapTexture = 0x400,
|
||||
VertexOpacities = 0x800,
|
||||
VertexColors = 0x1000,
|
||||
Scattering = 0x2000,
|
||||
PointSprite = 0x4000,
|
||||
SharedTextureCoords = 0x8000,
|
||||
StaticPointSize = 0x10000,
|
||||
};
|
||||
|
||||
enum
|
||||
|
@ -98,8 +100,8 @@ class ShaderProperties
|
|||
|
||||
public:
|
||||
unsigned short nLights{ 0 };
|
||||
unsigned short texUsage{ 0 };
|
||||
unsigned short lightModel{ DiffuseModel };
|
||||
unsigned long texUsage{ 0 };
|
||||
|
||||
// Effects that may be applied with any light model
|
||||
unsigned short effects{ 0 };
|
||||
|
|
Loading…
Reference in New Issue