mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 18:56:55 +02:00
Fix for misaligned color/material textures when resolution is greater than the
height map.
This commit is contained in:
parent
f7f480cee4
commit
b4cd13f0be
3 changed files with 16 additions and 4 deletions
|
@ -43,5 +43,5 @@ void main(void) {
|
||||||
gl_FrontColor = vec4(1.0, 1.0, 1.0, step(height, 0.0));
|
gl_FrontColor = vec4(1.0, 1.0, 1.0, step(height, 0.0));
|
||||||
|
|
||||||
// pass along the scaled/offset texture coordinates
|
// pass along the scaled/offset texture coordinates
|
||||||
gl_TexCoord[0] = vec4((heightCoord - heightScale.st) * colorScale, 0.0, 1.0);
|
gl_TexCoord[0] = vec4((heightCoord - vec2(0.5, 0.5)) * colorScale + vec2(0.5, 0.5), 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ void main(void) {
|
||||||
gl_TexCoord[3] = textureSpacePosition * vec4(splatTextureScalesS[3], splatTextureScalesT[3], 0.0, 1.0);
|
gl_TexCoord[3] = textureSpacePosition * vec4(splatTextureScalesS[3], splatTextureScalesT[3], 0.0, 1.0);
|
||||||
|
|
||||||
// compute the alpha values for each texture
|
// compute the alpha values for each texture
|
||||||
float value = texture2D(textureMap, (gl_MultiTexCoord0.st - heightScale) * textureScale).r;
|
float value = texture2D(textureMap, (gl_MultiTexCoord0.st - vec2(0.5, 0.5)) * textureScale + vec2(0.5, 0.5)).r;
|
||||||
vec4 valueVector = vec4(value, value, value, value);
|
vec4 valueVector = vec4(value, value, value, value);
|
||||||
alphaValues = step(textureValueMinima, valueVector) * step(valueVector, textureValueMaxima);
|
alphaValues = step(textureValueMinima, valueVector) * step(valueVector, textureValueMaxima);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2407,7 +2407,14 @@ void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const g
|
||||||
baseBatch.heightTextureID = _heightTextureID;
|
baseBatch.heightTextureID = _heightTextureID;
|
||||||
baseBatch.heightScale = glm::vec4(1.0f / width, 1.0f / height, (innerWidth - 1) / -2.0f, (innerHeight - 1) / -2.0f);
|
baseBatch.heightScale = glm::vec4(1.0f / width, 1.0f / height, (innerWidth - 1) / -2.0f, (innerHeight - 1) / -2.0f);
|
||||||
baseBatch.colorTextureID = _colorTextureID;
|
baseBatch.colorTextureID = _colorTextureID;
|
||||||
baseBatch.colorScale = glm::vec2((float)width / innerWidth, (float)height / innerHeight);
|
float widthMultiplier = 1.0f / (0.5f - 1.5f / width);
|
||||||
|
float heightMultiplier = 1.0f / (0.5f - 1.5f / height);
|
||||||
|
if (node->getColor()) {
|
||||||
|
int colorWidth = node->getColor()->getWidth();
|
||||||
|
int colorHeight = node->getColor()->getContents().size() / (colorWidth * DataBlock::COLOR_BYTES);
|
||||||
|
baseBatch.colorScale = glm::vec2((0.5f - 0.5f / colorWidth) * widthMultiplier,
|
||||||
|
(0.5f - 0.5f / colorHeight) * heightMultiplier);
|
||||||
|
}
|
||||||
Application::getInstance()->getMetavoxels()->addHeightfieldBaseBatch(baseBatch);
|
Application::getInstance()->getMetavoxels()->addHeightfieldBaseBatch(baseBatch);
|
||||||
|
|
||||||
if (!(cursor || _networkTextures.isEmpty())) {
|
if (!(cursor || _networkTextures.isEmpty())) {
|
||||||
|
@ -2422,7 +2429,12 @@ void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const g
|
||||||
splatBatch.heightTextureID = _heightTextureID;
|
splatBatch.heightTextureID = _heightTextureID;
|
||||||
splatBatch.heightScale = glm::vec4(1.0f / width, 1.0f / height, 0.0f, 0.0f);
|
splatBatch.heightScale = glm::vec4(1.0f / width, 1.0f / height, 0.0f, 0.0f);
|
||||||
splatBatch.materialTextureID = _materialTextureID;
|
splatBatch.materialTextureID = _materialTextureID;
|
||||||
splatBatch.textureScale = glm::vec2((float)width / innerWidth, (float)height / innerHeight);
|
if (node->getMaterial()) {
|
||||||
|
int materialWidth = node->getMaterial()->getWidth();
|
||||||
|
int materialHeight = node->getMaterial()->getContents().size() / materialWidth;
|
||||||
|
splatBatch.textureScale = glm::vec2((0.5f - 0.5f / materialWidth) * widthMultiplier,
|
||||||
|
(0.5f - 0.5f / materialHeight) * heightMultiplier);
|
||||||
|
}
|
||||||
splatBatch.splatTextureOffset = glm::vec2(
|
splatBatch.splatTextureOffset = glm::vec2(
|
||||||
glm::dot(translation, rotation * glm::vec3(1.0f, 0.0f, 0.0f)) / scale.x,
|
glm::dot(translation, rotation * glm::vec3(1.0f, 0.0f, 0.0f)) / scale.x,
|
||||||
glm::dot(translation, rotation * glm::vec3(0.0f, 0.0f, 1.0f)) / scale.z);
|
glm::dot(translation, rotation * glm::vec3(0.0f, 0.0f, 1.0f)) / scale.z);
|
||||||
|
|
Loading…
Reference in a new issue