SimpleSample.fx
资源名称:Direct3D.rar [点击查看]
上传用户:junlon
上传日期:2022-01-05
资源大小:39075k
文件大小:4k
源码类别:
DirextX编程
开发平台:
Visual C++
- //--------------------------------------------------------------------------------------
- // File: SimpleSample.fx
- //
- // The effect file for the SimpleSample sample.
- //
- // Copyright (c) Microsoft Corporation. All rights reserved.
- //--------------------------------------------------------------------------------------
- //--------------------------------------------------------------------------------------
- // Global variables
- //--------------------------------------------------------------------------------------
- float4 g_MaterialAmbientColor; // Material's ambient color
- float4 g_MaterialDiffuseColor; // Material's diffuse color
- float3 g_LightDir; // Light's direction in world space
- float4 g_LightDiffuse; // Light's diffuse color
- texture g_MeshTexture; // Color texture for mesh
- float g_fTime; // App's time in seconds
- float4x4 g_mWorld; // World matrix for object
- float4x4 g_mWorldViewProjection; // World * View * Projection matrix
- //--------------------------------------------------------------------------------------
- // Texture samplers
- //--------------------------------------------------------------------------------------
- sampler MeshTextureSampler =
- sampler_state
- {
- Texture = <g_MeshTexture>;
- MipFilter = LINEAR;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- };
- //--------------------------------------------------------------------------------------
- // Vertex shader output structure
- //--------------------------------------------------------------------------------------
- struct VS_OUTPUT
- {
- float4 Position : POSITION; // vertex position
- float4 Diffuse : COLOR0; // vertex diffuse color (note that COLOR0 is clamped from 0..1)
- float2 TextureUV : TEXCOORD0; // vertex texture coords
- };
- //--------------------------------------------------------------------------------------
- // This shader computes standard transform and lighting
- //--------------------------------------------------------------------------------------
- VS_OUTPUT RenderSceneVS( float4 vPos : POSITION,
- float3 vNormal : NORMAL,
- float2 vTexCoord0 : TEXCOORD0 )
- {
- VS_OUTPUT Output;
- float3 vNormalWorldSpace;
- // Transform the position from object space to homogeneous projection space
- Output.Position = mul(vPos, g_mWorldViewProjection);
- // Transform the normal from object space to world space
- vNormalWorldSpace = normalize(mul(vNormal, (float3x3)g_mWorld)); // normal (world space)
- // Calc diffuse color
- Output.Diffuse.rgb = g_MaterialDiffuseColor * g_LightDiffuse * max(0,dot(vNormalWorldSpace, g_LightDir)) +
- g_MaterialAmbientColor;
- Output.Diffuse.a = 1.0f;
- // Just copy the texture coordinate through
- Output.TextureUV = vTexCoord0;
- return Output;
- }
- //--------------------------------------------------------------------------------------
- // Pixel shader output structure
- //--------------------------------------------------------------------------------------
- struct PS_OUTPUT
- {
- float4 RGBColor : COLOR0; // Pixel color
- };
- //--------------------------------------------------------------------------------------
- // This shader outputs the pixel's color by modulating the texture's
- // color with diffuse material color
- //--------------------------------------------------------------------------------------
- PS_OUTPUT RenderScenePS( VS_OUTPUT In )
- {
- PS_OUTPUT Output;
- // Lookup mesh texture and modulate it with diffuse
- Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV) * In.Diffuse;
- return Output;
- }
- //--------------------------------------------------------------------------------------
- // Renders scene
- //--------------------------------------------------------------------------------------
- technique RenderScene
- {
- pass P0
- {
- VertexShader = compile vs_1_1 RenderSceneVS();
- PixelShader = compile ps_1_1 RenderScenePS();
- }
- }