DirectX
| DXIL Opcode |
DXIL OpName |
Shader Model |
Shader Stages |
| 56 |
Dot4 |
6.0 |
() |
SPIR-V
Refract:
Description:
Refract
For the incident vector I and surface normal N, and the ratio of
indices of refraction eta, the result is the refraction vector. The
result is computed by
k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
if k < 0.0 the result is 0.0
otherwise, the result is eta * I - (eta * dot(N, I) +
sqrt(k)) * N
The input parameters for the incident vector I and the surface normal
N must already be normalized to get the desired results.
The type of I and N must be a scalar or vector with a floating-point
component type.
The type of eta must be a 16-bit or 32-bit floating-point scalar.
Result Type, the type of I, and the type of N must all be the same
type.
| Number |
Operand 1 |
Operand 2 |
Operand 3 |
Operand 4 |
72 |
<id>
I |
<id>
N |
<id>
eta |
|
Test Case(s)
Example 1
//dxc refract_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export float4 fn(float4 p1, float4 p2, float p3) {
return refract(p1, p2, p3);
}
HLSL:
Returns a refraction vector using an entering ray, a surface normal, and a refraction index.
Parameters
| Item |
Description |
i
|
[in] A floating-point, ray direction vector.
|
n
|
[in] A floating-point, surface normal vector.
|
?
|
[in] A floating-point, refraction index scalar.
|
Return Value
A floating-point, refraction vector. If the angle between the entering ray i and the surface normal n is too great for a given refraction index ?, the return value is (0,0,0).
Type Description
Minimum Shader Model
This function is supported in the following shader models.
See also
-
Intrinsic Functions (DirectX HLSL)
refractusing HLSL source inhlsl_intrinsics.hrefractSPIR-V target built-in in clang/include/clang/Basic/BuiltinsSPIRV.tdrefracttoCheckSPIRVBuiltinFunctionCallinclang/lib/Sema/SemaSPIRV.cpprefracttoEmitSPIRVBuiltinExprinCGBuiltin.cppclang/test/CodeGenHLSL/builtins/refract.hlslclang/test/CodeGenSPIRV/Builtins/refract.cclang/test/SemaHLSL/BuiltIns/refract-errors.hlslclang/test/SemaSPIRV/BuiltIns/refract-errors.cint_spv_refractintrinsic inIntrinsicsSPIRV.tdrefractlowering and map it toint_spv_refractinSPIRVInstructionSelector::selectIntrinsic.llvm/test/CodeGen/SPIRV/hlsl-intrinsics/refract.llDirectX
SPIR-V
Refract:
Description:
Refract
For the incident vector I and surface normal N, and the ratio of
indices of refraction eta, the result is the refraction vector. The
result is computed by
k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
if k < 0.0 the result is 0.0
otherwise, the result is eta * I - (eta * dot(N, I) +
sqrt(k)) * N
The input parameters for the incident vector I and the surface normal
N must already be normalized to get the desired results.
The type of I and N must be a scalar or vector with a floating-point
component type.
The type of eta must be a 16-bit or 32-bit floating-point scalar.
Result Type, the type of I, and the type of N must all be the same
type.
72
<id>
I
<id>
N
<id>
eta
Test Case(s)
Example 1
HLSL:
Returns a refraction vector using an entering ray, a surface normal, and a refraction index.
Parameters
Return Value
A floating-point, refraction vector. If the angle between the entering ray i and the surface normal n is too great for a given refraction index ?, the return value is (0,0,0).
Type Description
Minimum Shader Model
This function is supported in the following shader models.
See also
Intrinsic Functions (DirectX HLSL)