Material on vertical polygon

Hi,

Cesium version: 1.131

I try to create a material for a vertical wall, but i am struggling with the correct way to define it, since whatever i try, i am just getting stripes on it. Worth to mention is, i am using a vertical polygon, so a Cesium primitive to assign the material.
The polygon is coming from GeoJSON like this:

{

        type: 'Feature',
        geometry: {
          type: 'Polygon',
          coordinates: [
            [
              [4.725512471801164, 50.88101331210589, 34.04014368685602],
              [4.725513347194739, 50.8810129046137, 42.76989201868262],
              [4.725652873658409, 50.880958198909866, 42.71970368259534],
              [4.725654056530405, 50.88095773512771, 33.74971261545709],
              [4.725512471801164, 50.88101331210589, 34.04014368685602],
            ],
          ],
        },
        properties: {
          materialType: 'greenwall',
        }
}

What i have so far is:

primitive.appearance.material = new Material({

      translucent: false,

      fabric: {

        type: 'GreenWall',

        uniforms: {

          leafColorDark: new Color(0.1, 0.35, 0.1, 1.0),

          leafColorLight: new Color(0.4, 0.8, 0.3, 1.0),

          redPlantDark: new Color(0.5, 0.15, 0.08, 1.0),

          redPlantLight: new Color(0.8, 0.3, 0.15, 1.0),

          scale: new Cartesian2(8.0, 3.0),

        },

        source: `

          // Simple noise function

          float hash(vec2 p) {

            return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);

          }

          float noise(vec2 p) {

            vec2 i = floor(p);

            vec2 f = fract(p);

            f = f * f * (3.0 - 2.0 * f);

            float a = hash(i);

            float b = hash(i + vec2(1.0, 0.0));

            float c = hash(i + vec2(0.0, 1.0));

            float d = hash(i + vec2(1.0, 1.0));

            return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);

          }

          czm_material czm_getMaterial(czm_materialInput materialInput) {

            czm_material material = czm_getDefaultMaterial(materialInput);

            vec2 st = materialInput.st;

            // Texture coordinates for detail

            vec2 texSt = vec2(st.x * scale.x, st.y * scale.y);

            // High frequency noise for plant detail

            float n1 = noise(texSt * 3.0);

            float n2 = noise(texSt * 7.0);

            float n3 = noise(texSt * 15.0);

            // Combine noise layers for both detail and plant type variation

            float detail = n1 * 0.5 + n2 * 0.3 + n3 * 0.2;

            float plantType = detail; // Use same noise for plant type

            // Define colors

            vec3 green1 = leafColorDark.rgb;

            vec3 green2 = leafColorLight.rgb;

            vec3 red1 = redPlantDark.rgb;

            vec3 red2 = redPlantLight.rgb;

            vec3 mix1 = vec3(0.15, 0.4, 0.12);

            vec3 mix2 = vec3(0.65, 0.8, 0.45);

            // Selectors based on noise (creates organic patches)

            float isRed = smoothstep(0.3, 0.5, plantType);

            float isMix = smoothstep(0.65, 0.8, plantType);

            // Choose color pair

            vec3 c1 = mix(green1, red1, isRed);

            c1 = mix(c1, mix1, isMix);

            vec3 c2 = mix(green2, red2, isRed);

            c2 = mix(c2, mix2, isMix);

            // Mix colors based on noise

            vec3 plantColor = mix(c1, c2, smoothstep(0.2, 0.8, plantType));

            // Add shadow variation

            float shadow = noise(texSt * 5.0 + 10.0);

            plantColor *= 0.75 + 0.25 * shadow;

            // Lighting

            vec3 normal = normalize(materialInput.normalEC);

            vec3 lightDir = normalize(czm_sunDirectionEC);

            float diffuse = max(dot(normal, lightDir), 0.3);

            material.diffuse = plantColor * diffuse;

            material.specular = 0.05;

            material.shininess = 3.0;

            material.alpha = 1.0;

            return material;

          }

        `,

      },

    });

But i always receive something like that here:

Applying the same material to a horizontal polygon, lying on the ground for instance works. So i assume it has something to do with the z-coordinates and not handling them correctly.
Has someone an idea on how to tackle that?

BR Thomas

Hi @Thomas_Adolphi ,

Thanks for your post and for being part of the Cesium community.

I believe this approach ends up projecting or draping the texture onto the polygon top down from above. You can see in this example of a bent polygon the face with steeper/ more vertical slope has more distortion.

One alternative is you could author your polygon in modeling software as a glTF, add the texture to the model, and then import it it into the scene. Would that be a possible alternative to defining your polygon and texture at runtime?

Thanks,
Luke

Hi Luke,

thanks for your reply and your example. That is actually what i thought so too. That it has something to do with the vertical polygon itself.
The basic idea was to give the user the possibiity to draw a vertical wall in the scene directly and then let him choose the “material” or “look-like” of the wall. could be also bricks or something else.
So using an external modeling software could work, but was not the basic idea. But if it cannot be done by material, i do not see another option.

BR and happy XMas
Thomas

Hey @Thomas_Adolphi,

You say this works when the polygon is horizontal - can you post an image of what it’s supposed to look like?

This issue reminds me of this forum post. I think the answer might be the same - that you need to specify UV coordinates in your polygon for Cesium to know exactly how you want your texture applied (see my comment on that post and the sandcastle I linked).

Give that a try and let us know if it works or not!

Best,
Matt

Hi,

thanks for your reply. i will have a look on your post. Anyway here is, how it more or less should look like:
horizonzal polygon:

here is how it look like on a vertical polygon (material is exactly the same. only polygon changed):

BR Thomas.