Skip to Content
Real-Time 3D Graphics with WebGL 2 - Second Edition
book

Real-Time 3D Graphics with WebGL 2 - Second Edition

by Farhad Ghayour, Diego Cantor
October 2018
Intermediate to advanced
500 pages
12h 40m
English
Packt Publishing
Content preview from Real-Time 3D Graphics with WebGL 2 - Second Edition

No More gl_FragColor

While in GLSL 100 you'd ultimately render the color of the pixel by setting the gl_FragColor inside of the fragment shader, in GLSL 300 ES, you simply expose a value from your fragment shader. Consider, for example, the following in GLSL 100:

void main(void) {  gl_FragColor = vec4(1.0, 0.2, 0.3, 1.0);}

This would be updated by setting a defined custom output variable, as follows:

out vec4 fragColor; void main(void) {  fragColor = vec4(1.0, 0.2, 0.3, 1.0);}

It's important to note that even though we declared a variable called fragColor, you can choose any name not starting with the prefix gl_, due to ambiguity. Throughout this book, we have defined this custom variable as fragColor.

Become 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,
and much more.
Start your free trial

You might also like

WebGL Programming Guide: Interactive 3D Graphics Programming with WebGL

WebGL Programming Guide: Interactive 3D Graphics Programming with WebGL

Kouichi Matsuda, Rodger Lea
3D Graphics Rendering Cookbook

3D Graphics Rendering Cookbook

Sergey Kosarevsky, Viktor Latypov

Publisher Resources

ISBN: 9781788629690Supplemental Content