Drawing intersection line over terrain

I would like to intersect my terrain with an invisible plain and just render the intersection line.
The excellent FractScape does something like that (see the yellow line in the attached screenshot).

How would I go about creating such an effect?

Thanks,

Niels

203646--7506--$line_188.png

I used a projector to do that, using a small stripe for the texture, using repeat (as opposed to clamp) for the texture so it covers the entire terrain. In order to not repeat vertically, the texture is very tall (8x1024), entirely transparent except for the 1-pixel stripe in the middle. So theoretically you could see it repeat vertically if the terrain was tall enough. But it would have to be real tall. :wink:

–Eric

Thanks for the hint.
I cannot get it to work quite right though. What type of shader are you using on the texture? Any special parameters I should set on the projector component?

Thanks,

Niels

Theoretically, you might be able to use a LineRenderer with collision.contacts[×].point(s) to draw a line highlighting the intersection.

This one:

Shader "FX/Projector Solid" { 
	Properties {
		_MainTex ("Cookie", 2D) = "gray" { TexGen ObjectLinear }
	}

	Subshader {
		Pass {
			ZWrite Off
			Offset -1, -1

			Fog { Mode Off }
			AlphaTest Greater 0
			ColorMask RGB
			SetTexture [_MainTex] {
				combine texture, ONE - texture
				Matrix [_Projector]
			}
		}
	}
}

Can’t remember where I got that from…might have adapted it from the standard shader myself.

It’s orthographic, but other than that, I don’t think so.

–Eric

Thanks for all the help!

I’m still struggling to get it right though, I keep seeing weird artifacts. I have the impression I’m doing something wrong with the texture. My image is 8x1024, fully transparent except for a black 1px border and a 1px line in the middle.
I tried without the black border as well, but that doesn’t help either.

I must admit I don’t really understand what I’m doing with this, I’m mostly going by trial and error. Any further hints would be very welcome!

Thanks,

Niels

You wouldn’t want a border at all. What kind of artifacts?

–Eric

See attached image. This is with the 1px border. I’ll post what it looks like without the border in a minute.

204586--7543--$artifact_140.png

Here’s what it looks like without the border. Clearly better, but the line is not completely solid and the colors vary. Also, the line get’s repeated vertically (not visible in screenshot). Should I perhaps attach my projector to the camera?

Also, unlike in Fractscape, the line doesn’t bend to follow the terrain…

204590--7544--$artifact2_187.png

Might need to make the orthographic size larger.

Nope, then it will project from the camera’s position, which would be wrong.

I used point filtering for the texture so it doesn’t get smeared by bilinear filtering.

–Eric

Ah, much better! Thanks!

Hi

I did this a year ago or something, so I don’t really remember how I did it (and I don’t have the project here), but I will try.

  1. Make a projector facing down, the orthographic size should be as large as the terrain, the shader should be the “Projector Additive” which can be found on the wiki.

  2. Create a gradient texture going from black to white (middle) and back to black again, then assign it as the falloff, make sure “border mipmaps” is on.

  3. Assign a 1*1 px texture as the cookie/main texture.

  4. The last thing is that you need to change the clip values. Near clip should be set to zero or a quite small value, far clip should be set to the height/width you want the line to be, i.e quite small too.

And that’s it, hope it helps.

Hi

I did this a year ago or something, so I don’t really remember how I did it (and I don’t have the project here), but I will try.

  1. Make a projector facing down, the orthographic size should be as large as the terrain, the shader should be the “Projector Additive” which can be found on the wiki.

  2. Create a gradient texture going from black to white (middle) and back to black again, then assign it as the falloff, make sure “border mipmaps” is on.

  3. Assign a 1*1 px texture as the cookie/main texture.

  4. The last thing is that you need to change the clip values. Near clip should be set to zero or a quite small value, far clip should be set to the height/width you want the line to be, i.e quite small too.

And that’s it, hope it helps.

could do it with an overlaid shader in the renderer that you pass a ‘contourheight’ parameter to and where the shader only draws itself if it’s near that height. Something like

Shader "Contour Line" {
	Properties {
		_Color ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
		_ContourHeight ("Contour Altitude", float) = 3.0
		_ContourThickness ("Contour Thickness", float) = 3.0
	}
	
	SubShader {
		Tags { "RenderType" = "Opaque" }
		Cull Off
		Lighting Off
		CGPROGRAM
		#pragma surface surf Lambert 
		
		uniform float4 _Color;
		 
		uniform float _ContourHeight;
		uniform float _ContourThickness;
		
		
		struct Input {
			float3 worldPos;
		};
		
		void surf (Input IN, inout SurfaceOutput o) {     
			float d = abs(IN.worldPos.y-_ContourHeight);
			clip(_ContourThickness-d);
			//clip(-(con);
			//clip (d-_ContourThickness);
			o.Albedo = _Color;
		}
		ENDCG
	} 
	
	
Fallback "Particles/Alpha Blended"
}

works ok for me