mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +02:00
When the stars and the atmosphere are both on, adjust the stars' alpha value
based on the distance from the atmosphere.
This commit is contained in:
parent
8a21823469
commit
caeccf59ec
5 changed files with 35 additions and 15 deletions
|
@ -34,7 +34,7 @@ float Stars::changeLOD(float fraction, float overalloc, float realloc) {
|
|||
return float(_ptrController->changeLOD(fraction, overalloc, realloc));
|
||||
}
|
||||
|
||||
void Stars::render(float fovY, float aspect, float nearZ) {
|
||||
void Stars::render(float fovY, float aspect, float nearZ, float alpha) {
|
||||
|
||||
// determine length of screen diagonal from quadrant height and aspect ratio
|
||||
float quadrantHeight = nearZ * tan(angleConvert<Degrees,Radians>(fovY) * 0.5f);
|
||||
|
@ -46,7 +46,7 @@ void Stars::render(float fovY, float aspect, float nearZ) {
|
|||
// pull the modelview matrix off the GL stack
|
||||
glm::mat4 view; glGetFloatv(GL_MODELVIEW_MATRIX, glm::value_ptr(view));
|
||||
|
||||
_ptrController->render(fovDiagonal, aspect, glm::affineInverse(view));
|
||||
_ptrController->render(fovDiagonal, aspect, glm::affineInverse(view), alpha);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class Stars {
|
|||
// Renders the starfield from a local viewer's perspective.
|
||||
// The parameters specifiy the field of view.
|
||||
//
|
||||
void render(float fovY, float aspect, float nearZ);
|
||||
void render(float fovY, float aspect, float nearZ, float alpha);
|
||||
|
||||
//
|
||||
// Sets the resolution for FOV culling.
|
||||
|
|
|
@ -686,8 +686,21 @@ void displaySide(Camera& whichCamera) {
|
|||
if (::starsOn) {
|
||||
// should be the first rendering pass - w/o depth buffer / lighting
|
||||
|
||||
// compute starfield alpha based on distance from atmosphere
|
||||
float alpha = 1.0f;
|
||||
if (::atmosphereOn) {
|
||||
float height = glm::distance(whichCamera.getPosition(), environment.getAtmosphereCenter());
|
||||
if (height < environment.getAtmosphereInnerRadius()) {
|
||||
alpha = 0.0f;
|
||||
|
||||
} else if (height < environment.getAtmosphereOuterRadius()) {
|
||||
alpha = (height - environment.getAtmosphereInnerRadius()) /
|
||||
(environment.getAtmosphereOuterRadius() - environment.getAtmosphereInnerRadius());
|
||||
}
|
||||
}
|
||||
|
||||
// finally render the starfield
|
||||
stars.render(whichCamera.getFieldOfView(), aspectRatio, whichCamera.getNearClip());
|
||||
stars.render(whichCamera.getFieldOfView(), aspectRatio, whichCamera.getNearClip(), alpha);
|
||||
}
|
||||
|
||||
// draw the sky dome
|
||||
|
|
|
@ -361,7 +361,7 @@ namespace starfield {
|
|||
|
||||
public:
|
||||
|
||||
void render(float perspective, float angle, mat4 const& orientation) {
|
||||
void render(float perspective, float angle, mat4 const& orientation, float alpha) {
|
||||
|
||||
#if STARFIELD_MULTITHREADING
|
||||
// check out renderer
|
||||
|
@ -377,7 +377,7 @@ namespace starfield {
|
|||
#else
|
||||
BrightnessLevel b = _valLodBrightness;
|
||||
#endif
|
||||
renderer->render(perspective, angle, orientation, b);
|
||||
renderer->render(perspective, angle, orientation, b, alpha);
|
||||
}
|
||||
|
||||
#if STARFIELD_MULTITHREADING
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#error "This is an implementation file - not intended for direct inclusion."
|
||||
#endif
|
||||
|
||||
#include "renderer/ProgramObject.h"
|
||||
|
||||
#include "starfield/Config.h"
|
||||
#include "starfield/data/InputVertex.h"
|
||||
#include "starfield/data/BrightnessLevel.h"
|
||||
|
@ -70,7 +72,8 @@ namespace starfield {
|
|||
GLint* _arrBatchOffs;
|
||||
GLsizei* _arrBatchCount;
|
||||
GLuint _hndVertexArray;
|
||||
OGlProgram _objProgram;
|
||||
ProgramObject _objProgram;
|
||||
int _alphaLocation;
|
||||
|
||||
Tiling _objTiling;
|
||||
|
||||
|
@ -123,7 +126,8 @@ namespace starfield {
|
|||
void render(float perspective,
|
||||
float aspect,
|
||||
mat4 const& orientation,
|
||||
BrightnessLevel minBright) {
|
||||
BrightnessLevel minBright,
|
||||
float alpha) {
|
||||
|
||||
// printLog("
|
||||
// Stars.cpp: rendering at minimal brightness %d\n", minBright);
|
||||
|
@ -186,7 +190,7 @@ namespace starfield {
|
|||
# define matrix matrix_debug
|
||||
#endif
|
||||
this->glBatch(glm::value_ptr(matrix), prepareBatch(
|
||||
(unsigned*) _arrBatchOffs, _itrOutIndex) );
|
||||
(unsigned*) _arrBatchOffs, _itrOutIndex), alpha);
|
||||
|
||||
#if STARFIELD_DEBUG_CULLING
|
||||
# undef matrix
|
||||
|
@ -463,24 +467,26 @@ namespace starfield {
|
|||
|
||||
GLchar const* const VERTEX_SHADER =
|
||||
"#version 120\n"
|
||||
"uniform float alpha;\n"
|
||||
"void main(void) {\n"
|
||||
|
||||
" vec3 c = gl_Color.rgb * 1.0125;\n"
|
||||
" float s = max(1.0, dot(c, c) * 0.7);\n"
|
||||
|
||||
" gl_Position = ftransform();\n"
|
||||
" gl_FrontColor= gl_Color;\n"
|
||||
" gl_FrontColor= gl_Color * alpha;\n"
|
||||
" gl_PointSize = s;\n"
|
||||
"}\n";
|
||||
|
||||
_objProgram.addShader(GL_VERTEX_SHADER, VERTEX_SHADER);
|
||||
_objProgram.attachFromSourceCode(GL_VERTEX_SHADER, VERTEX_SHADER);
|
||||
GLchar const* const FRAGMENT_SHADER =
|
||||
"#version 120\n"
|
||||
"void main(void) {\n"
|
||||
" gl_FragColor = gl_Color;\n"
|
||||
"}\n";
|
||||
_objProgram.addShader(GL_FRAGMENT_SHADER, FRAGMENT_SHADER);
|
||||
_objProgram.attachFromSourceCode(GL_FRAGMENT_SHADER, FRAGMENT_SHADER);
|
||||
_objProgram.link();
|
||||
_alphaLocation = _objProgram.getUniformLocation("alpha");
|
||||
|
||||
glGenBuffersARB(1, & _hndVertexArray);
|
||||
}
|
||||
|
@ -499,7 +505,7 @@ namespace starfield {
|
|||
glBindBufferARB(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
void glBatch(GLfloat const* matrix, GLsizei n_ranges) {
|
||||
void glBatch(GLfloat const* matrix, GLsizei n_ranges, float alpha) {
|
||||
|
||||
// printLog("Stars.cpp: rendering %d-multibatch\n", n_ranges);
|
||||
|
||||
|
@ -527,7 +533,8 @@ namespace starfield {
|
|||
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
|
||||
// select shader and vertex array
|
||||
_objProgram.activate();
|
||||
_objProgram.bind();
|
||||
_objProgram.setUniform(_alphaLocation, alpha);
|
||||
glBindBufferARB(GL_ARRAY_BUFFER, _hndVertexArray);
|
||||
glInterleavedArrays(GL_C4UB_V3F, sizeof(GpuVertex), 0l);
|
||||
|
||||
|
@ -537,7 +544,7 @@ namespace starfield {
|
|||
|
||||
// restore state
|
||||
glBindBufferARB(GL_ARRAY_BUFFER, 0);
|
||||
glUseProgram(0);
|
||||
_objProgram.release();
|
||||
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
||||
glDisable(GL_POINT_SMOOTH);
|
||||
glPopMatrix();
|
||||
|
|
Loading…
Reference in a new issue