mirror of
https://github.com/overte-org/overte.git
synced 2025-04-15 19:39:20 +02:00
Generating the SH from the cube map!
This commit is contained in:
parent
04d3f690dc
commit
65e83df214
6 changed files with 17 additions and 7 deletions
|
@ -57,7 +57,7 @@ const Texture::PixelsPointer Texture::Storage::getMipFace(uint16 level, uint8 fa
|
|||
|
||||
void Texture::Storage::notifyMipFaceGPULoaded(uint16 level, uint8 face) const {
|
||||
PixelsPointer mipFace = getMipFace(level, face);
|
||||
if (mipFace) {
|
||||
if (mipFace && (_type != TEX_CUBE)) {
|
||||
mipFace->_isGPULoaded = true;
|
||||
mipFace->_sysmem.resize(0);
|
||||
}
|
||||
|
|
|
@ -39,6 +39,9 @@ void Skybox::setColor(const Color& color) {
|
|||
}
|
||||
|
||||
void Skybox::setCubemap(const gpu::TexturePointer& cubemap) {
|
||||
if (_isSHValid && (cubemap != _cubemap)) {
|
||||
_isSHValid = false;
|
||||
}
|
||||
_cubemap = cubemap;
|
||||
}
|
||||
|
||||
|
@ -348,7 +351,7 @@ const SphericalHarmonics& Skybox::getAmbientSH() const {
|
|||
if (_cubemap && _cubemap->isDefined()) {
|
||||
|
||||
std::vector< glm::vec3 > coefs(10, glm::vec3(0.0f));
|
||||
sphericalHarmonicsFromTexture(*_cubemap, coefs, 2);
|
||||
sphericalHarmonicsFromTexture(*_cubemap, coefs, 3);
|
||||
|
||||
_ambientSH.L00 = coefs[0];
|
||||
_ambientSH.L1m1 = coefs[1];
|
||||
|
|
|
@ -20,5 +20,6 @@ varying vec3 color;
|
|||
void main(void) {
|
||||
vec3 coord = normalize(normal);
|
||||
vec4 texel = textureCube(cubeMap, coord);
|
||||
gl_FragData[0] = vec4(texel.xyz * color, 0.0);
|
||||
vec3 pixel = pow(texel.xyz * color, vec3(1.0/2.2)); // manual Gamma correction
|
||||
gl_FragData[0] = vec4(pixel, 0.0);
|
||||
}
|
||||
|
|
|
@ -111,8 +111,8 @@ vec3 evalSkyboxGlobalColor(float shadowAttenuation, vec3 position, vec3 normal,
|
|||
vec4 fragEyeVector = invViewMat * vec4(-position, 0.0);
|
||||
vec3 fragEyeDir = normalize(fragEyeVector.xyz);
|
||||
|
||||
vec3 color = diffuse.rgb * evalSkyboxLight(fragNormal, 0.75).xyz * getLightAmbientIntensity(light);
|
||||
|
||||
vec3 color = diffuse.rgb * evalSphericalLight(ambientSphere, fragNormal).xyz * getLightAmbientIntensity(light);
|
||||
|
||||
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss);
|
||||
|
||||
color += vec3(diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light);
|
||||
|
|
|
@ -291,7 +291,12 @@ void DeferredLightingEffect::render() {
|
|||
auto globalLight = _allocatedLights[_globalLights.front()];
|
||||
|
||||
if (locations->ambientSphere >= 0) {
|
||||
auto sh = globalLight->getAmbientSphere();
|
||||
model::SphericalHarmonics sh;
|
||||
if (useSkyboxCubemap) {
|
||||
sh = _skybox->getAmbientSH();
|
||||
} else {
|
||||
sh = globalLight->getAmbientSphere();
|
||||
}
|
||||
for (int i =0; i <model::SphericalHarmonics::NUM_COEFFICIENTS; i++) {
|
||||
program->setUniformValue(locations->ambientSphere + i, *(((QVector4D*) &sh) + i));
|
||||
}
|
||||
|
|
|
@ -514,7 +514,8 @@ void NetworkTexture::setImage(const QImage& image, bool translucent, const QColo
|
|||
|
||||
if ((_width > 0) && (_height > 0)) {
|
||||
|
||||
bool isLinearRGB = true; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE);
|
||||
// bool isLinearRGB = true; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE);
|
||||
bool isLinearRGB = !(_type == CUBE_TEXTURE); //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE);
|
||||
|
||||
gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB));
|
||||
gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB));
|
||||
|
|
Loading…
Reference in a new issue