mip-mapping related fixes
This commit is contained in:
parent
7ddf3f7537
commit
d9277e1b31
@ -16,8 +16,11 @@ void main() {
|
|||||||
vec4 tex_color = texture(u_texture0, a_texCoord);
|
vec4 tex_color = texture(u_texture0, a_texCoord);
|
||||||
float depth = (a_distance/256.0);
|
float depth = (a_distance/256.0);
|
||||||
float alpha = a_color.a * tex_color.a;
|
float alpha = a_color.a * tex_color.a;
|
||||||
if (u_alphaClip && alpha < 0.9f)
|
if (u_alphaClip) {
|
||||||
discard;
|
if (alpha < 0.2f)
|
||||||
|
discard;
|
||||||
|
alpha = 1.0;
|
||||||
|
}
|
||||||
f_color = mix(a_color * tex_color, vec4(fogColor,1.0),
|
f_color = mix(a_color * tex_color, vec4(fogColor,1.0),
|
||||||
min(1.0, pow(depth*u_fogFactor, u_fogCurve)));
|
min(1.0, pow(depth*u_fogFactor, u_fogCurve)));
|
||||||
f_color.a = alpha;
|
f_color.a = alpha;
|
||||||
|
|||||||
@ -25,7 +25,7 @@ GLTexture::GLTexture(const ubyte* data, uint width, uint height, ImageFormat ima
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -242,18 +242,34 @@ void ImageData::extrude(int x, int y, int w, int h) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fixing black transparent pixels for Mip-Mapping
|
||||||
void ImageData::fixAlphaColor() {
|
void ImageData::fixAlphaColor() {
|
||||||
// Fixing black transparent pixels for Mip-Mapping
|
int samples = 0;
|
||||||
for (uint ly = 0; ly < height-1; ly++) {
|
int sums[3] {};
|
||||||
for (uint lx = 0; lx < width-1; lx++) {
|
for (uint ly = 0; ly < height; ly++) {
|
||||||
if (data[((ly) * width + lx) * 4 + 3]) {
|
for (uint lx = 0; lx < width; lx++) {
|
||||||
for (int c = 0; c < 3; c++) {
|
if (data[(ly * width + lx) * 4 + 3] == 0) {
|
||||||
int val = data[((ly) + + lx) * 4 + c];
|
continue;
|
||||||
if (data[((ly) * width + lx + 1) * 4 + 3] == 0)
|
}
|
||||||
data[((ly) * width + lx + 1) * 4 + c] = val;
|
samples++;
|
||||||
if (data[((ly + 1) * width + lx) * 4 + 3] == 0)
|
for (int c = 0; c < 3; c++) {
|
||||||
data[((ly + 1) * width + lx) * 4 + c] = val;
|
sums[c] += data[(ly * width + lx) * 4 + c];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (samples == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
sums[i] /= samples;
|
||||||
|
}
|
||||||
|
for (uint ly = 0; ly < height; ly++) {
|
||||||
|
for (uint lx = 0; lx < width; lx++) {
|
||||||
|
if (data[(ly * width + lx) * 4 + 3] != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
data[(ly * width + lx) * 4 + i] = sums[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -197,7 +197,7 @@ void ChunksRenderer::drawChunks(
|
|||||||
|
|
||||||
// TODO: minimize draw calls number
|
// TODO: minimize draw calls number
|
||||||
for (int i = indices.size()-1; i >= 0; i--) {
|
for (int i = indices.size()-1; i >= 0; i--) {
|
||||||
auto chunk = chunks.getChunks()[indices[i].index];
|
auto& chunk = chunks.getChunks()[indices[i].index];
|
||||||
auto mesh = retrieveChunk(indices[i].index, camera, shader, culling);
|
auto mesh = retrieveChunk(indices[i].index, camera, shader, culling);
|
||||||
|
|
||||||
if (mesh) {
|
if (mesh) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user