Translation of GLSL in C ++ float / vec3?

What does this line do exactly

ra.rgb * ra.w / max(ra.r, 1e-4) * (bR.r / bR); 

The part I got confused with is how to translate

 (bR.r / bR); 

A float divided by vec3? I want to translate this into C ++, but what is it that returns a float divided by all elements of a vector? etc.

(no access to the graphics card for verification?)

+8
c ++ glsl
source share
1 answer

This is an example of component separation, and it works as follows:

GLSL Specification 4.40 - 5.9 Expressions - Pages 101-102

If the main types in the operands do not match, then the transforms from section 4.1.10 "Implicit conversions" are used to create the corresponding types. [...] After conversion, the following cases are possible:

[...]

  • One operand is a scalar, and the other is a vector or matrix. In this case, the scalar operation is applied independently to each component of the vector or matrix, leading to the same vector or size matrix.

Given the expression:

  vv vec3 (bR.r / bR); ^ float 

The bR.r bR.r essentially advances to vec3 (bR.r, bR.r, bR.r) , and then the component separation is performed, which leads to vec3 (bR.r/bR.r, bR.r/bR.g, bR.r/bR.b) .

So this expression is equivalent to:

 vec3 (1.0, bR.r/bR.g, bR.r/bR.b) 
+4
source share

All Articles