Own map with "magic marking" over TextureArray

I’m tinkering with my own map.

I still use basics, still no lighting effects. The exercises from the beginner’s documentation and here from the forum let me build a first presentable version.

The most important hint from Paul was: Use TextureArray for this task!
i’m still busy, the attempts without TextureArray to cut back.

At this point I would like to thank Paul and other for the quick answers here in the forum.

Video:

The heart of the marking is this snippet of code from the frag-shader:


    #if defined(HAS_MAGICMARKINDEX1) || defined(HAS_MAGICMARKINDEX2)
        vec4 worldPos = g_WorldMatrix  * vec4(position, 1.0);
        float rP;
        float rR;
        float reduction;
    #endif
    #if defined(HAS_MAGICMARKMAP) && defined(HAS_MAGICMARKINDEX1)
        float mark1_x=(m_MagicMarkPos1.x  - worldPos.x) / m_MagicMarkHalfSize1  ;
        float mark1_z=(m_MagicMarkPos1.z  - worldPos.z) / m_MagicMarkHalfSize1  ;
        float mark1_y=(m_MagicMarkPos1.y  - worldPos.y) / 2.0 ;
        rP = mark1_x*mark1_x + mark1_z*mark1_z;
        rR = rP + mark1_y*mark1_y;
        reduction = (rP > 0.0001) ? sqrt(rR/rP) : 1.0;
        // multiplication with reduction, 
        // because the faster out of the range [0, 1[ the smaller the image.
        mark1_x *= reduction;
        mark1_z *= reduction;
        vec3 mark1_texCoord = vec3(
            (mark1_x*m_MagicMarkCos1 - mark1_z*m_MagicMarkSin1)/2.0 + 0.5,
            (mark1_x*m_MagicMarkSin1 + mark1_z*m_MagicMarkCos1)/2.0 + 0.5,
            m_MagicMarkIndex1
        );
        vec4 mark1_color = (mark1_texCoord.x>=0.0 && mark1_texCoord.x<1.0 && mark1_texCoord.y>=0.0 && mark1_texCoord.y<1.0)
            ?texture2DArray(m_MagicMarkMap, mark1_texCoord)
            :vec4(0.0); 
        color =max(color,mark1_color*mark1_color.a + color*(1.0-mark1_color.a));
    #endif
    #if defined(HAS_MAGICMARKMAP) && defined(HAS_MAGICMARKINDEX2)
        float mark2_x=(m_MagicMarkPos2.x  - worldPos.x) / m_MagicMarkHalfSize2  ;
        float mark2_z=(m_MagicMarkPos2.z  - worldPos.z) / m_MagicMarkHalfSize2  ;
        float mark2_y=(m_MagicMarkPos2.y  - worldPos.y) / 2.0 ;
        rP = mark2_x*mark2_x + mark2_z*mark2_z;
        rR = rP + mark2_y*mark2_y;
        reduction = (rP > 0.0001) ? sqrt(rR/rP) : 1.0;
        // multiplication with reduction, 
        // because the faster out of the range [0, 1[ the smaller the image.
        mark2_x *= reduction;
        mark2_z *= reduction;
        vec3 mark2_texCoord = vec3(
            (mark2_x*m_MagicMarkCos2 - mark2_z*m_MagicMarkSin2)/2.0 + 0.5,
            (mark2_x*m_MagicMarkSin2 + mark2_z*m_MagicMarkCos2)/2.0 + 0.5,
            m_MagicMarkIndex2
        );
        vec4 mark2_color = (mark2_texCoord.x>=0.0 && mark2_texCoord.x<1.0 && mark2_texCoord.y>=0.0 && mark2_texCoord.y<1.0)
            ?texture2DArray(m_MagicMarkMap, mark2_texCoord)
            :vec4(0.0); 
        color =max(color,mark2_color*mark2_color.a + color*(1.0-mark2_color.a));
    #endif

The MaterialParameters are:


        TextureArray MagicMarkMap   //  Pictures
        Vector3 MagicMarkPos1       //  x-y-z in 3d space E.G.: shootables.collideWith(ray, results);
        Float MagicMarkIndex1       //  Index of Texture, clear Param == mark is off
        Float MagicMarkSin1         //  Rotate mark
        Float MagicMarkCos1         //  Rotate mark
        Float MagicMarkHalfSize1    //  Size / 2.0f
        Vector3 MagicMarkPos2       //  x-y-z in 3d space E.G.: shootables.collideWith(ray, results);
        Float MagicMarkIndex2       //  Index of Texture, clear Param == mark is off
        Float MagicMarkSin2         //  Rotate mark
        Float MagicMarkCos2         //  Rotate mark
        Float MagicMarkHalfSize2    //  Size / 2.0f
4 Likes

Addendum:

If I in the shader already retract the position in the 3d space, then the implementation of the nebulization is almost forced:

I just have to calculate the distance to the camera to know the intensity of the cloud. And since I also know “y”, I can represent the cloud as a gradient. Dark and somewhat moddy below, rather light gray above.

The heart of the fog is this snippet of code from the frag-shader:

    #if defined(HAS_FOG) || defined(HAS_MAGICMARKMAP) || defined(HAS_MAGICMARKINDEX1) || defined(HAS_MAGICMARKINDEX2)
        vec4 worldPos = g_WorldMatrix  * vec4(position, 1.0);
        float rP;
        float rR;
        float reduction;
    #endif

(…)


    #ifdef HAS_FOG
        float fog_x=  m_FogCamPos.x  - worldPos.x;
        float fog_z=  m_FogCamPos.z  - worldPos.z;
        float fog_y=  max(0.0,min(1.0, worldPos.y / m_FogTop));
        vec4 fog_color = m_FogStartColorUp*fog_y + m_FogStartColor0*(1.0-fog_y);
        rP = max(0.0, fog_x*fog_x + fog_z*fog_z - m_FogStartDistanceSqr);
        rR = min(1.0, rP / m_FogDistanceSqr); 
        color =fog_color*rR + color*(1.0-rR);
    #endif

The new MaterialParameters are:


        Vector3 FogCamPos           //  x-y-z camera position in 3d space, clear Param == fog is off
        Float FogStartDistanceSqr   //  Start distance ^2
        Color FogStartColor0        //  Start color on y == 0
        Float FogTop                //  y of FogStartColorUp
        Color FogStartColorUp       //  Start color on y == FogTop
        Float FogDistanceSqr        //  distance ^2
3 Likes

Claim:
But with the fog I could also implement LOD. Everything behind the fog just needs vertices. No texCoord. No color. And the shader would also be thin, without Textures:

        vec4 worldPos = g_WorldMatrix  * vec4(position, 1.0);

        float fog_y=  max(0.0,min(1.0, worldPos.y / m_FogTop));
        color = m_FogStartColorUp*fog_y + m_FogStartColor0*(1.0-fog_y);

Question: Is such a LOD solution for rooms behind the fog worthwhile ?