1

So, I want to make scene same to this Sphere Scene

enter image description here

Now I have mesh with random generation as a ground and a sphere. But I dont't know how to cull off spheres geometry above mesh. Tried to use Stencil, and hightmap. Stencil rendered ground in front, but sphere above ground is still rendered. Using heightmap, to get know if it needs to render (I compared height map and worldPos) is problematic, because the texture is superimposed over the all sphere, and not projected onto it. Can you help. Is there any shader function to cull off all above mesh.

2 Answers 2

0

I did something similar for an Asteroids demo a few years ago. Whenever an asteroid was hit, I used a height map - really, just a noise map - to offset half of the vertices on the asteroid model to give it a broken-in-half look. For the other half, I just duplicated the asteroid model and offset the other half using the same noise map. The effect is that the two "halves" matched perfectly.

Here's what I'd try:

  1. Your sphere model should be a complete sphere.
  2. You'll need a height map for the terrain.
  3. In your sphere's vertex shader, for any vertex north of the equator:
    • Sample the height map.
    • Set the vertex's Y coordinate to the height from the height map. This will effectively flatten the top of the sphere, and then offset it based on your height map. You will likely have to scale the height value here to get something rational.
    • Transform the new x,y,z as usual.

Note that you are not texturing the sphere. You're modifying the geometry. This needs to happen in the geometry part of the pipeline, not in the fragment shader.

The other thing you'll need to consider is how to add the debris - rocks, etc. - so that it matches the geometry offset on the sphere. Since you've got a height map, that should be straightforward.

To start with, I'd just get your vertex shader to flatten the top half of the sphere. Once that works, add in the height map.

For this to look convincing, you'll need a fairly high-resolution sphere and height map. To cut down on geometry, you could use a plane for the terrain and a hemisphere for the bottom part. Just discard any fragment for the plane that is not within the spherical volume you're interested in. (You could also use a circular "plane" rather than a rectangular plane, but getting the vertices to line up with the sphere and filling in holes at the border can be tricky.)

2
  • tried again with heightmap, but it's awful. Any tips how to use heightmap, made from mesh and texture renderer?
    – Artromskiy
    Commented Feb 19, 2020 at 17:10
  • @Artromskiy Please don't post code in a comment. It's illegible.
    – 3Dave
    Commented Feb 19, 2020 at 17:19
0

As I realised, there's no standard way to cull it without artifacts. The only way it can be done is using raymarching rendering.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.