Skyboxes
A common application of a texture cube is to map the texture cube around camera to a skybox,box or a sphere, and to create a visual view of the scene environment. Listing 8.1 lists a skybox effect code.
List 8.1 skybox.fx
/************* Resources *************/cbuffer Cbufferperobject {float4x4 worldviewprojection:worldviewprojectio N < string uiwidget= "None";
>;
} texturecube skyboxtexture < string uiname = "Skybox texture";
String resourcetype = "3D";
>;
Samplerstate Trilinearsampler {Filter = min_mag_mip_linear;};
Rasterizerstate disableculling {cullmode = NONE;
/************* Data Structures *************/struct Vs_input {float4;};
struct Vs_output {float4 position:sv_position;
FLOAT3 Texturecoordinate:texcoord;
};
/************* Vertex Shader *************/vs_output vertex_shader (vs_input in) {vs_output out = (vs_output) 0; Out. Position = Mul (in.
Objectposition, worldviewprojection); Out. Texturecoordinate = in.
Objectposition;
return out; }/************* Pixel Shader *************/float4 pixel_shader (vs_output in): Sv_target {return skyboxtexture.sa Mple (TrilinearsamplEr, in.
Texturecoordinate); }/************* Techniques *************/technique10 Main10 {pass P0 {SetVertexShader (
Vs_4_0, Vertex_shader ()));
Setgeometryshader (NULL);
SetPixelShader (Compileshader (Ps_4_0, Pixel_shader ()));
Setrasterizerstate (disableculling);
}
}