Direct3D (DirectX 9.0) Code Samples - Page 9

Simple Vertex Shader (Cg)
 

Demonstrates how to write a simple vertex shader, or vertex program using Cg. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant Keywords: CGcontext, CGprogram, CGparameter, cgCreateContext, cgD3D9GetLatestVertexProfile, cgCreateProgramFromFile, cgD3D9ValidateVertexDeclaration, cgD3D9LoadProgram, cgGetNamedParameter, cgGetParameterType, cgD3D9TypeToSize, cgD3D9SetDevice, cgDestroyProgram, cgDestroyContext, cgD3D9SetUniformMatrix, cgD3D9SetUniform, cgD3D9BindProgram, CreateVertexDeclaration, LPDIRECT3DVERTEXDECLARATION9, LPDIRECT3DVERTEXDECLARATION9, POSITION, COLOR0, uniform, float4x4, float4, mul, and return.

 

Simple Vertex & Pixel Shader (Cg)
 

Demonstrates how to write both a simple vertex and pixel shader using Cg. The two shaders have matching connectors and can be used simultaneously on the same piece of geometry. The shaders in this sample don't really do anything useful or neat, it's meant to be used as a framework or starting place for experimenting with shaders. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant Keywords: cgD3D9GetLatestPixelProfile, cgD3D9GetOptimalOptions, cgD3D9SetTextureWrapMode, cgD3D9SetSamplerState, cgD3D9BindProgram, D3DXMatrixTranspose, D3DXMatrixRotationYawPitchRoll, D3DVERTEXELEMENT9, D3DDECLTYPE_FLOAT3, D3DDECLUSAGE_POSITION, D3DDECLTYPE_D3DCOLOR, D3DDECLUSAGE_COLOR, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, D3DSAMP_ADDRESSUD3DSAMP_ADDRESSV, D3DTADDRESS_WRAP, D3DTEXF_POINT, D3DTEXF_NONE, D3DSAMP_MINFILTER, D3DSAMP_MAGFILTER, D3DSAMP_MIPFILTER, float2, float3, float4, uniform, float4x4, sampler2D, and tex2D.

 

Lighting Shader (Cg)
 

Demonstrates how to write a vertex shader using Cg, which calculates simple diffuse lighting for a single light source. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant Keywords: cgD3D9SetUniformMatrix, cgD3D9SetUniform, SetLight, SetRenderState, LightEnable, SetMaterial, D3DLIGHT9, D3DMATERIAL9, D3DRS_LIGHTING, LPDIRECT3DVERTEXDECLARATION9, POSITION, NORMAL, COLOR0, float4, float4x4, uniform, mul, normalize, dot, and pow.

 

Anisotropic Lighting Shader (Cg)
 

Demonstrates how to write a vertex shader using Cg, which calculates Anisotropic Lighting for a single light source. The shader uses a texture as a look-up table for the correct Anisotropic Lighting values by storing the pre-calculated diffuse values in the texture's RGB components and specular values in its alpha component. This style of lighting is very useful for rendering surfaces like brushed steel where the surface is composed of micro facets or microscopic scratches that tend to lay parallel or run in the same direction. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant Keywords: D3DXLoadMeshFromX, GetVertexBuffer, GetIndexBuffer, CloneMeshFVF, Optimize, GetAttributeTable, LPDIRECT3DVERTEXDECLARATION9, LPDIRECT3DINDEXBUFFER9, D3DXATTRIBUTERANGE, D3DXMESH_SYSTEMMEM, D3DXMESHOPT_ATTRSORT, D3DXMESH_WRITEONLY, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR, D3DTOP_MODULATE4X, D3DTA_ALPHAREPLICATE, D3DTSS_COLOROP, D3DTSS_COLORARG1, D3DTSS_COLORARG2, D3DTA_TEXTURE, POSITION, NORMAL, TEXCOORD0, float3x3, float3x4, normalize, mul, and max.

 

Vertex Displacement or Mesh Deformation Shader (Cg)
 

Demonstrates how to performs vertex displacement on a simple mesh to create a flag waving animation. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant Keywords: CGcontext, CGprogram, CGparameter, cgCreateContext, cgD3D9GetLatestVertexProfile, cgCreateProgramFromFile, cgD3D9ValidateVertexDeclaration, cgD3D9LoadProgram, cgGetNamedParameter, cgGetParameterType, cgD3D9TypeToSize, cgD3D9SetDevice, cgDestroyProgram, cgDestroyContext, cgD3D9SetUniformMatrix, cgD3D9SetUniform, cgD3D9BindProgram, CreateVertexDeclaration, SetRenderState, D3DRS_FILLMODE, D3DFILL_WIREFRAME, D3DFILL_SOLID, LPDIRECT3DVERTEXDECLARATION9, LPDIRECT3DVERTEXDECLARATION9, POSITION, COLOR0, uniform, float4x4, float4, mul, sin, and return.