TMXLoader v0.5.0 released

Thank you. I’m glad you like it.

I’m now tring to figure out some graphics problems. There are two main problems here.

  1. Cracks appears when moving or zooming camera.
  2. The transparency.

About the cracks

The cracks looks like this.

I don’t really understand why it happens. I guess it is due to my shader. When moving the camera, inPosition in WorldViewProjection may be have some rounding error when calculate floating-point numbers.

code of tiled.vert

#import "Common/ShaderLib/GLSLCompat.glsllib"
#import "Common/ShaderLib/Instancing.glsllib"

attribute vec3 inPosition;
attribute vec2 inTexCoord;
attribute vec4 inColor;

varying vec2 texCoord;

void main(){
    #ifdef HAS_COLORMAP
        texCoord = inTexCoord;
    #endif

    vec4 modelSpacePos = vec4(inPosition, 1.0);

    gl_Position = TransformWorldViewProjection(modelSpacePos);
}

About the transparency problems

Look at the 2nd orthgonal maps I post.

I read this post again and again.

now it looks better.

But I still have some more problems. There is a screenshot of a straggered map that I didn’t post.

I think this it due to how I discard the fragcolor.

code of tiled.j3md

MaterialDef Tiled {

    MaterialParameters {
        Texture2D ColorMap
        Color Color (Color)
        Color TransColor
    }
    
    Technique {
        VertexShader GLSL100:   com/jme3/tmx/resources/Tiled.vert
        FragmentShader GLSL100: com/jme3/tmx/resources/Tiled.frag

        WorldParameters {
            WorldViewProjectionMatrix
            ViewProjectionMatrix
            ViewMatrix
        }

        RenderState {
            Blend Alpha
            FaceCull Off
            DepthWrite On
            DepthTest On
            ColorWrite On
        }
        
        Defines {
            HAS_COLORMAP : ColorMap
            HAS_COLOR : Color
            TRANS_COLOR: TransColor
        }
    }

}

code of tiled.frag

#import "Common/ShaderLib/GLSLCompat.glsllib"

#ifdef TRANS_COLOR
    uniform vec4 m_TransColor;
#endif

uniform vec4 m_Color;
uniform sampler2D m_ColorMap;

varying vec2 texCoord;

void main(){
    vec4 color = vec4(1.0);

    #ifdef HAS_COLORMAP
        color *= texture2D(m_ColorMap, texCoord);     
    #endif

    #ifdef TRANS_COLOR
        if(color.rgb == m_TransColor.rgb) {
            color.a = 0.;
        }
    #endif
    
    #ifdef HAS_COLOR
        color *= m_Color;
    #endif
    
    if (color.a < 0.01) {
    	discard;
    }
    
    gl_FragColor = color;
}

If I change the threshold to 0.5, it looks better for this map, but any other translucent objects with alpha < 0.5 will be discard.

Hope some one can help me…

1 Like