float rayleighDepth = ...
float mieDepth = ...
float3 wavelength4 = ...
float3 attenuation
attenuation[0] = exp(-rayleighDepth / wavelength4[0] - mieDepth);
attenuation[1] = exp(-rayleighDepth / wavelength4[1] - mieDepth);
attenuation[2] = exp(-rayleighDepth / wavelength4[2] - mieDepth);
float3 attenuation2 = exp(-rayleighDepth / wavelength4 - mieDepth);
Little HLSL question
The result should be equivalent, since division, subtraction, and exp are all operations that that are performed on the individual components of the vectors. The HLSL compiler should compile both to the same assembly (using vector operations), or at least when optimization is enabled.
Yes, but rayleighDepth and mieDepth are no vectors. Thats why I dont know if it is the same.
Would it be better to write rayleighDepth.xyz and mieDepth.xyz?
Would it be better to write rayleighDepth.xyz and mieDepth.xyz?
Quote:Original post by schupf
Yes, but rayleighDepth and mieDepth are no vectors. Thats why I dont know if it is the same.
It doesn't matter that they are not vectors. It's the same as in algebra, multiplication of a scalar and a vector is a vector with components of the original vector multiplied by the scalar, each one separately.
So in this HLSL code:
float3 vector = float3(1, 2, 3);float scalar = 0.5f;float3 result = vector * scalar;
The "result" variable will be equal to (0.5, 1, 1.5)
Quote:
Would it be better to write rayleighDepth.xyz and mieDepth.xyz?
Nope. These variables are float (scalars), they don't have x y z components.
Yes, your multiplication example sounds logical to me.
Without a doubt this would be the same:
Every component of vector wavelength4 is divided by rayleighDepth.
but my code
divides a scalar by a vector. Are you 100% sure that this doesnt mean "divide the sclara rayleighDepth by the first element of wavelength4"?
Is there a website which lists the arithmetic operator rules for vectors and scalars in HLSL?
Without a doubt this would be the same:
wavelength4 /rayleighDepth
Every component of vector wavelength4 is divided by rayleighDepth.
but my code
rayleighDepth / wavelength4
divides a scalar by a vector. Are you 100% sure that this doesnt mean "divide the sclara rayleighDepth by the first element of wavelength4"?
Is there a website which lists the arithmetic operator rules for vectors and scalars in HLSL?
Multiplication and division of a vector by a scalar is distributive, that's a mathematical rule.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement