Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


GLSL Fragment Shader Gridlines on heightmapped terrain


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 mynameisnafe   Members   -  Reputation: 252

Like
0Likes
Like

Posted 25 November 2012 - 12:04 PM

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. :/


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;
}

Many thanks.
Nathan

Sponsor:

#2 valles   Members   -  Reputation: 172

Like
2Likes
Like

Posted 25 November 2012 - 12:48 PM

Texture coordinates in opengl are from 0 to 1, so you're going to need to divide texCoord by 1024 to get your texture2D to work.

#3 valles   Members   -  Reputation: 172

Like
2Likes
Like

Posted 25 November 2012 - 12:52 PM

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.

#4 mynameisnafe   Members   -  Reputation: 252

Like
0Likes
Like

Posted 25 November 2012 - 04:12 PM

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 :)

#5 mynameisnafe   Members   -  Reputation: 252

Like
0Likes
Like

Posted 28 November 2012 - 09:50 AM

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..




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS