Sign in to follow this  

GLSL Fragment Shader Gridlines on heightmapped terrain

This topic is 1842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all!

In short:

I have a heightmapped terrain, which has had its y value offset in the vertex shader.

Now I am looking to draw gridlines over the terrain, in the fragment shader.

I am able to sample colour from the heightmap texture in the fragment shader.

This what I've been attempting, but no luck. The idea is that the terrain is white, gridlines are black.

Terrain width is 1024. So is the texture.

Could somebody please suggest a method of testing whether the texture coord components, x, and y, are divisible by some number? and changing the pixel colour.

With this code I only get white terrain. :/


[CODE]
uniform sampler2D hmap_texture;
in vec2 texCoord;
layout (location=0) out vec4 fragColour;

void main(void) {
//vec4 colour = texture2D(hmap_texture, texCoord);
vec4 colour = vec4(1.0, 1.0, 1.0, 1.0);

if( mod(texCoord.x, 32) == 0) {
colour = vec4(0.0, 0.0, 0.0, 1.0)
}

if( mod(texCoord.y, 32) == 0) {
colour = vec4(0.0, 0.0, 0.0, 1.0)
}

fragColour = colour;
}
[/CODE]

Many thanks.
Nathan

Share this post


Link to post
Share on other sites
Also, texCoord is likely a float, so you should try copying the data into an integer before using mod. There are debuggers for shaders provided by nvidia or amd that may help you solve this problem.

Share this post


Link to post
Share on other sites
Thanks, I did try something along the lines of this before but it was a bit hashed - very good point about using intergers with modulo though! That's something I hadn't thought of :)

I'm away from a real GFX card at the mo but I'll try this in a few hours and get back to you :)

Share this post


Link to post
Share on other sites
I took so long to reply! Many apologies my learned freind!

I got the Mod function working by multipling the vertexCoord * WIDTH, essentially. Thank you!

I now have a new question about this, but it's off this topic, so I'm off to start a new thread..

Share this post


Link to post
Share on other sites

This topic is 1842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this