Skip to content

Latest commit

 

History

History
116 lines (69 loc) · 1.62 KB

dx-graphics-hlsl-return.md

File metadata and controls

116 lines (69 loc) · 1.62 KB
title description ms.assetid keywords topic_type api_name api_type ms.topic ms.date api_location
return Statement
A return statement signals the end of a function.
e6c097af-ba0b-4abc-8099-69882ced1e18
return Statement HLSL
apiref
return Statement
NA
reference
05/31/2018

return Statement

A return statement signals the end of a function.

return [value];

 

The simplest return statement returns control from the function to the calling program; it returns no value.

void main()
{
    return ;
}

However, a return statement can return one or more values. This example returns a literal value:

float main( float input : COLOR0) : COLOR0
{
    return 0;
}

This example returns the scalar result of an expression.

return  light.enabled = true ;

This example returns a four-component vector that is constructed from a local variable and a literal.

return  float4(color.rgb, 1) ;

This example returns a four-component vector that is constructed from the result that is returned from an intrinsic function, together with literal values.

float4 func(float2 a: POSITION): COLOR
{
    return float4(sin(length(a) * 100.0) * 0.5 + 0.5, sin(a.y * 50.0), 0, 1);
}

This example returns a structure that contains one or more members.

float4x4 WorldViewProj;

struct VS_OUTPUT
{
    float4 Pos  : POSITION;
};

VS_OUTPUT VertexShader_Tutorial_1(float4 inPos : POSITION )
{
    VS_OUTPUT out;
    out.Pos = mul(inPos, WorldViewProj );
    return out;
};

See also

Functions (DirectX HLSL)