How To: Create mesh, add color or texture, add lighting. (Just a hint!)

In my first entry to P3D Processing, I want to create a simple height field, z(x,y), cover it with a pattern or texture and add lighting. This would be the basis for hobby projects such as (1) a static background (e.g. golf putting green) or (2) a dynamic field for animating fluid wave motion.

My first attempt used beginShape(LINES) with vertex(x, y, z) value pairs based on a cosine curve to generate horizontal wave sample points then repeated vertically with slight phase-shifted versions. The x-direction samples are connected as are the y-direction points. It looks like this:

meshByLines

I made a feeble attempt to apply color (fill()) or texture with no success.

I'm looking for hints/tips on the simplest approach to produce an opaque surface I can spin off for other projects. Here are a couple of question(s) that come to mind:

  1. Should I use a different argument to beginShape() requiring a different sequence of vertex() calls? Or...

  2. A completely different approach? (I probably don't want to enter the GPU/shader jungle.)

Thanks for reading my wordy post.

Answers

  • edited May 2017 Answer ✓

    @bob97086 --

    Your approach makes sense, but your PShapes have no surface area (they are lines) so there is nothing to fill(). The easiest approach is to change to a tile strip, then use fill(). As you said, this requires altering your vertex sequence.

    For an example of using TRIANGLE_STRIP see the rendering loop used in this demo of random terrain generation by Shiffman:

    • 3D Terrain Generation with Perlin Noise

  • Great tip! The first 12m of this video was a big help.

    Thanks.

Sign In or Register to comment.