Do conditional statements slow down shaders?

What is it about shaders that even potentially makes if statements performance problems? It has to do with how shaders get executed and where GPUs get their massive computing performance from. Separate shader invocations are usually executed in parallel, executing the same instructions at the same time. They’re simply executing them on different sets of … Read more

Passing a list of values to fragment shader

There are currently 4 ways to do this: standard 1D textures, buffer textures, uniform buffers, and shader storage buffers. 1D Textures With this method, you use glTex(Sub)Image1D to fill a 1D texture with your data. Since your data is just an array of floats, your image format should be GL_R32F. You then access it in … Read more

How does the calculation of the light model work in a shader program?

Lambertian reflectance model To model the reflection of light in computer graphics is used a Bidirectional reflectance distribution function (BRDF). BRDF is a function that gives the relation between the light reflected along an outgoing direction and the light incident from an incoming direction. A perfect diffuse surface has a BRDF that has the same … Read more

Is it possible to express “t” variable from Cubic Bezier Curve equation?

What you need is to search your cubic path and remember closest point. This can be done recursively with increasing precisions here small C++ GL example: //————————————————————————— double pnt[]= // cubic curve control points { -0.9,-0.8,0.0, -0.6,+0.8,0.0, +0.6,+0.8,0.0, +0.9,-0.8,0.0, }; const int pnts3=sizeof(pnt)/sizeof(pnt[0]); const int pnts=pnts3/3; //————————————————————————— double cubic_a[4][3]; // cubic coefficients void cubic_init(double *pnt) … Read more

Normal mapping gone horribly wrong

My bet is on the color setting/mixing in fragment shader… you are setting output color more then once If I remember correctly on some gfx drivers that do a big problems for example everything after the line color = vec4(brownColor * (texture(diffuseMap, fsCoords).rgb + 0.25), 1.0);//add a fixed base color (0.25), because its dark as … Read more