book
OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition
by Dave Shreiner, Graham Sellers, John M. Kessenich, Bill M. Licea-Kane
March 2013
Intermediate to advanced
984 pages
26h 18m
English
Content preview from OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth EditionBecome an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
Start your free trial



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] ...