Marble

Yet another variation on the noise function is to use it as part of a periodic function such as sine. By adding noise to the input value for the sine function, we get a “noisy” oscillating function. We use this to create a look similar to the alternating color veins of some types of marble. Example 8.19 shows the fragment shader to do it. Again, we use the same vertex shader. Results of this shader are also shown in Figure 8.27.

Example 8.19. Fragment Shader for Marble

#version 330 coreuniform sampler3D Noise;uniform vec3 MarbleColor;uniform vec3 VeinColor;in float LightIntensity;in vec3  MCposition;out vec4 FragColor;void main(){   vec4 noisevec = texture(Noise, MCposition);   float intensity = abs(noisevec[0] ...

Get OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.