How to get world coordinates in vertex shader of a tile within a TileMap?

farfallefarfalle Posts: 2Member

I've tried using WORLD_MATRIX, but that appears to actually give me screen coordinates (unless I'm doing it wrong, which is possible -- I'm pretty new at this). I'm using 2.1.4.

Thanks in advance!


  • NightAvailNightAvail Posts: 2Member

    Not sure if this applies as I use 3.0, however I set the following in the vertex shader.

    world_pos = (WORLD_MATRIX * vec4(VERTEX, 1.0)).xyz;

  • farfallefarfalle Posts: 2Member
    edited January 13

    Hmm, I'm still missing something. Do I need to do something extra to account for the camera?

    I set my vertex shader on the tiles to just this:
    VAR1 = WORLD_MATRIX * vec4(VERTEX, 1.0, 1.0); // I was using SRC_VERTEX before, but the result appears the same

    and my fragment shader is:
    COLOR.rgb = / 192.0;

    I've got a platformer type of 2D game, with the camera attached to the player as he moves around. Specifically the player is a scene with the top node is a KinematicBody2D and he has a child Camera2D node with anchor mode = drag center. Now when I move around the map, the top left corner of the screen is always black (r=g=0), the left edge is green (r=x=0 and g=y=1), the top is red (r=x=1 and g=y=0), fading to yellow on most of the screen (r=1, g=1) -- and the colors are constant on the screen, not on the tiles as they move around the screen.

  • MegalomaniakMegalomaniak Posts: 783Admin

    Note that multiplication order matters when dealing with matrices.

Sign In or Register to comment.