Get (world space) height in shader

Discussion in 'Modding' started by Przemek_kondor, Feb 20, 2019.

  1. Hi,
    I'm trying to change color of pixel (fragment) depending on its height above the ground (e.g. the higher above the ground the brighter would be a pixel).
    In order to achieve that first I need to calculate/get vertex position in world space:
    worldPos = worldMatrix * gl_Vertex

    The vertex shader (e.g. Cossacks 3\data\shaders\obj\ has:
    • (in-built) gl_Vertex - position of a vertex in object space
    • (in-built) gl_ModelViewMatrix - combined world (so called "model") and camera matrix
    • custom cameraMVM - I'm assuming it's just camera matrix (w/o world transformations)

    Since there's no world matrix attribute passed (btw1: is there a way to do so?) I tried to get it this way:
    uniform mat4 cameraMVM;
    varying float worldPos;

    void main()
    mat4 cameraMVMInverted = inverse(cameraMVM);
    mat4 worldMatrix = gl_ModelViewMatrix * cameraMVMInverted;
    worldPos = worldMatrix * gl_Vertex;

    but I don't get anything sane in worldPos
    Anyone know how to get such position (in world space)
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice