mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 02:53:43 +02:00
Fixed the cube map loading issue
This commit is contained in:
parent
72c3270ec6
commit
45e70c98f8
3 changed files with 90 additions and 20 deletions
|
@ -121,6 +121,18 @@ public:
|
|||
NUM_TYPES,
|
||||
};
|
||||
|
||||
// Definition of the cube face name and layout
|
||||
enum CubeFace {
|
||||
CUBE_FACE_RIGHT_POS_X = 0,
|
||||
CUBE_FACE_LEFT_NEG_X,
|
||||
CUBE_FACE_TOP_POS_Y,
|
||||
CUBE_FACE_BOTTOM_NEG_Y,
|
||||
CUBE_FACE_BACK_POS_X,
|
||||
CUBE_FACE_FRONT_NEG_Z,
|
||||
|
||||
NUM_CUBE_FACES, // Not a valid vace index
|
||||
};
|
||||
|
||||
class Storage {
|
||||
public:
|
||||
Storage() {}
|
||||
|
|
|
@ -108,11 +108,12 @@ 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 * evalSkyboxLight(fragNormal, 0.75).xyz * getLightAmbientIntensity(light);
|
||||
vec3 color = /*diffuse.rgb * */evalSkyboxLight(fragNormal, getLightAmbientIntensity(light)).xyz;
|
||||
|
||||
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss);
|
||||
// vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss);
|
||||
|
||||
color += vec3(diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light);
|
||||
// color += vec3(diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
|
|
@ -524,32 +524,89 @@ void NetworkTexture::setImage(const QImage& image, bool translucent, const QColo
|
|||
}
|
||||
|
||||
if (_type == CUBE_TEXTURE) {
|
||||
_gpuTexture = gpu::TexturePointer(gpu::Texture::createCube(formatGPU, image.width(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR, gpu::Sampler::WRAP_CLAMP)));
|
||||
_gpuTexture->autoGenerateMips(-1);
|
||||
|
||||
std::vector<QImage> faces;
|
||||
if (_height == (6 * _width)) {
|
||||
int faceWidth = _width;
|
||||
|
||||
faces.push_back(image.copy(QRect(0, 0 * faceWidth, faceWidth, faceWidth)));
|
||||
faces.push_back(image.copy(QRect(0, 1 * faceWidth, faceWidth, faceWidth)));
|
||||
faces.push_back(image.copy(QRect(0, 2 * faceWidth, faceWidth, faceWidth)));
|
||||
faces.push_back(image.copy(QRect(0, 3 * faceWidth, faceWidth, faceWidth)));
|
||||
faces.push_back(image.copy(QRect(0, 4 * faceWidth, faceWidth, faceWidth)));
|
||||
faces.push_back(image.copy(QRect(0, 5 * faceWidth, faceWidth, faceWidth)));
|
||||
|
||||
// Here is the expected layout for the faces in an image with the 1/6 aspect ratio:
|
||||
//
|
||||
// WIDTH
|
||||
// <------>
|
||||
// ^ +------+
|
||||
// | | |
|
||||
// | | +X |
|
||||
// | | |
|
||||
// H +------+
|
||||
// E | |
|
||||
// I | -X |
|
||||
// G | |
|
||||
// H +------+
|
||||
// T | |
|
||||
// | | +Y |
|
||||
// | | |
|
||||
// | +------+
|
||||
// | | |
|
||||
// | | -Y |
|
||||
// | | |
|
||||
// H +------+
|
||||
// E | |
|
||||
// I | +Z |
|
||||
// G | |
|
||||
// H +------+
|
||||
// T | |
|
||||
// | | -Z |
|
||||
// | | |
|
||||
// V +------+
|
||||
//
|
||||
// FaceWidth = width = height / 6
|
||||
|
||||
faces.push_back(image.copy(QRect(0, 0 * faceWidth, faceWidth, faceWidth)).mirrored(true, false));
|
||||
faces.push_back(image.copy(QRect(0, 1 * faceWidth, faceWidth, faceWidth)).mirrored(true, false));
|
||||
faces.push_back(image.copy(QRect(0, 2 * faceWidth, faceWidth, faceWidth)).mirrored(false, true));
|
||||
faces.push_back(image.copy(QRect(0, 3 * faceWidth, faceWidth, faceWidth)).mirrored(false, true));
|
||||
faces.push_back(image.copy(QRect(0, 4 * faceWidth, faceWidth, faceWidth)).mirrored(true, false));
|
||||
faces.push_back(image.copy(QRect(0, 5 * faceWidth, faceWidth, faceWidth)).mirrored(true, false));
|
||||
|
||||
} else if ((_height / 3) == (_width / 4)) {
|
||||
int faceWidth = _height / 3;
|
||||
faces.push_back(image.copy(QRect(2 * faceWidth, faceWidth, faceWidth, faceWidth)));
|
||||
faces.push_back(image.copy(QRect(0 * faceWidth, faceWidth, faceWidth, faceWidth)));
|
||||
|
||||
faces.push_back(image.copy(QRect(1 * faceWidth, 0, faceWidth, faceWidth)));
|
||||
faces.push_back(image.copy(QRect(1 * faceWidth, 0 * faceWidth, faceWidth, faceWidth)));
|
||||
|
||||
faces.push_back(image.copy(QRect(3 * faceWidth, faceWidth, faceWidth, faceWidth)));
|
||||
faces.push_back(image.copy(QRect(1 * faceWidth, faceWidth, faceWidth, faceWidth)));
|
||||
// Here is the expected layout for the faces in an image with the 3/4 aspect ratio:
|
||||
//
|
||||
// <-----------WIDTH----------->
|
||||
// ^ +------+------+------+------+
|
||||
// | | | | | |
|
||||
// | | | +Y | | |
|
||||
// | | | | | |
|
||||
// H +------+------+------+------+
|
||||
// E | | | | |
|
||||
// I | -X | -Z | +X | +Z |
|
||||
// G | | | | |
|
||||
// H +------+------+------+------+
|
||||
// T | | | | |
|
||||
// | | | -Y | | |
|
||||
// | | | | | |
|
||||
// V +------+------+------+------+
|
||||
//
|
||||
// FaceWidth = width / 4 = height / 3
|
||||
|
||||
// Right = +X
|
||||
faces.push_back(image.copy(QRect(2 * faceWidth, faceWidth, faceWidth, faceWidth)).mirrored(true, false));
|
||||
// Left = -X
|
||||
faces.push_back(image.copy(QRect(0 * faceWidth, faceWidth, faceWidth, faceWidth)).mirrored(true, false));
|
||||
// Top = +Y
|
||||
faces.push_back(image.copy(QRect(1 * faceWidth, 0, faceWidth, faceWidth)).mirrored(false, true));
|
||||
// Bottom = -Y
|
||||
faces.push_back(image.copy(QRect(1 * faceWidth, 2 * faceWidth, faceWidth, faceWidth)).mirrored(false, true));
|
||||
// Back = +Z
|
||||
faces.push_back(image.copy(QRect(3 * faceWidth, faceWidth, faceWidth, faceWidth)).mirrored(true, false));
|
||||
// Front = -Z
|
||||
faces.push_back(image.copy(QRect(1 * faceWidth, faceWidth, faceWidth, faceWidth)).mirrored(true, false));
|
||||
}
|
||||
|
||||
if (faces.size() == _gpuTexture->getNumFaces()) {
|
||||
if (faces.size() == gpu::Texture::NUM_FACES_PER_TYPE[gpu::Texture::TEX_CUBE]) {
|
||||
_gpuTexture = gpu::TexturePointer(gpu::Texture::createCube(formatGPU, faces[0].width(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR, gpu::Sampler::WRAP_CLAMP)));
|
||||
_gpuTexture->autoGenerateMips(-1);
|
||||
int f = 0;
|
||||
for (auto& face : faces) {
|
||||
_gpuTexture->assignStoredMipFace(0, formatMip, face.byteCount(), face.constBits(), f);
|
||||
|
|
Loading…
Reference in a new issue