Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (Kingware, AndrewAMD, AemStones, RealSerious3D, degenerate_762), 837 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 6 1 2 3 4 5 6
Real DX9 Reflection #37712
12/14/04 03:12
12/14/04 03:12
Joined: May 2004
Posts: 66
Brazil
key_46 Offline OP
Junior Member
key_46  Offline OP
Junior Member

Joined: May 2004
Posts: 66
Brazil
I found this code in DX9 SDK, He Have a CUBEMap Shader and a code to fill objects from de scene to envmap, how i can make the program get the 3dgs scene?



Code:
  //-----------------------------------------------------------------------------
// File: CubeMap.cpp
//
// Desc: Example code showing how to do environment mapping
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#define STRICT
#include <Windows.h>
#include <commctrl.h>
#include <tchar.h>
#include <math.h>
#include <stdio.h>
#include <C:\DXSDK\Include\D3DX9.h>
#include "DXUtil.h"
#include "D3DEnumeration.h"
#include "D3DSettings.h"
#include "D3DApp.h"
#include "D3DFile.h"
#include "D3DFont.h"
#include "D3DUtil.h"


//-----------------------------------------------------------------------------
// Name: g_szEffect
// Desc: String containing effect used to render shiny teapot. Two techniques
// are shown.. one which simply uses cubemaps, and a fallback which uses
// a vertex shader to do a sphere-map lookup.
//-----------------------------------------------------------------------------

const char g_szEffect[] =

"textureCUBE texCubeMap;\n"
"texture texSphereMap;\n"

"matrix matWorld;\n"
"matrix matView;\n"
"matrix matProject;\n"
"matrix matWorldView;\n"


"technique Cube\n"
"{\n"
"pass P0\n"
"{\n"
// Vertex state
"VertexShader = null;\n"
"WorldTransform[0] = <matWorld>;\n"
"ViewTransform = <matView>;\n"
"ProjectionTransform = <matProject>;\n"

// Pixel state
"Texture[0] = <texCubeMap>;\n"

"MinFilter[0] = Linear;\n"
"MagFilter[0] = Linear;\n"

"AddressU[0] = Clamp;\n"
"AddressV[0] = Clamp;\n"
"AddressW[0] = Clamp;\n"

"ColorOp[0] = SelectArg1;\n"
"ColorArg1[0] = Texture;\n"

"TexCoordIndex[0] = CameraSpaceReflectionVector;\n"
"TextureTransformFlags[0] = Count3;\n"
"}\n"
"}\n"


"technique Sphere\n"
"{\n"
"pass P0\n"
"{\n"

// Vertex state
"VertexShader =\n"
"decl\n"
"{\n"
// Decls no longer associated with vertex shaders in DX9
"}\n"
"asm\n"
"{\n"
"vs.1.1\n"
"def c64, 0.25f, 0.5f, 1.0f, -1.0f\n"

"dcl_position v0\n"
"dcl_normal v1\n"

// r0: camera-space position
// r1: camera-space normal
// r2: camera-space vertex-eye vector
// r3: camera-space reflection vector
// r4: texture coordinates

// Transform position and normal into camera-space
"m4x4 r0, v0, c0\n"
"m3x3 r1.xyz, v1, c0\n"
"mov r1.w, c64.z\n"

// Compute normalized view vector
"mov r2, -r0\n"
"dp3 r3, r2, r2\n"
"rsq r3, r3.w\n"
"mul r2, r2, r3\n"

// Compute camera-space reflection vector
"dp3 r3, r1, r2\n"
"mul r1, r1, r3\n"
"add r1, r1, r1\n"
"add r3, r1, -r2\n"

// Compute sphere-map texture coords
"mad r4.w, -r3.z, c64.y, c64.y\n"
"rsq r4, r4.w\n"
"mul r4, r3, r4\n"
"mad r4, r4, c64.x, c64.y\n"

// Project position
"m4x4 oPos, r0, c4\n"
"mul oT0.xy, r4.xy, c64.zw\n"
"mov oT0.zw, c64.z\n"
"};\n"

"VertexShaderConstant4[0] = <matWorldView>;\n"
"VertexShaderConstant4[4] = <matProject>;\n"

// Pixel state
"Texture[0] = <texSphereMap>;\n"
"AddressU[0] = Wrap;\n"
"AddressV[0] = Wrap;\n"
"MinFilter[0] = Linear;\n"
"MagFilter[0] = Linear;\n"
"ColorOp[0] = SelectArg1;\n"
"ColorArg1[0] = Texture;\n"
"}\n"
"}\n";

const UINT g_cchEffect = sizeof(g_szEffect) - 1;




//-----------------------------------------------------------------------------
// Name: struct ENVMAPPEDVERTEX
// Desc: D3D vertex type for environment-mapped objects
//-----------------------------------------------------------------------------
struct ENVMAPPEDVERTEX
{
D3DXVECTOR3 p; // Position
D3DXVECTOR3 n; // Normal

static const DWORD FVF;
};
const DWORD ENVMAPPEDVERTEX::FVF = D3DFVF_XYZ | D3DFVF_NORMAL;

// CUBEMAP_RESOLUTION indicates how big to make the cubemap texture. Larger
// textures will generate a better-looking reflection.
#define CUBEMAP_RESOLUTION 256



//-----------------------------------------------------------------------------
// Name: class CMyD3DApplication
// Desc: Application class. The base class (CD3DApplication) provides the
// generic functionality needed in all Direct3D samples. CMyD3DApplication
// adds functionality specific to this sample program.
//-----------------------------------------------------------------------------
class CMyD3DApplication : public CD3DApplication
{
BOOL m_bCapture;

D3DXMATRIXA16 m_matProject;
D3DXMATRIXA16 m_matView;
D3DXMATRIXA16 m_matWorld;
D3DXMATRIXA16 m_matAirplane;
D3DXMATRIXA16 m_matTrackBall;

CD3DFont* m_pFont;
CD3DMesh* m_pShinyTeapot;
CD3DMesh* m_pSkyBox;
CD3DMesh* m_pAirplane;
CD3DMesh* m_pMyMesh;

ID3DXEffect* m_pEffect;
ID3DXRenderToEnvMap* m_pRenderToEnvMap;

IDirect3DCubeTexture9* m_pCubeMap;
IDirect3DTexture9* m_pSphereMap;

protected:
HRESULT RenderSceneIntoEnvMap();
HRESULT RenderScene( CONST D3DXMATRIXA16* pView, CONST D3DXMATRIXA16* pProject, BOOL bRenderTeapot );

HRESULT ConfirmDevice( D3DCAPS9*, DWORD, D3DFORMAT, D3DFORMAT );
HRESULT OneTimeSceneInit();
HRESULT InitDeviceObjects();
HRESULT RestoreDeviceObjects();
HRESULT InvalidateDeviceObjects();
HRESULT DeleteDeviceObjects();
HRESULT Render();
HRESULT FrameMove();
HRESULT FinalCleanup();

public:
LRESULT MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );

CMyD3DApplication();
};




//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything, and goes into a
// message-processing loop. Idle time is used to render the scene.
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
CMyD3DApplication d3dApp;

InitCommonControls();
if( FAILED( d3dApp.Create( hInst ) ) )
return 0;

return d3dApp.Run();
}




//-----------------------------------------------------------------------------
// Name: CMyD3DApplication()
// Desc: Application constructor. Sets attributes for the app.
//-----------------------------------------------------------------------------
CMyD3DApplication::CMyD3DApplication()
{
m_strWindowTitle = _T("CubeMap");
m_d3dEnumeration.AppUsesDepthBuffer = TRUE;
m_bCapture = FALSE;

m_pFont = NULL;
m_pShinyTeapot = NULL;
m_pSkyBox = NULL;
m_pAirplane = NULL;
m_pMyMesh = NULL;

m_pEffect = NULL;
m_pRenderToEnvMap = NULL;

m_pCubeMap = NULL;
m_pSphereMap = NULL;
}




//-----------------------------------------------------------------------------
// Name: OneTimeSceneInit()
// Desc: Called during initial app startup, this function performs all the
// permanent initialization.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::OneTimeSceneInit()
{
D3DXMatrixIdentity( &m_matWorld );

m_pFont = new CD3DFont( _T("Arial"), 12, D3DFONT_BOLD );
m_pShinyTeapot = new CD3DMesh();
m_pSkyBox = new CD3DMesh();
m_pAirplane = new CD3DMesh();
m_pMyMesh = new CD3DMesh();

if( !m_pFont || !m_pShinyTeapot || !m_pSkyBox || !m_pAirplane || !m_pMyMesh )
return E_OUTOFMEMORY;

D3DXMatrixIdentity( &m_matTrackBall );
D3DXMatrixTranslation( &m_matView, 0.0f, 0.0f, 3.0f );

return S_OK;
}




//-----------------------------------------------------------------------------
// Name: FrameMove()
// Desc: Called once per frame, the call is the entry point for animating
// the scene.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::FrameMove()
{
// Animate file object
D3DXMATRIXA16 mat;
D3DXMatrixScaling( &m_matAirplane, 0.2f, 0.2f, 0.2f );
D3DXMatrixTranslation( &mat, 0.0f, 2.0f, 0.0f );
D3DXMatrixMultiply( &m_matAirplane, &m_matAirplane, &mat );
D3DXMatrixRotationX( &mat, -2.9f * m_fTime );
D3DXMatrixMultiply( &m_matAirplane, &m_matAirplane, &mat );
D3DXMatrixRotationY( &mat, 1.055f * m_fTime );
D3DXMatrixMultiply( &m_matAirplane, &m_matAirplane, &mat );

// When the window has focus, let the mouse adjust the camera view
if( m_bCapture )
{
D3DXMATRIXA16 matCursor;
D3DXQUATERNION qCursor = D3DUtil_GetRotationFromCursor( m_hWnd );
D3DXMatrixRotationQuaternion( &matCursor, &qCursor );
D3DXMatrixMultiply( &m_matView, &m_matTrackBall, &matCursor );

D3DXMATRIXA16 matTrans;
D3DXMatrixTranslation( &matTrans, 0.0f, 0.0f, 3.0f );
D3DXMatrixMultiply( &m_matView, &m_matView, &matTrans );
}


// Render the scene into the surfaces of the cubemap
if( FAILED( RenderSceneIntoEnvMap() ) )
return E_FAIL;

return S_OK;
}




//-----------------------------------------------------------------------------
// Name: RenderSceneIntoEnvMap()
// Desc: Renders the scene to each of the 6 faces of the cube map
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::RenderSceneIntoEnvMap()
{
HRESULT hr;

// Set the projection matrix for a field of view of 90 degrees
D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI * 0.5f, 1.0f, 0.5f, 1000.0f );


// Get the current view matrix, to concat it with the cubemap view vectors
D3DXMATRIXA16 matViewDir( m_matView );
matViewDir._41 = 0.0f; matViewDir._42 = 0.0f; matViewDir._43 = 0.0f;



// Render the six cube faces into the environment map
if( m_pCubeMap )
hr = m_pRenderToEnvMap->BeginCube( m_pCubeMap );
else
hr = m_pRenderToEnvMap->BeginSphere( m_pSphereMap );

if(FAILED(hr))
return hr;

for( UINT i = 0; i < 6; i++ )
{
m_pRenderToEnvMap->Face( (D3DCUBEMAP_FACES) i, 0 );

// Set the view transform for this cubemap surface
D3DXMATRIXA16 matView;
matView = D3DUtil_GetCubeMapViewMatrix( (D3DCUBEMAP_FACES) i );
D3DXMatrixMultiply( &matView, &matViewDir, &matView );

// Render the scene (except for the teapot)
RenderScene( &matView, &matProj, FALSE );
}

m_pRenderToEnvMap->End( 0 );
return S_OK;
}




//-----------------------------------------------------------------------------
// Name: RenderScene()
// Desc: Renders all visual elements in the scene. This is called by the main
// Render() function, and also by the RenderIntoCubeMap() function.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::RenderScene( CONST D3DXMATRIXA16 *pView, CONST D3DXMATRIXA16 *pProject,
BOOL bRenderTeapot )
{
// Render the Skybox
{
D3DXMATRIXA16 matWorld;
D3DXMatrixScaling( &matWorld, 10.0f, 10.0f, 10.0f );

D3DXMATRIXA16 matView(*pView);
matView._41 = matView._42 = matView._43 = 0.0f;

m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
m_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
m_pd3dDevice->SetTransform( D3DTS_PROJECTION, pProject );

m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
if( (m_d3dCaps.TextureAddressCaps & D3DPTADDRESSCAPS_MIRROR) == D3DPTADDRESSCAPS_MIRROR )
{
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR );
}

// Always pass Z-test, so we can avoid clearing color and depth buffers
m_pd3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_ALWAYS );
m_pSkyBox->Render( m_pd3dDevice );
m_pd3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_LESSEQUAL );
}


// Render the Airplane
{
m_pd3dDevice->SetTransform( D3DTS_WORLD, &m_matAirplane );
m_pd3dDevice->SetTransform( D3DTS_VIEW, pView );
m_pd3dDevice->SetTransform( D3DTS_PROJECTION, pProject );

m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP );

m_pAirplane->Render( m_pd3dDevice );
m_pMyMesh->Render( m_pd3dDevice );

m_pd3dDevice->SetTransform( D3DTS_WORLD, &m_matWorld);
}


// Render the environment-mapped ShinyTeapot
if( bRenderTeapot )
{
// Set transform state
if( m_pCubeMap )
{
m_pEffect->SetMatrix( "matWorld", &m_matWorld );
m_pEffect->SetMatrix( "matView", (D3DXMATRIXA16*) pView );
}
else
{
D3DXMATRIXA16 matWorldView;
D3DXMatrixMultiply( &matWorldView, &m_matWorld, pView );
m_pEffect->SetMatrix( "matWorldView", &matWorldView );
}

m_pEffect->SetMatrix( "matProject", (D3DXMATRIXA16*) pProject );


// Draw teapot
LPDIRECT3DVERTEXBUFFER9 pVB;
LPDIRECT3DINDEXBUFFER9 pIB;

m_pShinyTeapot->m_pLocalMesh->GetVertexBuffer(&pVB);
m_pShinyTeapot->m_pLocalMesh->GetIndexBuffer(&pIB);

m_pd3dDevice->SetStreamSource(0, pVB, 0, sizeof(ENVMAPPEDVERTEX));
m_pd3dDevice->SetFVF(ENVMAPPEDVERTEX::FVF);
m_pd3dDevice->SetIndices( pIB );

UINT uPasses;
m_pEffect->Begin( &uPasses, 0 );

for( UINT iPass = 0; iPass < uPasses; iPass++ )
{
m_pEffect->Pass( iPass );

m_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0,
0, m_pShinyTeapot->m_pLocalMesh->GetNumVertices(),
0, m_pShinyTeapot->m_pLocalMesh->GetNumFaces());

}

m_pEffect->End();

SAFE_RELEASE(pVB);
SAFE_RELEASE(pIB);
}

return S_OK;
}




//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Called once per frame, the call is the entry point for 3d
// rendering. This function sets up render states, clears the
// viewport, and renders the scene.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::Render()
{
// Begin the scene
if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
{
// Render the scene, including the teapot
RenderScene( &m_matView, &m_matProject, TRUE );

// Output statistics
m_pFont->DrawText( 2, 0, D3DCOLOR_ARGB(255,255,255,0), m_strFrameStats );
m_pFont->DrawText( 2, 20, D3DCOLOR_ARGB(255,255,255,0), m_strDeviceStats );

// End the scene.
m_pd3dDevice->EndScene();
}

return S_OK;
}




//-----------------------------------------------------------------------------
// Name: InitDeviceObjects()
// Desc: Initialize scene objects.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::InitDeviceObjects()
{
// Load the file objects
if( FAILED( m_pShinyTeapot->Create( m_pd3dDevice, _T("Teapot.x") ) ) )
return D3DAPPERR_MEDIANOTFOUND;
if( FAILED( m_pSkyBox->Create( m_pd3dDevice, _T("lobby_skybox.x") ) ) )
return D3DAPPERR_MEDIANOTFOUND;
if( FAILED( m_pAirplane->Create( m_pd3dDevice, _T("airplane 2.x") ) ) )
return D3DAPPERR_MEDIANOTFOUND;

if( FAILED( m_pMyMesh->Create( m_pd3dDevice, _T("tree.x") ) ) )
return D3DAPPERR_MEDIANOTFOUND;


// Set mesh properties
m_pAirplane->SetFVF( m_pd3dDevice, D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1 );
m_pShinyTeapot->SetFVF( m_pd3dDevice, ENVMAPPEDVERTEX::FVF );

// Restore the device-dependent objects
m_pFont->InitDeviceObjects( m_pd3dDevice );

// Create Effect object
if( FAILED( D3DXCreateEffect( m_pd3dDevice, g_szEffect, g_cchEffect, NULL, NULL, 0, NULL, &m_pEffect, NULL ) ) )
return E_FAIL;

return S_OK;
}




//-----------------------------------------------------------------------------
// Name: RestoreDeviceObjects()
// Desc: Restore device-memory objects and state after a device is created or
// resized.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::RestoreDeviceObjects()
{
// InitDeviceObjects for file objects (build textures and vertex buffers)
m_pShinyTeapot->RestoreDeviceObjects( m_pd3dDevice );
m_pSkyBox->RestoreDeviceObjects( m_pd3dDevice );
m_pAirplane->RestoreDeviceObjects( m_pd3dDevice );
m_pFont->RestoreDeviceObjects();
m_pMyMesh->RestoreDeviceObjects( m_pd3dDevice );
m_pEffect->OnResetDevice();



// Create RenderToEnvMap object
if( FAILED( D3DXCreateRenderToEnvMap( m_pd3dDevice, CUBEMAP_RESOLUTION, 1,
m_d3dsdBackBuffer.Format, TRUE, D3DFMT_D16, &m_pRenderToEnvMap ) ) )
{
return E_FAIL;
}


// Create the cubemap, with a format that matches the backbuffer
if( m_d3dCaps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP )
{
if( FAILED( D3DXCreateCubeTexture( m_pd3dDevice, CUBEMAP_RESOLUTION, 1,
D3DUSAGE_RENDERTARGET, m_d3dsdBackBuffer.Format, D3DPOOL_DEFAULT, &m_pCubeMap ) ) )
{
if( FAILED( D3DXCreateCubeTexture( m_pd3dDevice, CUBEMAP_RESOLUTION, 1,
0, m_d3dsdBackBuffer.Format, D3DPOOL_DEFAULT, &m_pCubeMap ) ) )
{
m_pCubeMap = NULL;
}
}
}


// Create the spheremap, with a format that matches the backbuffer
if( !m_pCubeMap )
{
if( FAILED( D3DXCreateTexture( m_pd3dDevice, CUBEMAP_RESOLUTION, CUBEMAP_RESOLUTION,
1, D3DUSAGE_RENDERTARGET, m_d3dsdBackBuffer.Format, D3DPOOL_DEFAULT, &m_pSphereMap ) ) )
{
if( FAILED( D3DXCreateTexture( m_pd3dDevice, CUBEMAP_RESOLUTION, CUBEMAP_RESOLUTION,
1, 0, m_d3dsdBackBuffer.Format, D3DPOOL_DEFAULT, &m_pSphereMap ) ) )
{
return E_FAIL;
}
}
}


// Initialize effect
m_pEffect->SetTexture( "texCubeMap", m_pCubeMap );
m_pEffect->SetTexture( "texSphereMap", m_pSphereMap );

if( m_pCubeMap )
{
m_pEffect->SetTechnique( "Cube" );
SetWindowText( m_hWnd, _T("CubeMap: Environment cube-mapping") );
}
else
{
m_pEffect->SetTechnique( "Sphere" );
SetWindowText( m_hWnd, _T("CubeMap: Environment cube-mapping (using dynamic spheremap)") );
}


// Set the transform matrices
FLOAT fAspect = (FLOAT) m_d3dsdBackBuffer.Width / (FLOAT) m_d3dsdBackBuffer.Height;
D3DXMatrixPerspectiveFovLH( &m_matProject, D3DX_PI * 0.4f, fAspect, 0.5f, 100.0f );


return S_OK;
}




//-----------------------------------------------------------------------------
// Name: InvalidateDeviceObjects()
// Desc: Called when the device-dependent objects are about to be lost.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::InvalidateDeviceObjects()
{
m_pShinyTeapot->InvalidateDeviceObjects();
m_pSkyBox->InvalidateDeviceObjects();
m_pAirplane->InvalidateDeviceObjects();
m_pFont->InvalidateDeviceObjects();

if(m_pEffect)
m_pEffect->OnLostDevice();

SAFE_RELEASE( m_pRenderToEnvMap );
SAFE_RELEASE( m_pCubeMap );
SAFE_RELEASE( m_pSphereMap );

return S_OK;
}




//-----------------------------------------------------------------------------
// Name: DeleteDeviceObjects()
// Desc: Called when the app is exiting, or the device is being changed,
// this function deletes any device dependent objects.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::DeleteDeviceObjects()
{
m_pFont->DeleteDeviceObjects();
m_pShinyTeapot->Destroy();
m_pSkyBox->Destroy();
m_pAirplane->Destroy();
m_pMyMesh->Destroy();

SAFE_RELEASE( m_pEffect );

return S_OK;
}




//-----------------------------------------------------------------------------
// Name: FinalCleanup()
// Desc: Called before the app exits, this function gives the app the chance
// to cleanup after itself.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::FinalCleanup()
{
SAFE_DELETE( m_pFont );
SAFE_DELETE( m_pShinyTeapot );
SAFE_DELETE( m_pSkyBox );
SAFE_DELETE( m_pAirplane );
SAFE_DELETE( m_pMyMesh );

return S_OK;
}




//-----------------------------------------------------------------------------
// Name: ConfirmDevice()
// Desc: Called during device initialization, this code checks the device
// for some minimum set of capabilities
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::ConfirmDevice( D3DCAPS9* pCaps, DWORD dwBehavior,
D3DFORMAT adapterFormat, D3DFORMAT backBufferFormat )
{
if( dwBehavior & D3DCREATE_PUREDEVICE )
return E_FAIL;

if( !(pCaps->TextureCaps & D3DPTEXTURECAPS_CUBEMAP) &&
!(dwBehavior & D3DCREATE_SOFTWARE_VERTEXPROCESSING) &&
!(pCaps->VertexShaderVersion >= D3DVS_VERSION(1, 0)) )
{
return E_FAIL;
}

return S_OK;
}


//-----------------------------------------------------------------------------
// Name: MsgProc()
// Desc: Message proc function to handle key and menu input
//-----------------------------------------------------------------------------
LRESULT CMyD3DApplication::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam )
{
// Capture mouse when clicked
if( WM_LBUTTONDOWN == uMsg )
{
D3DXMATRIXA16 matCursor;
D3DXQUATERNION qCursor = D3DUtil_GetRotationFromCursor( m_hWnd );
D3DXMatrixRotationQuaternion( &matCursor, &qCursor );
D3DXMatrixTranspose( &matCursor, &matCursor );
D3DXMatrixMultiply( &m_matTrackBall, &m_matTrackBall, &matCursor );

SetCapture( m_hWnd );
m_bCapture = TRUE;
return 0;
}

if( WM_LBUTTONUP == uMsg )
{
D3DXMATRIXA16 matCursor;
D3DXQUATERNION qCursor = D3DUtil_GetRotationFromCursor( m_hWnd );
D3DXMatrixRotationQuaternion( &matCursor, &qCursor );
D3DXMatrixMultiply( &m_matTrackBall, &m_matTrackBall, &matCursor );

ReleaseCapture();
m_bCapture = FALSE;
return 0;
}

// Pass remaining messages to default handler
return CD3DApplication::MsgProc( hWnd, uMsg, wParam, lParam );
}




ADPA Ataque Dos Pôneis Assassinos! Atack Of Killer Ponys! ADPA(R) all rights reserved
Re: Real DX9 Reflection [Re: key_46] #37713
12/14/04 05:50
12/14/04 05:50
Joined: Jul 2004
Posts: 1,710
MMike Offline
Serious User
MMike  Offline
Serious User

Joined: Jul 2004
Posts: 1,710
I did a Realtime Cubemap generator, that creates the environemnt cube, so it can be used to apply the shader each frame or 4 (eg) frame, depending on CPU power.

My problem at the moment is:
-> how to modify the cubemap of a shader each frame... ( envinormant cubemapshader Dx8)

-> It just works for the player till now..



Re: Real DX9 Reflection [Re: MMike] #37714
12/14/04 07:53
12/14/04 07:53
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
You need a material event.. say in the begining of you material put event=envmapevent

then make a function:

function envmapevent()
{
mtl.enablerender=on; //means this function will run every frame
mtl.skin1=newenvmap; //skin1 is the environment map you are using in the shader
}

Re: Real DX9 Reflection [Re: Matt_Aufderheide] #37715
12/14/04 16:54
12/14/04 16:54
Joined: May 2002
Posts: 2,541
Berlin
EX Citer Offline
Expert
EX Citer  Offline
Expert

Joined: May 2002
Posts: 2,541
Berlin
Hey, thatīs exactly what I need, and I just need it for my player. Is the shader using Entity.skills? And is the alpha of the reflaction adjustable? I just can hope you get this working Realy good.

And itīs a new chance for refraction and other shaders.

EX Citer


:L
Re: Real DX9 Reflection [Re: EX Citer] #37716
12/14/04 19:45
12/14/04 19:45
Joined: Oct 2002
Posts: 8,939
planet.earth
ello Offline
Senior Expert
ello  Offline
Senior Expert

Joined: Oct 2002
Posts: 8,939
planet.earth
if you once have the realtime cubemap there are no limits to it (refraction is just another calculation)

Re: Real DX9 Reflection [Re: ello] #37717
12/14/04 23:29
12/14/04 23:29
Joined: Jul 2004
Posts: 1,710
MMike Offline
Serious User
MMike  Offline
Serious User

Joined: Jul 2004
Posts: 1,710
Loll Of course you can select areas on the player with alpha map . ehhe

For example this guys has the "venil" on the shirt that is reflected .. just 10% i guess.. so the mark looks kinda wet when playing

And..

I just Have these problems.. i guess that one of the features that Conitec could do .. it Generation of a camera wih the 6 slots in real time already ( I had to do this by my own .. what took a bit of ..hehe) .. And then implement this on a cube shader envirnom..


and this problem goes for matt i guess ... That script did not work or IM doin gthis wrong..

Whats the command to take a screen shot?? with a determined sizE! each frame or 2 seconds I just need that...

and then .. the shader could acess the shot taken and use it ( Notice: I od't know if this is possible, but I want to take a shot that will overwrite and not create a variable one like shot1 shot 2 ....


So far thats my problems.. And i must say .. The effect is amazing, it look very realistic .. I guess thats how most engines works ( to use medium card)



Re: Real DX9 Reflection [Re: MMike] #37718
12/15/04 00:13
12/15/04 00:13
Joined: Oct 2002
Posts: 8,939
planet.earth
ello Offline
Senior Expert
ello  Offline
Senior Expert

Joined: Oct 2002
Posts: 8,939
planet.earth
do you share your programm? i think i am not the only one who likes to use it:)

Re: Real DX9 Reflection [Re: ello] #37719
12/15/04 04:01
12/15/04 04:01
Joined: Dec 2003
Posts: 1,097
Maryland, USA
Steempipe Offline
Serious User
Steempipe  Offline
Serious User

Joined: Dec 2003
Posts: 1,097
Maryland, USA
Yes.... please share. I would bet that good things would come out of it.

Re: Real DX9 Reflection [Re: MMike] #37720
12/15/04 06:02
12/15/04 06:02
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany

Re: Real DX9 Reflection [Re: Pappenheimer] #37721
12/15/04 06:48
12/15/04 06:48
Joined: Jul 2004
Posts: 1,710
MMike Offline
Serious User
MMike  Offline
Serious User

Joined: Jul 2004
Posts: 1,710
Screenshot thing .. is fixed.

Last edited by Unknot; 12/15/04 07:41.
Page 1 of 6 1 2 3 4 5 6

Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1