mirror of
https://github.com/lubosz/overte.git
synced 2025-04-19 16:44:04 +02:00
Wavelengths, switch for environment rendering, far plane adjustment.
This commit is contained in:
parent
7faa9e4318
commit
47f3566929
4 changed files with 42 additions and 19 deletions
|
@ -12,15 +12,6 @@
|
|||
#include "Environment.h"
|
||||
#include "world.h"
|
||||
|
||||
// checks for an error, printing the info log if one is deteced
|
||||
static void errorCheck(GLhandleARB obj) {
|
||||
if (glGetError() != GL_NO_ERROR) {
|
||||
QByteArray log(1024, 0);
|
||||
glGetInfoLogARB(obj, log.size(), 0, log.data());
|
||||
qDebug() << log;
|
||||
}
|
||||
}
|
||||
|
||||
static GLhandleARB compileShader(int type, const QString& filename) {
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
|
@ -32,7 +23,6 @@ static GLhandleARB compileShader(int type, const QString& filename) {
|
|||
const char* sdata = source.constData();
|
||||
glShaderSource(shaderID, 1, &sdata, 0);
|
||||
glCompileShaderARB(shaderID);
|
||||
errorCheck(shaderID);
|
||||
return shaderID;
|
||||
}
|
||||
|
||||
|
@ -43,7 +33,6 @@ void Environment::init() {
|
|||
glAttachObjectARB(_skyFromAtmosphereProgramID, compileShader(
|
||||
GL_FRAGMENT_SHADER_ARB, "resources/shaders/SkyFromAtmosphere.frag"));
|
||||
glLinkProgramARB(_skyFromAtmosphereProgramID);
|
||||
errorCheck(_skyFromAtmosphereProgramID);
|
||||
|
||||
_cameraPosLocation = glGetUniformLocationARB(_skyFromAtmosphereProgramID, "v3CameraPos");
|
||||
_lightPosLocation = glGetUniformLocationARB(_skyFromAtmosphereProgramID, "v3LightPos");
|
||||
|
@ -65,18 +54,28 @@ void Environment::render(Camera& camera) {
|
|||
glPushMatrix();
|
||||
glTranslatef(getAtmosphereCenter().x, getAtmosphereCenter().y, getAtmosphereCenter().z);
|
||||
|
||||
// use the camera distance to reset the near and far distances to keep the atmosphere in the frustum
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
gluPerspective(camera.getFieldOfView(), camera.getAspectRatio(), 100, 100000000);
|
||||
|
||||
glUseProgramObjectARB(_skyFromAtmosphereProgramID);
|
||||
float projection[16];
|
||||
glGetFloatv(GL_PROJECTION_MATRIX, projection);
|
||||
glm::vec3 relativeCameraPos = camera.getPosition() - getAtmosphereCenter();
|
||||
float near = camera.getNearClip(), far = glm::length(relativeCameraPos) + getAtmosphereOuterRadius();
|
||||
projection[10] = (far + near) / (near - far);
|
||||
projection[14] = (2.0f * far * near) / (near - far);
|
||||
glLoadMatrixf(projection);
|
||||
|
||||
// the constants here are from Sean O'Neil's GPU Gems entry
|
||||
// (http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter16.html), GameEngine.cpp
|
||||
glUseProgramObjectARB(_skyFromAtmosphereProgramID);
|
||||
glUniform3fARB(_cameraPosLocation, relativeCameraPos.x, relativeCameraPos.y, relativeCameraPos.z);
|
||||
glm::vec3 lightDirection = glm::normalize(getSunLocation());
|
||||
glUniform3fARB(_lightPosLocation, lightDirection.x, lightDirection.y, lightDirection.z);
|
||||
glUniform3fARB(_invWavelengthLocation,
|
||||
1 / powf(0.650f, 4.0f), 1 / powf(0.570f, 4.0f), 1 / powf(0.475f, 4.0f));
|
||||
1 / powf(getScatteringWavelengths().r, 4.0f),
|
||||
1 / powf(getScatteringWavelengths().g, 4.0f),
|
||||
1 / powf(getScatteringWavelengths().b, 4.0f));
|
||||
glUniform1fARB(_innerRadiusLocation, getAtmosphereInnerRadius());
|
||||
glUniform1fARB(_krESunLocation, getRayleighScattering() * getSunBrightness());
|
||||
glUniform1fARB(_kmESunLocation, getMieScattering() * getSunBrightness());
|
||||
|
@ -90,7 +89,10 @@ void Environment::render(Camera& camera) {
|
|||
glUniform1fARB(_g2Location, -0.990f * -0.990f);
|
||||
|
||||
glFrontFace(GL_CW);
|
||||
glDepthMask(GL_FALSE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glutSolidSphere(getAtmosphereOuterRadius(), 100, 50);
|
||||
glDepthMask(GL_TRUE);
|
||||
glFrontFace(GL_CCW);
|
||||
|
||||
glUseProgramObjectARB(0);
|
||||
|
@ -98,5 +100,5 @@ void Environment::render(Camera& camera) {
|
|||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
glPopMatrix();
|
||||
}
|
||||
|
|
|
@ -152,6 +152,7 @@ bool renderWarningsOn = false; // Whether to show render pipeline warnings
|
|||
|
||||
bool statsOn = false; // Whether to show onscreen text overlay with stats
|
||||
bool starsOn = false; // Whether to display the stars
|
||||
bool environmentOn = true; // Whether to display the environment
|
||||
bool paintOn = false; // Whether to paint voxels as you fly around
|
||||
VoxelDetail paintingVoxel; // The voxel we're painting if we're painting
|
||||
unsigned char dominantColor = 0; // The dominant color of the voxel we're painting
|
||||
|
@ -685,8 +686,10 @@ void displaySide(Camera& whichCamera) {
|
|||
glPushMatrix();
|
||||
|
||||
// draw the sky dome
|
||||
environment.render(whichCamera);
|
||||
|
||||
if (::environmentOn) {
|
||||
environment.render(whichCamera);
|
||||
}
|
||||
|
||||
if (::starsOn) {
|
||||
// should be the first rendering pass - w/o depth buffer / lighting
|
||||
|
||||
|
@ -1218,6 +1221,10 @@ int setStars(int state) {
|
|||
return setValue(state, &::starsOn);
|
||||
}
|
||||
|
||||
int setEnvironment(int state) {
|
||||
return setValue(state, &::environmentOn);
|
||||
}
|
||||
|
||||
int setOculus(int state) {
|
||||
bool wasOn = ::oculusOn;
|
||||
int value = setValue(state, &::oculusOn);
|
||||
|
@ -1363,6 +1370,7 @@ void initMenu() {
|
|||
menuColumnRender = menu.addColumn("Render");
|
||||
menuColumnRender->addRow("Voxels (V)", setVoxels);
|
||||
menuColumnRender->addRow("Stars (*)", setStars);
|
||||
menuColumnRender->addRow("Environment (E)", setEnvironment);
|
||||
menuColumnRender->addRow("Oculus (o)", setOculus);
|
||||
|
||||
// Tools
|
||||
|
@ -1550,6 +1558,7 @@ void key(unsigned char k, int x, int y)
|
|||
if (k == '/') ::statsOn = !::statsOn; // toggle stats
|
||||
if (k == '*') ::starsOn = !::starsOn; // toggle stars
|
||||
if (k == 'V' || k == 'v') ::showingVoxels = !::showingVoxels; // toggle voxels
|
||||
if (k == 'E') ::environmentOn = !::environmentOn;
|
||||
if (k == 'F') ::frustumOn = !::frustumOn; // toggle view frustum debugging
|
||||
if (k == 'C') ::cameraFrustum = !::cameraFrustum; // toggle which frustum to look at
|
||||
if (k == 'O' || k == 'G') setFrustumOffset(MENU_ROW_PICKED); // toggle view frustum offset debugging
|
||||
|
|
|
@ -11,13 +11,14 @@
|
|||
#include "PacketHeaders.h"
|
||||
|
||||
// initial values from Sean O'Neil's GPU Gems entry (http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter16.html),
|
||||
// GameEngine.cpp
|
||||
// GameEngine.cpp (and the radius of the earth)
|
||||
EnvironmentData::EnvironmentData() :
|
||||
_atmosphereCenter(0, -6371000, 0),
|
||||
_atmosphereInnerRadius(6371000),
|
||||
_atmosphereOuterRadius(6530275),
|
||||
_rayleighScattering(0.0025f),
|
||||
_mieScattering(0.0010f),
|
||||
_scatteringWavelengths(0.650f, 0.570f, 0.475f),
|
||||
_sunLocation(1000, 1000, 0),
|
||||
_sunBrightness(20.0f) {
|
||||
}
|
||||
|
@ -40,6 +41,9 @@ int EnvironmentData::getBroadcastData(unsigned char* destinationBuffer) const {
|
|||
memcpy(destinationBuffer, &_mieScattering, sizeof(_mieScattering));
|
||||
destinationBuffer += sizeof(_mieScattering);
|
||||
|
||||
memcpy(destinationBuffer, &_scatteringWavelengths, sizeof(_scatteringWavelengths));
|
||||
destinationBuffer += sizeof(_scatteringWavelengths);
|
||||
|
||||
memcpy(destinationBuffer, &_sunLocation, sizeof(_sunLocation));
|
||||
destinationBuffer += sizeof(_sunLocation);
|
||||
|
||||
|
@ -70,6 +74,9 @@ int EnvironmentData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
|||
memcpy(&_mieScattering, sourceBuffer, sizeof(_mieScattering));
|
||||
sourceBuffer += sizeof(_mieScattering);
|
||||
|
||||
memcpy(&_scatteringWavelengths, sourceBuffer, sizeof(_scatteringWavelengths));
|
||||
sourceBuffer += sizeof(_scatteringWavelengths);
|
||||
|
||||
memcpy(&_sunLocation, sourceBuffer, sizeof(_sunLocation));
|
||||
sourceBuffer += sizeof(_sunLocation);
|
||||
|
||||
|
|
|
@ -28,6 +28,9 @@ public:
|
|||
float getRayleighScattering() const { return _rayleighScattering; }
|
||||
float getMieScattering() const { return _mieScattering; }
|
||||
|
||||
void setScatteringWavelengths(const glm::vec3& wavelengths) { _scatteringWavelengths = wavelengths; }
|
||||
const glm::vec3& getScatteringWavelengths() const { return _scatteringWavelengths; }
|
||||
|
||||
void setSunLocation(const glm::vec3& location) { _sunLocation = location; }
|
||||
void setSunBrightness(float brightness) { _sunBrightness = brightness; }
|
||||
const glm::vec3& getSunLocation() const { return _sunLocation; }
|
||||
|
@ -45,6 +48,8 @@ private:
|
|||
float _rayleighScattering;
|
||||
float _mieScattering;
|
||||
|
||||
glm::vec3 _scatteringWavelengths;
|
||||
|
||||
glm::vec3 _sunLocation;
|
||||
float _sunBrightness;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue