Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6007209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:38:55+00:00 2026-05-23T01:38:55+00:00

The application loads terrain elevation data into floating point textures. Textures are then rendered

  • 0

The application loads terrain elevation data into floating point textures. Textures are then rendered on a float color buffer (using *GL_ARB_color_buffer_float*).

The first pass is to get an overall texture (resulting from multiple textured quads rendering). To do this, I disable the color clamp, render each quad, and the copy the (float) frame buffer into a (float) texture: this texture is the base of multiple passes for processing the terrain elevation data.

There’s no problem in rendering the float texture data using false colors: indeed the terrain elevation information is preserved during the first pass (no color clamp).

I’m getting in trouble by computing the terrain normals. Here is a snipper of the fragment shader:

// Required shader language version (compatibility profile)
#version 150 compatibility

//---------------------------------------------------------------------------
// SYSTEM INPUTS/OUTPUT
//---------------------------------------------------------------------------

// Fragment texture coordinate (in)
in vec4 gl_TexCoord[];
// Fragment color (out)
vec4 gl_FragColor;

    // DTED elevation data as texture.
// Value fetched by the texture if the altitude of the terrain, in meters.
uniform sampler2D rdr_ElevationData;

// Obtain fragment elevation
float GetFragmentElevation(const vec2 texcoord)
{
    // This is OK! Tested with false colors
    return (texture(rdr_ElevationData, gl_TexCoord[0].st).r);
}

vec3 GetFragmentNormal(const vec2 texcoord, const float sOffset, const float tOffset)
{
    const vec2
        texcoordN  = texcoord + vec2( 0.0,      +tOffset),
        texcoordNE = texcoord + vec2(+sOffset,  +tOffset),
        texcoordE  = texcoord + vec2(+sOffset,   0.0),
        texcoordSE = texcoord + vec2(+sOffset,  -tOffset),
        texcoordS  = texcoord + vec2( 0.0,      -tOffset),
        texcoordSW = texcoord + vec2(-sOffset,  -tOffset),
        texcoordW  = texcoord + vec2(-sOffset,   0.0),
        texcoordNW = texcoord + vec2(-sOffset,  +tOffset);
    float TerrainAroundHeights[9];

    // Ensuring clamped texture coordinates
    clamp(texcoordN , 0.0, 1.0);
    clamp(texcoordNE, 0.0, 1.0);
    clamp(texcoordE , 0.0, 1.0);
    clamp(texcoordSE, 0.0, 1.0);
    clamp(texcoordS , 0.0, 1.0);
    clamp(texcoordSW, 0.0, 1.0);
    clamp(texcoordW , 0.0, 1.0);
    clamp(texcoordNW, 0.0, 1.0);
    // Fetch terrain heights around the fragment
    TerrainAroundHeights[0] = GetFragmentElevation(texcoord);
    TerrainAroundHeights[1] = GetFragmentElevation(texcoordN);
    TerrainAroundHeights[2] = GetFragmentElevation(texcoordNE);
    TerrainAroundHeights[3] = GetFragmentElevation(texcoordE);
    TerrainAroundHeights[4] = GetFragmentElevation(texcoordSE);
    TerrainAroundHeights[5] = GetFragmentElevation(texcoordS);
    TerrainAroundHeights[6] = GetFragmentElevation(texcoordSW);
    TerrainAroundHeights[7] = GetFragmentElevation(texcoordW);
    TerrainAroundHeights[8] = GetFragmentElevation(texcoordNW);

    const float NormalLength = 0.001;

    vec3 v0 = vec3(0.0, 0.0, 0.0), v1 = vec3(0.0, NormalLength, 0.0), v2 = vec3(NormalLength, 0.0, 0.0);

    // Compute averaged heights for each fragment corner
    /*v0.z = (TerrainAroundHeights[0] + TerrainAroundHeights[7] + TerrainAroundHeights[6] + TerrainAroundHeights[5]) / 4.0;
    v1.z = (TerrainAroundHeights[0] + TerrainAroundHeights[1] + TerrainAroundHeights[8] + TerrainAroundHeights[7]) / 4.0;
    v2.z = (TerrainAroundHeights[0] + TerrainAroundHeights[5] + TerrainAroundHeights[4] + TerrainAroundHeights[3]) / 4.0;*/

    // MY TESTS... unable to understand what's going on
    if (TerrainAroundHeights[0] < (TerrainAroundHeights[5]))
        v0.z = 1.0;
    return (v0);

    // Compute terrain normal
    return (normalize(cross(v2 - v0, v1 - v0)));
}

void main()
{
    ivec2 rdr_ElevationData_Size = textureSize(rdr_ElevationData, 0);       // Texture size, in textel
    vec3 frag_Normal;                                                       // Fragment normal
    float rdr_ElevationData_S_CoordStep = 1.0 / /*rdr_ElevationData_Size[0]*/ 672.0 /* Tried but not working... * 4.0 */;
    float rdr_ElevationData_T_CoordStep = 1.0 / /*rdr_ElevationData_Size[1]*/ 672.0 /* Tried but not working... * 4.0 */;

    // Determine fragment normal
    frag_Normal = GetFragmentNormal(gl_TexCoord[0].st, rdr_ElevationData_S_CoordStep, rdr_ElevationData_T_CoordStep);

            // Test purpose... (always 0.0!!!)
    gl_FragColor = vec4(frag_Normal.z, 0.0, 0.0, 1.0);
}

You can see in GetFragmentNormal, I try to get the elevation data from the neightboor textels, but the values of TerrainAroundHeights seems always equal!!!

Have I missed something huge? Is there a better way to fetch neightboor textel?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:38:55+00:00Added an answer on May 23, 2026 at 1:38 am

    You compute the offset texcoord in GetFragmentNormal and then pass it in to GetFragmentElevation, but then you don’t use it in the texture lookup — you use the original texcoord before adding the offset.

    float GetFragmentElevation(const vec2 texcoord)
    {
        // This is OK! Tested with false colors
        return (texture(rdr_ElevationData, gl_TexCoord[0].st).r);
    }
    

    So not too suprisingly, you get the same elevation regardless of the offset. Change that gl_TexCoord[0] to be texcoord instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application loads an XML data set from a file on disk using serialization,
When my application loads, using the didFinishLaunchingWithOptions i parse data from the internet to
My application loads lots of data from a database into a complex data structure.
What is the best way to remember the Windows position between application loads using
My application loads a data set of approx. 85bm to 100mb each time. The
I am using an UIDatePicker in my application. When the application loads up, the
When an ASP.NET application loads, are application config settings loaded into memory or read
I'm running an application on my iPad that loads images into a carousel. In
I've launched wampserver using vb.net when the application loads. My problem is, how do
Hi I am using an NSTreeController to control an NSOutlineView. This application loads bookmarks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.