## How to calculate Tangent and Binormal?

The relevant input data to your problem are the texture coordinates. Tangent and Binormal are vectors locally parallel to the object’s surface. And in the case of normal mapping they’re describing the local orientation of the normal texture. So you have to calculate the direction (in the model’s space) in which the texturing vectors point. … Read more

## How to express tetration function, for complex numbers

well lets start with Real domain and integer b only: a^^b = a^a^a^a^a…^a // a is there b times this can be evaluated like this in C++: double tetration(double a,int b) // a^^b = a^a^a^a… b times { double c; if (b<=0) return 0; for (c=a;b>1;b–) c=pow(a,c); return c; } as You already got the … Read more

## How to use Pivot Point in Transformations

If you have to following rectangle, where the red cross is the center of the world and you want to rotate it around the green pivot then you’ve to do the following steps: Translate the rectangle in that way that way, that the pivot is on the origin of the world. This is a translation … Read more

## GCC, stringification, and inline GLSL?

Can you use C++11? If so you could use raw string literals: const GLchar* vert = R”END( #version 120 attribute vec2 position; void main() { gl_Position = vec4( position, 0.0, 1.0 ); } )END”; No need for escapes or explicit newlines. These strings start with an R (or r). You need a delimiter (I chose … Read more

## Why is the sprite not rendering in OpenGL?

You have to initialize the model matrix variable glm::mat4 model. The glm API documentation refers to The OpenGL Shading Language specification 4.20. 5.4.2 Vector and Matrix Constructors If there is a single scalar parameter to a vector constructor, it is used to initialize all components of the constructed vector to that scalar’s value. If there … Read more

## How to recover view space position given view space depth value and ndc xy

3 Solutions to recover view space position in perspective projection The projection matrix describes the mapping from 3D points of a scene, to 2D points of the viewport. It transforms from view (eye) space to the clip space, and the coordinates in the clip space are transformed to the normalized device coordinates (NDC) by dividing … Read more

Categories c++

## 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

## How to correctly linearize depth in OpenGL ES in iOS?

the problem is that you store non linear values which are truncated so when you peek the depth values later on you got choppy result because you lose accuracy the more you are far from znear plane. No matter what you evaluate you will not obtain better results unless: Lower accuracy loss You can change … 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

## GLSL fixed function fragment program replacement

You might be interested in having a look at ShaderGen. From the description: ShaderGen is a program that can automatically produce shaders that mimic the results of a set of fixed function state. This tool was used to verify the fixed function shader code that is described in Chapter 9. By the way, you will … Read more