satoshinm / NetCraft

Web-based fork of fogleman/Craft ⛺
https://satoshinm.github.io/NetCraft/
MIT License
57 stars 13 forks source link

Change textures based on Pixeludi pack #117

Closed satoshinm closed 7 years ago

satoshinm commented 7 years ago

Change the textures to the Pixeludi Pack (Creative Commons 2011 by Wojtek Mroczek), or at least based on it. This is the CC-BY-SA pack used in TrueCraft:

https://github.com/SirCmpwn/TrueCraft/blob/7f0e3338d231b8a8f7fba35742b618a4fb3575bf/TrueCraft.Client/Content/terrain.png

https://truecraft.io/blog/32/New%20texture%20pack%2C%20gamepad%20support licensed as CC-BY-SA

Other resources to consider: https://github.com/SirCmpwn/TrueCraft/issues/45 "Free (as in freedom) resources for TrueCraft use"


screen shot 2017-05-12 at 11 01 46 pm

satoshinm commented 7 years ago

The textures have a 0x7f7f7f background, solid gray:

terrain

but Craft uses 0xff01ff magenta for transparent. Changed it with the flood fill tool, substituted in block breaking animation texture section:

texture

but it doesn't look right. The color is too white:

screen shot 2017-05-12 at 7 23 23 pm

probably it is meant to be an alpha layer over the actual block texture?

satoshinm commented 7 years ago

The block break texture is meant to be blended, hence 0x7f7f7f (0.5 rgb) for neutral, see: glBlendFunc, glBlendEquation. TrueCraft does it this way:

            DestructionBlendState = new BlendState
            {
                ColorSourceBlend = Blend.DestinationColor,
                ColorDestinationBlend = Blend.SourceColor,
                AlphaSourceBlend = Blend.DestinationAlpha,
                AlphaDestinationBlend = Blend.SourceAlpha
            };
...
                Game.GraphicsDevice.BlendState = DestructionBlendState;
                ProgressMesh.Draw(DestructionEffect);
                Game.GraphicsDevice.BlendState = BlendState.AlphaBlend;
                Game.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

Some examples of comparing blend functions: http://www.machwerx.com/2009/02/11/glblendfunc/

More from https://gamedev.stackexchange.com/questions/30315/understanding-how-opengl-blending-works

i2iac

satoshinm commented 7 years ago

The C# code translates to in C:

glBlendFuncSeparate(GL_DST_COLOR, GL_SRC_COLOR, GL_DST_ALPHA, GL_SRC_ALPHA);

this looks better, but darkens the block too much:

screen shot 2017-05-12 at 9 52 33 pm

Something related to premultiplied alpha? http://stackoverflow.com/questions/19674740/opengl-es2-premultiplied-vs-straight-alpha-blending#23256585 https://developer.nvidia.com/content/alpha-blending-pre-or-not-pre

Conversely, this is too light:

glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_COLOR, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
screen shot 2017-05-12 at 9 58 14 pm

There are other inputs to the block shader, could they have an unintended effect? None of the uniforms need to be set or rather changed in render_cover() from render_chunks():

    /*
    glUniform1i(attrib->sampler, 0);
    glUniform1f(attrib->timer, time_of_day());
    glUniform3f(attrib->camera, s->x, s->y, s->z);
    glUniform1i(attrib->extra1, 2); // sky_sampler
    glUniform1f(attrib->extra2, get_daylight()); // daylight
    glUniform1f(attrib->extra3, g->render_radius * CHUNK_SIZE); // fog_distance
    glUniform1i(attrib->extra4, g->ortho); // ortho
    */

shaders/block_fragment.glsl:

    color = mix(color, sky_color, fog_factor);
    gl_FragColor = vec4(color, 1.0);
satoshinm commented 7 years ago

Magenta-discarding is in shaders/block_fragment.glsl:

    if (color == vec3(1.0, 0.0, 1.0)) {
        discard;
    }

but if 0x7f7f7f is exactly transparent.. note this is not 0.5, but 127 / 255 = 0.4980392156862745... TrueCraft sets TransparentEffect.ReferenceAlpha = 127, ReferenceAlpha documentation: "Specifies a reference alpha value against which pixels are tested when alpha testing is enabled. The default value is 0.". Alpha test in OpenGL: http://www.glprogramming.com/red/chapter10.html - "GL_GREATER Accept fragment if fragment alpha > reference alpha". This appears decent:

    if (color == vec3(127.0/255.0, 127.0/255.0, 127.0/255.0)) {
        discard;
    }

but then there are holes in stone:

screen shot 2017-05-12 at 10 23 21 pm

might as well change the texture to magenta for discard.

satoshinm commented 7 years ago
screen shot 2017-05-12 at 10 29 41 pm
satoshinm commented 7 years ago

Here's the new look (player can still change by drag-and-drop other texture atlas png):

screen shot 2017-05-12 at 11 01 46 pm screen shot 2017-05-12 at 11 00 08 pm

satoshinm commented 7 years ago

I made the changes to Pixeludi, but then, found referenced from https://github.com/traverseda/pycraft/issues/60 another pack: "Piehole", CC-BY: http://piehole.alexvoelk.de - it looks good, too, nice and clean. Saving here in case want to use it later (need to convert textures cutting & pasting 16x16 segments by hand - no real "texture pack" parsing support: https://github.com/satoshinm/NetCraft/issues/113), but this is piehole-pattern/terrain.png:

terrain

and piehold-plain/terrain.png:

terrain

and pixeludi from truecraft terrain.png https://github.com/SirCmpwn/TrueCraft/blob/7f0e3338d231b8a8f7fba35742b618a4fb3575bf/TrueCraft.Client/Content/terrain.png:

terrain