- Home /
Question on Shader Function Return Values,Question on shader function return values
I'm following along a shader implementation of a certain specular calculation. Here's the function:
inline float3 ComputeSpecular( ... ) { float F, D, G;
// ---- Calculation of F, D, and G ----
// Calculates the specular as a scalar value
float specular = NdotL * D * F * G;
// But it returns a vector value
return specular;
}
So it returns a scalar in a vector-returning function. So what will the output look like? Will it simply be a vector of repeating values?,I'm following an implementation of a custom specular shader in Unity. It sort of goes like this:
inline float3 ComputeSpecular( ... )
{
float F, D, G;
// ---- Calculation of F, D, and G ----
// Calculates the specular as a scalar value
float specular = NdotL * D * F * G;
// But it returns a vector value
return specular;
}
So when we assign a scalar as the return value for a vector-calculating function, what does the actual output look like? Is it a simple vector with repeating values?
Answer by Bunny83 · Aug 29, 2018 at 01:34 PM
Yes, the scalar is simply used for each component. For reference the cg language specification. Search for "Type Conversions" and read the "Scalar conversions" section:
Scalar types may be implicitly converted to vectors and matrixes of compatible type. The scalar will be replicated to all elements of the vector or matrix. Scalar types may also be explicitly cast to structure types if the scalar type can be legally cast to every member of the structure.