-
Notifications
You must be signed in to change notification settings - Fork 536
Authoring an Effect
This lesson covers writing your own IEffect implementation, specifically a custom effect for rendering a skybox with a cubemap.
First create a new project using the instructions from the previous lessons: Using DeviceResources and Adding the DirectX Tool Kit which we will use for this lesson.
A skybox is a shape like a sphere or a cube that surrounds the render scene giving the appearance of the distant sky, horizon, and/or surroundings. In our implementation we are going to be using a cubemap (i.e. 6-faced texture) to provide the texture information on the sky. For the geometry, we'll make use of GeometricPrimitive, and the shaders we are using for the SkyboxEffect are as follows:
cbuffer SkyboxConstants : register(b0)
{
float4x4 WorldViewProj;
}
struct VSOutput
{
float3 TexCoord : TEXCOORD0;
float4 PositionPS : SV_Position;
};VSOutput main(float4 position : SV_Position)
{
VSOutput vout;
vout.PositionPS = mul(position, WorldViewProj);
vout.PositionPS.z = vout.PositionPS.w; // Draw on far plane
vout.TexCoord = position.xyz;
return vout;
}TextureCube<float4> CubeMap : register(t0);
SamplerState Sampler : register(s0);
float4 main(float3 texCoord : TEXCOORD0) : SV_TARGET0
{
return CubeMap.Sample(Sampler, normalize(texCoord));
}UNDER CONSTRUCTION
UNDER CONSTRUCTION
UNDER CONSTRUCTION
Next lessons: Using HDR rendering
All content and source code for this package are subject to the terms of the MIT License.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Windows 8.1
- Xbox One
- x86
- x64
- ARM64
- Visual Studio 2026
- Visual Studio 2022 (17.12 or later)
- clang/LLVM v12 - v21
- MinGW 14.2, 15.2, 16.1
- CMake 3.21