hlsl之ambient
最简单的hlsl。
effect code:
//-------------------------------------------------------------------------------------- // 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 float4 g_LightAmbient; // Light's diffuse color texture g_MeshTexture; // Color texture for meshfloat 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 Ambient : 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 spaceOutput.Position = mul(vPos, g_mWorldViewProjection);// Calc diffuse color Output.Ambient.rgb = g_MaterialAmbientColor * g_LightAmbient; Output.Ambient.a = 1.0f; // Just copy the texture coordinate throughOutput.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 diffuseOutput.RGBColor = tex2D(MeshTextureSampler, In.TextureUV) * In.Ambient;return Output; }//-------------------------------------------------------------------------------------- // Renders scene //-------------------------------------------------------------------------------------- technique RenderScene {pass P0{ VertexShader = compile vs_2_0 RenderSceneVS();PixelShader = compile ps_2_0 RenderScenePS(); } }
main source code:
//-------------------------------------------------------------------------------------- // File: SimpleSample.cpp // // Copyright (c) Microsoft Corporation. All rights reserved. //-------------------------------------------------------------------------------------- #include "DXUT.h" #include "DXUTgui.h" #include "DXUTmisc.h" #include "DXUTCamera.h" #include "DXUTSettingsDlg.h" #include "SDKmisc.h" #include "SDKmesh.h" #include "resource.h"//#define DEBUG_VS // Uncomment this line to debug D3D9 vertex shaders //#define DEBUG_PS // Uncomment this line to debug D3D9 pixel shaders //-------------------------------------------------------------------------------------- // Global variables //-------------------------------------------------------------------------------------- CModelViewerCamera g_Camera; // A model viewing camera CDXUTDialogResourceManager g_DialogResourceManager; // manager for shared resources of dialogs CD3DSettingsDlg g_SettingsDlg; // Device settings dialog CDXUTTextHelper* g_pTxtHelper = NULL; CDXUTDialog g_HUD; // dialog for standard controls CDXUTDialog g_SampleUI; // dialog for sample specific controls// Direct3D 9 resources ID3DXFont* g_pFont9 = NULL; ID3DXSprite* g_pSprite9 = NULL; ID3DXEffect* g_pEffect9 = NULL; IDirect3DVertexDeclaration9* g_pVertDecl = NULL; // Vertex decl for the sample CDXUTXFileMesh g_Room; // Mesh representing room (wall, floor, ceiling) CDXUTXFileMesh g_Chair; // Mesh representing room (wall, floor, ceiling)//-------------------------------------------------------------------------------------- // UI control IDs //-------------------------------------------------------------------------------------- #define IDC_TOGGLEFULLSCREEN 1 #define IDC_TOGGLEREF 2 #define IDC_CHANGEDEVICE 3D3DVERTEXELEMENT9 g_aVertDecl[] = {{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },D3DDECL_END() }; //-------------------------------------------------------------------------------------- // Forward declarations //-------------------------------------------------------------------------------------- LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing,void* pUserContext ); void CALLBACK OnKeyboard( UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext ); void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext ); void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext ); bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, void* pUserContext );bool CALLBACK IsD3D9DeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat,bool bWindowed, void* pUserContext ); HRESULT CALLBACK OnD3D9CreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,void* pUserContext ); HRESULT CALLBACK OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,void* pUserContext ); void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ); void CALLBACK OnD3D9LostDevice( void* pUserContext ); void CALLBACK OnD3D9DestroyDevice( void* pUserContext );void InitApp(); void RenderText(); HRESULT LoadMesh( IDirect3DDevice9* pd3dDevice, LPCWSTR wszName, CDXUTXFileMesh& Mesh );//-------------------------------------------------------------------------------------- // Entry point to the program. Initializes everything and goes into a message processing // loop. Idle time is used to render the scene. //-------------------------------------------------------------------------------------- int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow ) {// Enable run-time memory check for debug builds. #if defined(DEBUG) | defined(_DEBUG)_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif// DXUT will create and use the best device (either D3D9 or D3D10) // that is available on the system depending on which D3D callbacks are set below// Set DXUT callbacks DXUTSetCallbackMsgProc( MsgProc );DXUTSetCallbackKeyboard( OnKeyboard );DXUTSetCallbackFrameMove( OnFrameMove );DXUTSetCallbackDeviceChanging( ModifyDeviceSettings );DXUTSetCallbackD3D9DeviceAcceptable( IsD3D9DeviceAcceptable );DXUTSetCallbackD3D9DeviceCreated( OnD3D9CreateDevice );DXUTSetCallbackD3D9DeviceReset( OnD3D9ResetDevice );DXUTSetCallbackD3D9DeviceLost( OnD3D9LostDevice );DXUTSetCallbackD3D9DeviceDestroyed( OnD3D9DestroyDevice );DXUTSetCallbackD3D9FrameRender( OnD3D9FrameRender );InitApp();DXUTInit( true, true, NULL ); // Parse the command line, show msgboxes on error, no extra command line paramsDXUTSetCursorSettings( true, true );DXUTCreateWindow( L"SimpleSample" );DXUTCreateDevice( true, 640, 480 );DXUTMainLoop(); // Enter into the DXUT render loopreturn DXUTGetExitCode(); }//-------------------------------------------------------------------------------------- // Initialize the app //-------------------------------------------------------------------------------------- void InitApp() {g_SettingsDlg.Init( &g_DialogResourceManager );g_HUD.Init( &g_DialogResourceManager );g_SampleUI.Init( &g_DialogResourceManager );g_HUD.SetCallback( OnGUIEvent ); int iY = 10;g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 35, iY, 125, 22 );g_HUD.AddButton( IDC_TOGGLEREF, L"Toggle REF (F3)", 35, iY += 24, 125, 22, VK_F3 );g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 35, iY += 24, 125, 22, VK_F2 );g_SampleUI.SetCallback( OnGUIEvent ); iY = 10; }//-------------------------------------------------------------------------------------- // Render the help and statistics text. This function uses the ID3DXFont interface for // efficient text rendering. //-------------------------------------------------------------------------------------- void RenderText() {g_pTxtHelper->Begin();g_pTxtHelper->SetInsertionPos( 5, 5 );g_pTxtHelper->SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 0.0f, 1.0f ) );g_pTxtHelper->DrawTextLine( DXUTGetFrameStats( DXUTIsVsyncEnabled() ) );g_pTxtHelper->DrawTextLine( DXUTGetDeviceStats() );g_pTxtHelper->End(); }//-------------------------------------------------------------------------------------- // Rejects any D3D9 devices that aren't acceptable to the app by returning false //-------------------------------------------------------------------------------------- bool CALLBACK IsD3D9DeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat,D3DFORMAT BackBufferFormat, bool bWindowed, void* pUserContext ) {// Skip backbuffer formats that don't support alpha blendingIDirect3D9* pD3D = DXUTGetD3D9Object();if( FAILED( pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType,AdapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING,D3DRTYPE_TEXTURE, BackBufferFormat ) ) )return false;// No fallback defined by this app, so reject any device that // doesn't support at least ps2.0if( pCaps->PixelShaderVersion < D3DPS_VERSION( 2, 0 ) )return false;return true; }//-------------------------------------------------------------------------------------- // Called right before creating a D3D9 or D3D10 device, allowing the app to modify the device settings as needed //-------------------------------------------------------------------------------------- bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, void* pUserContext ) {if( pDeviceSettings->ver == DXUT_D3D9_DEVICE ){IDirect3D9* pD3D = DXUTGetD3D9Object();D3DCAPS9 Caps;pD3D->GetDeviceCaps( pDeviceSettings->d3d9.AdapterOrdinal, pDeviceSettings->d3d9.DeviceType, &Caps );// If device doesn't support HW T&L or doesn't support 1.1 vertex shaders in HW // then switch to SWVP.if( ( Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ) == 0 ||Caps.VertexShaderVersion < D3DVS_VERSION( 1, 1 ) ){pDeviceSettings->d3d9.BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;}// Debugging vertex shaders requires either REF or software vertex processing // and debugging pixel shaders requires REF. #ifdef DEBUG_VSif( pDeviceSettings->d3d9.DeviceType != D3DDEVTYPE_REF ){pDeviceSettings->d3d9.BehaviorFlags &= ~D3DCREATE_HARDWARE_VERTEXPROCESSING;pDeviceSettings->d3d9.BehaviorFlags &= ~D3DCREATE_PUREDEVICE;pDeviceSettings->d3d9.BehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;} #endif #ifdef DEBUG_PSpDeviceSettings->d3d9.DeviceType = D3DDEVTYPE_REF; #endif}// For the first device created if its a REF device, optionally display a warning dialog boxstatic bool s_bFirstTime = true;if( s_bFirstTime ){s_bFirstTime = false;if( ( DXUT_D3D9_DEVICE == pDeviceSettings->ver && pDeviceSettings->d3d9.DeviceType == D3DDEVTYPE_REF ) ||( DXUT_D3D10_DEVICE == pDeviceSettings->ver &&pDeviceSettings->d3d10.DriverType == D3D10_DRIVER_TYPE_REFERENCE ) )DXUTDisplaySwitchingToREFWarning( pDeviceSettings->ver );}return true; }//-------------------------------------------------------------------------------------- // Create any D3D9 resources that will live through a device reset (D3DPOOL_MANAGED) // and aren't tied to the back buffer size //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D9CreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,void* pUserContext ) {HRESULT hr;V_RETURN( g_DialogResourceManager.OnD3D9CreateDevice( pd3dDevice ) );V_RETURN( g_SettingsDlg.OnD3D9CreateDevice( pd3dDevice ) );V_RETURN( D3DXCreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET,OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,L"Arial", &g_pFont9 ) );// Read the D3DX effect file WCHAR str[MAX_PATH];DWORD dwShaderFlags = D3DXFX_NOT_CLONEABLE;#ifdef DEBUG_VSdwShaderFlags |= D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT; #endif #ifdef DEBUG_PSdwShaderFlags |= D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT; #endif #ifdef D3DXFX_LARGEADDRESS_HANDLEdwShaderFlags |= D3DXFX_LARGEADDRESSAWARE; #endifV_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"SimpleSample.fx" ) );V_RETURN( D3DXCreateEffectFromFile( pd3dDevice, str, NULL, NULL, dwShaderFlags,NULL, &g_pEffect9, NULL ) );/* set mtrl ambient and diffuse, to test ambient, diffuse is disable */D3DXCOLOR colorMtrlDiffuse(0.0f, 0.0f, 0.0f, 1.0f);D3DXCOLOR colorMtrlAmbient(0.5f, 0.5f, 0.1f, 1.0f);D3DXCOLOR colorLightAmbient(1.0f, 0.5f, 0.1f, 1.0f);V_RETURN( g_pEffect9->SetValue( "g_MaterialAmbientColor", &colorMtrlAmbient, sizeof( D3DXCOLOR ) ) );V_RETURN( g_pEffect9->SetValue( "g_MaterialDiffuseColor", &colorMtrlDiffuse, sizeof( D3DXCOLOR ) ) );V_RETURN( g_pEffect9->SetValue( "g_LightAmbient", &colorLightAmbient, sizeof( D3DXCOLOR ) ) );V_RETURN( pd3dDevice->CreateVertexDeclaration( g_aVertDecl, &g_pVertDecl ) );/* load room mesh */if( FAILED( LoadMesh( pd3dDevice, L"ChairScene\\room.x", g_Room ) ) )return DXUTERR_MEDIANOTFOUND;if( FAILED( LoadMesh( pd3dDevice, L"ChairScene\\chair.x", g_Chair ) ) )return DXUTERR_MEDIANOTFOUND;// Setup the camera's view parametersD3DXVECTOR3 vecEye( 0.0f, 8.0f, -20.0f );D3DXVECTOR3 vecAt ( 0.0f, 0.0f, -0.0f );g_Camera.SetViewParams( &vecEye, &vecAt );return S_OK; }//-------------------------------------------------------------------------------------- // Create any D3D9 resources that won't live through a device reset (D3DPOOL_DEFAULT) // or that are tied to the back buffer size //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice,const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) {HRESULT hr;V_RETURN( g_DialogResourceManager.OnD3D9ResetDevice() );V_RETURN( g_SettingsDlg.OnD3D9ResetDevice() );if( g_pFont9 ) V_RETURN( g_pFont9->OnResetDevice() );if( g_pEffect9 ) V_RETURN( g_pEffect9->OnResetDevice() );g_Room.RestoreDeviceObjects( pd3dDevice ); g_Chair.RestoreDeviceObjects(pd3dDevice);V_RETURN( D3DXCreateSprite( pd3dDevice, &g_pSprite9 ) );g_pTxtHelper = new CDXUTTextHelper( g_pFont9, g_pSprite9, NULL, NULL, 15 );// Setup the camera's projection parametersfloat fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height;g_Camera.SetProjParams( D3DX_PI / 4, fAspectRatio, 0.1f, 1000.0f );g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height );g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 );g_HUD.SetSize( 170, 170 );g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 350 );g_SampleUI.SetSize( 170, 300 );return S_OK; }//-------------------------------------------------------------------------------------- // Handle updates to the scene. This is called regardless of which D3D API is used //-------------------------------------------------------------------------------------- void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext ) {// Update the camera's position based on user input g_Camera.FrameMove( fElapsedTime ); }//-------------------------------------------------------------------------------------- // Render the scene using the D3D9 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) {HRESULT hr;D3DXMATRIXA16 mWorld;D3DXMATRIXA16 mView;D3DXMATRIXA16 mProj;D3DXMATRIXA16 mWorldViewProjection;// If the settings dialog is being shown, then render it instead of rendering the app's sceneif( g_SettingsDlg.IsActive() ){g_SettingsDlg.OnRender( fElapsedTime );return;}// Clear the render target and the zbuffer V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 45, 50, 170 ), 1.0f, 0 ) );// Render the sceneif( SUCCEEDED( pd3dDevice->BeginScene() ) ){// Get the projection & view matrix from the camera classmWorld = *g_Camera.GetWorldMatrix();mProj = *g_Camera.GetProjMatrix();mView = *g_Camera.GetViewMatrix();mWorldViewProjection = mWorld * mView * mProj;// Update the effect's variables. Instead of using strings, it would // be more efficient to cache a handle to the parameter by calling // ID3DXEffect::GetParameterByNameV( g_pEffect9->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection ) );V( g_pEffect9->SetMatrix( "g_mWorld", &mWorld ) );V( g_pEffect9->SetFloat( "g_fTime", ( float )fTime ) );/* render room */UINT p, cPass;V( g_pEffect9->SetTechnique( "RenderScene" ) );V( g_pEffect9->Begin( &cPass, 0 ) );for(p = 0; p < cPass; ++p){LPD3DXMESH pMeshObj;V( g_pEffect9->BeginPass(p));pMeshObj = g_Room.GetMesh();for(DWORD m = 0; m < g_Room.m_dwNumMaterials; ++m){V( g_pEffect9->SetTexture( "g_MeshTexture", g_Room.m_pTextures[m] ) );V( g_pEffect9->CommitChanges() );V( pMeshObj->DrawSubset( m ) );}}V( g_pEffect9->End() );V( g_pEffect9->SetTechnique( "RenderScene" ) );V( g_pEffect9->Begin( &cPass, 0 ) );for(p = 0; p < cPass; ++p){LPD3DXMESH pMeshObj;V( g_pEffect9->BeginPass(p));pMeshObj = g_Chair.GetMesh();for(DWORD m = 0; m < g_Chair.m_dwNumMaterials; ++m){V( g_pEffect9->SetTexture( "g_MeshTexture", g_Room.m_pTextures[m] ) );V( g_pEffect9->CommitChanges() );V( pMeshObj->DrawSubset( m ) );}}V( g_pEffect9->End() );DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); // These events are to help PIX identify what the code is doing RenderText();V( g_HUD.OnRender( fElapsedTime ) );V( g_SampleUI.OnRender( fElapsedTime ) );DXUT_EndPerfEvent();V( pd3dDevice->EndScene() );} }//-------------------------------------------------------------------------------------- // Handle messages to the application //-------------------------------------------------------------------------------------- LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing,void* pUserContext ) {// Pass messages to dialog resource manager calls so GUI state is updated correctly*pbNoFurtherProcessing = g_DialogResourceManager.MsgProc( hWnd, uMsg, wParam, lParam );if( *pbNoFurtherProcessing )return 0;// Pass messages to settings dialog if its activeif( g_SettingsDlg.IsActive() ){g_SettingsDlg.MsgProc( hWnd, uMsg, wParam, lParam );return 0;}// Give the dialogs a chance to handle the message first*pbNoFurtherProcessing = g_HUD.MsgProc( hWnd, uMsg, wParam, lParam );if( *pbNoFurtherProcessing )return 0;*pbNoFurtherProcessing = g_SampleUI.MsgProc( hWnd, uMsg, wParam, lParam );if( *pbNoFurtherProcessing )return 0;// Pass all remaining windows messages to camera so it can respond to user input g_Camera.HandleMessages( hWnd, uMsg, wParam, lParam );return 0; }//-------------------------------------------------------------------------------------- // Handle key presses //-------------------------------------------------------------------------------------- void CALLBACK OnKeyboard( UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext ) { }//-------------------------------------------------------------------------------------- // Handles the GUI events //-------------------------------------------------------------------------------------- void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext ) {switch( nControlID ){case IDC_TOGGLEFULLSCREEN:DXUTToggleFullScreen(); break;case IDC_TOGGLEREF:DXUTToggleREF(); break;case IDC_CHANGEDEVICE:g_SettingsDlg.SetActive( !g_SettingsDlg.IsActive() ); break;} }//-------------------------------------------------------------------------------------- // Release D3D9 resources created in the OnD3D9ResetDevice callback //-------------------------------------------------------------------------------------- void CALLBACK OnD3D9LostDevice( void* pUserContext ) {g_DialogResourceManager.OnD3D9LostDevice();g_SettingsDlg.OnD3D9LostDevice();if( g_pFont9 ) g_pFont9->OnLostDevice();if( g_pEffect9 ) g_pEffect9->OnLostDevice();SAFE_RELEASE( g_pSprite9 );SAFE_DELETE( g_pTxtHelper );SAFE_RELEASE( g_pVertDecl ); }//-------------------------------------------------------------------------------------- // Release D3D9 resources created in the OnD3D9CreateDevice callback //-------------------------------------------------------------------------------------- void CALLBACK OnD3D9DestroyDevice( void* pUserContext ) {g_DialogResourceManager.OnD3D9DestroyDevice();g_SettingsDlg.OnD3D9DestroyDevice();SAFE_RELEASE( g_pEffect9 );SAFE_RELEASE( g_pFont9 );SAFE_RELEASE( g_pVertDecl );g_Room.Destroy();g_Chair.Destroy(); }HRESULT LoadMesh( IDirect3DDevice9* pd3dDevice, LPCWSTR wszName, CDXUTXFileMesh& Mesh ) {HRESULT hr;if( FAILED( hr = Mesh.Create( pd3dDevice, wszName ) ) )return hr;hr = Mesh.SetVertexDecl( pd3dDevice, g_aVertDecl );return hr; }
media:
ChairScene
转载于:https://www.cnblogs.com/zengqh/archive/2012/07/03/2574034.html
hlsl之ambient相关推荐
- 在场景中添加光线——添加HLSL Vertex Shading
问题 使用你配置好的光照,BasicEffect可以很好地绘制场景.但是,如果你想定义一些更酷的效果,首先要实现的就是正确的光照. 本教程中,你将学习如何编写一个基本的HLSL effect实现逐顶点 ...
- HLSL内置函数一览
本文版权归 博客园 七星重剑 所有,如有转载,请按如下方式于显示位置标明原创作者及出处,以示尊重!! 作者:七星重剑 原文:每天30分钟看Shader--(1)HLSL固有函数 [Intrinsic ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十一章:环境光遮蔽(AMBIENT OCCLUSION)
学习目标 熟悉环境光遮蔽的基本思路,以及通过光线跟踪的实现方法: 学习如何在屏幕坐标系下实现实时模拟的环境光遮蔽. 1 通过光线追踪实现的环境光遮蔽 其中一种估算点P遮蔽的方法是光线跟踪.我们随机跟踪 ...
- Unity Shader - 在 URP 获取 Ambient(环境光) 颜色
之前在 Unity Built-in 管线中,我们在自定义 shader 中,可以使用一下代码来获取 Ambient 环境光的颜色: fixed3 ambient = UNITY_LIGHTMODEL ...
- unity Shader Lab(cg hlsl glsl)着色器入门教程 以及 vs2019 支持unity shader语法(更新中2019.9.5)
前言: 如果你对cg glsl hlsl 顶点着色器 片段着色器 表面着色器 固定渲染管线 等等有所疑惑,或是想学会unity的渲染,看这一篇就足够了.另外我博客的shader分类中还有很多shade ...
- HLSL着色器原理:(三)高级着色器
小光!小光!小光!小光!小光! 本文所总结视频为或许是小光从油管搬运到B站的视频:传送门 本篇主要汇总HLSL着色器的知识原理部分,并涉及少量必要的代码知识点,主要为知识点总结,实践部分建议参照其他S ...
- HLSL着色器原理:(一)着色器基础
小光!小光!小光!小光!小光! 本文所总结视频为或许是小光从油管搬运到B站的视频:传送门 本篇主要汇总HLSL着色器的知识原理部分,并涉及少量必要的代码知识点,主要为知识点总结,实践部分建议参照其他S ...
- 将HLSL射线追踪到Vulkan
将HLSL射线追踪到Vulkan Bringing HLSL Ray Tracing to Vulkan Vulkan标志 DirectX光线跟踪(DXR)允许您使用光线跟踪而不是传统的光栅化方法渲染 ...
- 快速浏览Silverlight3 Beta:当HLSL遇上Silverlight
HLSL 高级着色器语言(High Level Shader Language,简称HLSL),由微软拥 有及开发的一种语言,只能供微软的Direct3D使用. HLSL是微软抗衡GLSL的产品,同 ...
最新文章
- 装饰器的定义、语法糖用法及示例代码
- js如何关闭当前页,而不弹出提示框
- 大数据引发的风险与管控
- Codeforces 1338 题解
- Asp.Net_文件操作基类
- 【转】Dynamics CRM 365零基础入门学习(二)Dynamics 插件注册的基本流程
- springsession分布式登录被覆盖_拉勾 分布式 学习小结
- 解决maven打jar包报错:Could not resolve substitution to a value: ${akka.stream.materializer}
- 计算理论101:这可能是讲FSM的最生动的一篇了
- Bailian2992 Lab杯【排序】
- java 改像素不改尺寸_如何不改变分辨率的情况下缩小尺寸PNG图片
- https的报文传输机制
- 单片机外文参考文献期刊_单片机-英文参考文献
- 电子元器件选型——MOSFET
- SAXReader解析xml文件
- 苹果任性,降低iPhone电池容量,用户需要多买个充电宝奶妈
- AD中如何快速画完原理图引脚?
- VPP线程之间报文调度
- 网页视频播放速度修改器,亲测可用
- DeFi:过去、现在和未来
热门文章
- is,as,sizeof,typeof,GetType
- 【Vue2.0】—Vue与Component的关系(十二)
- Vue报错:sockjs.js?9be2:1627 GET http://192.168.43.88:8080/sockjs-node/info?t=1631603986586 net::ERR_CO
- JavaScript学习(二十)—DOM中常用的属性
- CSS基本知识之复合选择器、元素显示模式、背景图片位置,精灵图
- git回退历史版本无法上传_git下载历史版本
- TrueNAS SCALE是什么
- 我有30万现金,如何规划理财,让钱生钱?
- 越混越差的十个原因,看看你有没有?
- 两大思维,就可以让你轻松完成任意一个目标