Using an instance name with a uniform block

A uniform block can have an optional instance name. For example, with our BlobSettings block, we could have used the instance name Blob, as shown here:

uniform BlobSettings { 
  vec4 InnerColor; 
  vec4 OuterColor; 
  float RadiusInner; 
  float RadiusOuter; 
} Blob;

In this case, the variables within the block are placed within a namespace qualified by the instance name. Therefore, our shader code needs to refer to them prefixed with the instance name. For example:

FragColor =    mix( Blob.InnerColor, Blob.OuterColor,        smoothstep( Blob.RadiusInner, Blob.RadiusOuter, dist ) 
  ); 

Additionally, we need to qualify the variable names (with the BlobSettings block name) within the OpenGL code when querying for variable ...

Get OpenGL 4 Shading Language Cookbook - Third 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.