Real DX9 Reflection

Posted By: key_46

Real DX9 Reflection - 12/14/04 03:12

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 );
}


Posted By: MMike

Re: Real DX9 Reflection - 12/14/04 05:50

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..


Posted By: Matt_Aufderheide

Re: Real DX9 Reflection - 12/14/04 07:53

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
}
Posted By: EX Citer

Re: Real DX9 Reflection - 12/14/04 16:54

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
Posted By: ello

Re: Real DX9 Reflection - 12/14/04 19:45

if you once have the realtime cubemap there are no limits to it (refraction is just another calculation)
Posted By: MMike

Re: Real DX9 Reflection - 12/14/04 23:29

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)


Posted By: ello

Re: Real DX9 Reflection - 12/15/04 00:13

do you share your programm? i think i am not the only one who likes to use it:)
Posted By: Steempipe

Re: Real DX9 Reflection - 12/15/04 04:01

Yes.... please share. I would bet that good things would come out of it.
Posted By: Pappenheimer

Re: Real DX9 Reflection - 12/15/04 06:02

Do you need something like this?

http://www.conitecserver.com/wiki/index.php/RenderCubeScript
Posted By: MMike

Re: Real DX9 Reflection - 12/15/04 06:48

Screenshot thing .. is fixed.
Posted By: MMike

Re: Real DX9 Reflection - 12/15/04 07:21

OKay now im done with the size problem.. the script does a 128 cubemap ( its enough for now) and it work 100%

Now. I would like to take a screenshot 4 seconds in 4 seconds... and that overwrite them ..instead of saving as shot1, shot2, shot3 and so..

Anyone??
Posted By: Josh_Arldt

Re: Real DX9 Reflection - 12/15/04 08:18

Use what Pappenheimer suggested.
This saves the bitmaps as a cubemap instead of shot1, shot2 ect...

savedir="output";
var_nsave fh;
bmap* canvas;
bmap* b_render1;
bmap* b_render2;
bmap* b_render3;
bmap* b_render4;
bmap* b_render5;
bmap* b_render6;
var cubenumber = 0;
var directions[18] = 180, 0, 0, 90, 0, 0, 0, 0, 0, -90, 0, 0, 90, -90, 0, 90, 90, 0;
string tempstring1;
string tempstring2;
string _ts_;

//----------------------------------------------------------------------------- write_cubemap
function write8(byte) // write char
{
file_asc_write(fh, byte);
}

function write16(short) // write unsigned short
{
file_asc_write(fh, short&255);
file_asc_write(fh, (short>>8)&255);
}

function str_padding(str, number, padding)
{
str_for_num(_ts_, number);
var i = 0;
i = padding - str_len(_ts_);
while(i > 0)
{
str_cat(str, "0");
i-=1;
}
str_cat(str, _ts_);
}

function write_cubemap()
{
var i;
var xx;
var yy;
var format;
var pixel;
var pixelalpha;
var canvas_size[2];

canvas_size.x = bmap_width(b_render1);
canvas_size.y = bmap_height(b_render1);
format = bmap_lock(b_render1, 0);
bmap_lock(b_render2, 0);
bmap_lock(b_render3, 0);
bmap_lock(b_render4, 0);
bmap_lock(b_render5, 0);
bmap_lock(b_render6, 0);

str_cpy(tempstring1, "cubemap");
str_padding(tempstring1, cubenumber, 4);
str_cat(tempstring1, "+6.tga");
fh = file_open_write(tempstring1);
cubenumber+=1;
//--------------------------------------------------------write header
write8(0);
write8(0);
write8(2); // image type
write16(0);
write16(0);
write8(0);
write16(0);
write16(0);
write16(canvas_size.x * 6); // width
write16(canvas_size.y); // height
write8(24); // color depth
write8(0);
//--------------------------------------------------------write image data
yy = canvas_size.y - 1;
while(yy >= 0)
{
i = 0;
while(i < 6)
{
if(i==0){canvas=b_render1;}
if(i==1){canvas=b_render2;}
if(i==2){canvas=b_render3;}
if(i==3){canvas=b_render4;}
if(i==4){canvas=b_render5;}
if(i==5){canvas=b_render6;}
xx = 0;
while(xx < canvas_size.x)
{
pixel = pixel_for_bmap(canvas, xx, yy);
pixel_to_vec(temp, pixelalpha, format, pixel);
write8(temp.x); // b
write8(temp.y); // g
write8(temp.z); // r
xx+=1;
}
i+=1;
}
yy-=1;
}
file_close(fh);
bmap_unlock(b_render1);
bmap_unlock(b_render2);
bmap_unlock(b_render3);
bmap_unlock(b_render4);
bmap_unlock(b_render5);
bmap_unlock(b_render6);
}

//----------------------------------------------------------------------------- capture_cubemap
function capture_cubemap
{
var old_arc;
var old_x;
var old_y;
var old_screen;

b_render1 = bmap_create("render.tga"); // use a 256x256 tga for example -> determines cube map size
b_render2 = bmap_create("render.tga");
b_render3 = bmap_create("render.tga");
b_render4 = bmap_create("render.tga");
b_render5 = bmap_create("render.tga");
b_render6 = bmap_create("render.tga");

old_arc = camera.arc;
old_x = screen_size.x;
old_y = screen_size.y;
old_screen = video_screen;

camera.arc = 90;
video_set(256, 256, 32, 2); // should be same resolution as render.tga

freeze_mode = on;
vec_set(camera.pan, directions[0]); wait(1); bmap_for_screen(b_render1,1,0);
vec_set(camera.pan, directions[3]); wait(1); bmap_for_screen(b_render2,1,0);
vec_set(camera.pan, directions[6]); wait(1); bmap_for_screen(b_render3,1,0);
vec_set(camera.pan, directions[9]); wait(1); bmap_for_screen(b_render4,1,0);
vec_set(camera.pan, directions[12]); wait(1); bmap_for_screen(b_render5,1,0);
vec_set(camera.pan, directions[15]); wait(1); bmap_for_screen(b_render6,1,0);
freeze_mode = off;

wait(1);
write_cubemap();

wait(1);
camera.arc = old_arc;
video_set(old_x, old_y, 32, old_screen);
}

on_c=capture_cubemap;
Posted By: Matt_Aufderheide

Re: Real DX9 Reflection - 12/15/04 08:29

the problem with this whole technique is that it is going to be extremely slow.. to do this properly you'd have to use render to texture.. instead of taking screenshots
Posted By: Josh_Arldt

Re: Real DX9 Reflection - 12/15/04 08:36

Not all of us have the render to texture feature.
Posted By: MMike

Re: Real DX9 Reflection - 12/15/04 09:12

thats why im taking this way..
Posted By: MMike

Re: Real DX9 Reflection - 12/15/04 10:21

Okay i can do the screenshot overwrite...

Now my only problem is refresh The Bmap picture in the shader material.. what im not getting to work..
Posted By: MMike

Re: Real DX9 Reflection - 12/15/04 13:06

Okay its done..
NOw it updates the environment cube, and it fake a real mirror..

Posted By: Drew

Re: Real DX9 Reflection - 12/15/04 14:19

can you please share? very cool...
Posted By: Joey

Re: Real DX9 Reflection - 12/15/04 22:19

i wrote a plugin that writes to a image handle from wdl... kinda fast (however depends on the size).
do you write the image data into a tga file on hd, or in memory? if you want, i can share my c++ code to improve your feature...
Posted By: EX Citer

Re: Real DX9 Reflection - 12/16/04 00:18

I am using as a sky cube a 64x64per square or something (very small), and itīs looking good even if it is scaled very large. So the mirror map wouldnīt have to be big ether. maybe 32x32 per square would be enough.

EX Citer
Posted By: M3PHiSTOPH3L3S

Re: Real DX9 Reflection - 12/16/04 04:56

First off, very cool. I agree that you should use very small maps. Maybe even set a detail level in the options or something.

Have you been able to generate the environment map from the center of the reflecting object with it being hidden yet? I was asking because I noticed in the screen that the sphere was reflecting itself.

Have you tryed setting this to refresh every second or so yet? If so, what kind of effect did it have on fps?

Good luck. This could possibly solve some of the problems of not having render-to-texture in the lower editions.

M3PHiSTO
Posted By: Drew

Re: Real DX9 Reflection - 12/16/04 05:38

maybe we could use this to get the scene glow/blur/bloom going too
Posted By: Matt_Aufderheide

Re: Real DX9 Reflection - 12/16/04 07:16

you can do the glow thing with this dll: renderview

just copy this into your plugin folder, and then in script declare this function:
dllfunction render_backbuffer(entity);

then make a screen sized quad as a view entity and make a function where you call:
me=scree_quad;
render_backbuffer(me);

i recommend using a small skin texture for the quad. like 64*64..otherwise it gets slow. Then you also apply some postprocessing like blur..
Posted By: Drew

Re: Real DX9 Reflection - 12/16/04 08:56

Wow, i will try (hehe yeah right!) but a glow filter is second after normal mapping as far as competetive looka nd feel...and you already contributed such a great normal map code...
Posted By: Matt_Aufderheide

Re: Real DX9 Reflection - 12/16/04 11:09

Are you saying you want a blur shader? i have one..i'll post it you want.. also Ello has posted a blur shader as well.
Posted By: EX Citer

Re: Real DX9 Reflection - 12/16/04 16:20

Drew is talking of the bloom shader I think... Yep, there he wrote it. The shader which makes bright areas in the view glowing. But I can need some blur shaders for my under water scenes. And I am still waiting for the parallax mapping shader... And of course for this reflaction master thingy

EX Citer
Posted By: MMike

Re: Real DX9 Reflection - 12/16/04 17:33

OKay guys im back.. eehh
Well I can share of course im not selfish )

Well the FPS is 137 FPs on my pc .. Cause it just use a normal env Map DX8

And to refresh you need to press t ( for now (test))... cause It needs to save to a bmp picture, as far as i know the screenshot its bmp, and then, it takes time to save to the disc, so we can't have a refrshment each frame..


Maybe your C++ plugin could be very useful don't know :S, shoud we give it a try..

Concerning to the sphere, im working on that , making it invisible when taking the shot ... ( sounds ugly).. ( but the fact of you seeing the shpere, is cause the model i used to that test has is axis not on the center, thats the only reason.. i made it like that, to be able to see the shpere reflection . ehe im not using templates, and even havent tryed to add a f7 (orbital cam) ehehh


The refectiong used to the cube , it based on the player pos... So it just works for the player for now. For multi object that would be Overload, cause it had to take a individual shot cubemap ... So i guess you are getting there..

Of course , this can be always used To simple reflections..
Posted By: Drew

Re: Real DX9 Reflection - 12/17/04 05:30

Quote:

Drew is talking of the bloom shader I think... Yep, there he wrote it. The shader which makes bright areas in the view glowing. But I can need some blur shaders for my under water scenes. And I am still waiting for the parallax mapping shader... And of course for this reflaction master thingy

EX Citer




yup, bloom filter is what I need, not blur... ala Prince o' persia...Is there one for non pro?!
sorry about the hijack

Great to hear abouth the fps... REALLY looking forward to this
Posted By: Matt_Aufderheide

Re: Real DX9 Reflection - 12/17/04 07:47

bloom is the same as blur basically..just render to the scene using my dll and then apply a blur shader
Posted By: Drew

Re: Real DX9 Reflection - 12/17/04 19:51

if you or someone could assemble this, would be amazing...I tried, I just dont have the chops
thanks
Posted By: Machinery_Frank

Re: Real DX9 Reflection - 12/17/04 20:08

... not only assembling. Please create a plugin and an easy way to use (little documentation). Then feel free to make an affordable price. That work should be honored. I would pay for it.

And if there is an option to choose between the render to texture mode and the slower one then would everyone be very happy.
Posted By: MMike

Re: Real DX9 Reflection - 12/17/04 23:22

The script im doing , Allow you to take cubemap shots, On walktrough Mode, and then you can place then in Static Objects (Don't move), of course the player won't be able to show in the reflection in this case... cause the texture is not refreshed..

For PLayer ( dinamic entity) the script let you take shot each 3 ( im not sure , seconds) refreshing the envirnoment cube map, based on player position.
Posted By: key_46

Re: Real DX9 Reflection - 12/19/04 03:17

Really i have make a simple shader using alpha map and a simple cube map:



Posted By: Metal_Thrasher

Re: Real DX9 Reflection - 12/26/04 04:40

Quote:

Use what Pappenheimer suggested.
This saves the bitmaps as a cubemap instead of shot1, shot2 ect...

savedir="output";
var_nsave fh;
bmap* canvas;
bmap* b_render1;
bmap* b_render2;
bmap* b_render3;
bmap* b_render4;
bmap* b_render5;
bmap* b_render6;
var cubenumber = 0;
var directions[18] = 180, 0, 0, 90, 0, 0, 0, 0, 0, -90, 0, 0, 90, -90, 0, 90, 90, 0;
string tempstring1;
string tempstring2;
string _ts_;

//----------------------------------------------------------------------------- write_cubemap
function write8(byte) // write char
{
file_asc_write(fh, byte);
}

function write16(short) // write unsigned short
{
file_asc_write(fh, short&255);
file_asc_write(fh, (short>>8)&255);
}

function str_padding(str, number, padding)
{
str_for_num(_ts_, number);
var i = 0;
i = padding - str_len(_ts_);
while(i > 0)
{
str_cat(str, "0");
i-=1;
}
str_cat(str, _ts_);
}

function write_cubemap()
{
var i;
var xx;
var yy;
var format;
var pixel;
var pixelalpha;
var canvas_size[2];

canvas_size.x = bmap_width(b_render1);
canvas_size.y = bmap_height(b_render1);
format = bmap_lock(b_render1, 0);
bmap_lock(b_render2, 0);
bmap_lock(b_render3, 0);
bmap_lock(b_render4, 0);
bmap_lock(b_render5, 0);
bmap_lock(b_render6, 0);

str_cpy(tempstring1, "cubemap");
str_padding(tempstring1, cubenumber, 4);
str_cat(tempstring1, "+6.tga");
fh = file_open_write(tempstring1);
cubenumber+=1;
//--------------------------------------------------------write header
write8(0);
write8(0);
write8(2); // image type
write16(0);
write16(0);
write8(0);
write16(0);
write16(0);
write16(canvas_size.x * 6); // width
write16(canvas_size.y); // height
write8(24); // color depth
write8(0);
//--------------------------------------------------------write image data
yy = canvas_size.y - 1;
while(yy >= 0)
{
i = 0;
while(i < 6)
{
if(i==0){canvas=b_render1;}
if(i==1){canvas=b_render2;}
if(i==2){canvas=b_render3;}
if(i==3){canvas=b_render4;}
if(i==4){canvas=b_render5;}
if(i==5){canvas=b_render6;}
xx = 0;
while(xx < canvas_size.x)
{
pixel = pixel_for_bmap(canvas, xx, yy);
pixel_to_vec(temp, pixelalpha, format, pixel);
write8(temp.x); // b
write8(temp.y); // g
write8(temp.z); // r
xx+=1;
}
i+=1;
}
yy-=1;
}
file_close(fh);
bmap_unlock(b_render1);
bmap_unlock(b_render2);
bmap_unlock(b_render3);
bmap_unlock(b_render4);
bmap_unlock(b_render5);
bmap_unlock(b_render6);
}

//----------------------------------------------------------------------------- capture_cubemap
function capture_cubemap
{
var old_arc;
var old_x;
var old_y;
var old_screen;

b_render1 = bmap_create("render.tga"); // use a 256x256 tga for example -> determines cube map size
b_render2 = bmap_create("render.tga");
b_render3 = bmap_create("render.tga");
b_render4 = bmap_create("render.tga");
b_render5 = bmap_create("render.tga");
b_render6 = bmap_create("render.tga");

old_arc = camera.arc;
old_x = screen_size.x;
old_y = screen_size.y;
old_screen = video_screen;

camera.arc = 90;
video_set(256, 256, 32, 2); // should be same resolution as render.tga

freeze_mode = on;
vec_set(camera.pan, directions[0]); wait(1); bmap_for_screen(b_render1,1,0);
vec_set(camera.pan, directions[3]); wait(1); bmap_for_screen(b_render2,1,0);
vec_set(camera.pan, directions[6]); wait(1); bmap_for_screen(b_render3,1,0);
vec_set(camera.pan, directions[9]); wait(1); bmap_for_screen(b_render4,1,0);
vec_set(camera.pan, directions[12]); wait(1); bmap_for_screen(b_render5,1,0);
vec_set(camera.pan, directions[15]); wait(1); bmap_for_screen(b_render6,1,0);
freeze_mode = off;

wait(1);
write_cubemap();

wait(1);
camera.arc = old_arc;
video_set(old_x, old_y, 32, old_screen);
}

on_c=capture_cubemap;



Now, what kind of action will attach this screenshot to an entity?
Posted By: Josh_Arldt

Re: Real DX9 Reflection - 12/26/04 10:38

Quote:

str_cpy(tempstring1, "cubemap");



I believe this is the name of the cubemap it writes. It writes it as cubemap+6.tga. Just use a cubemap shader and change the cubemap to this one.
Posted By: Braxton

Re: Real DX9 Reflection - 12/28/04 12:00

Is the original shader for C-Script or C++.
Posted By: Metal_Thrasher

Re: Real DX9 Reflection - 12/31/04 08:02

The very first piost is C++ I think, the filename was something.cpp.
Posted By: Braxton

Re: Real DX9 Reflection - 12/31/04 09:42

How do we use HumanSandBags shager in a 3DGS level.
Posted By: Braxton

Re: Real DX9 Reflection - 12/31/04 09:46

I mean I pasted his (HumanSandBag) code in a new script file and then saved it as DX9.wdl now when I load the level and try to add the code to the player (in behaviors) nothing shows up. I have added the DX9 code to my A^ template code externally. How can I fix this???
Posted By: Metal_Thrasher

Re: Real DX9 Reflection - 12/31/04 12:05

Well, HSB's code there is for taking the cobe map picture...the actual code for it is on the wiki page on the bottom of this page. I just used sky texture instead of a cobe map and I got a very pretty crome-effect.
Posted By: Braxton

Re: Real DX9 Reflection - 12/31/04 12:11

How do I add the original code to 3DGS... where can I get a dll. The one on the forum is for Visual C++ I need one for Dev-C++. I want to try this out but I need to know how.
Posted By: Metal_Thrasher

Re: Real DX9 Reflection - 12/31/04 13:24

It's not a dll, it's a wdl file using c-script not C++. It's in Wiki.
Posted By: Braxton

Re: Real DX9 Reflection - 12/31/04 13:34

I am talking about the original... I want to use that one.
Posted By: Braxton

Re: Real DX9 Reflection - 12/31/04 13:42

Well DragonX Dark - Do you have a link to the shader... can't seem to find on called DirextX9 Reflections shader.
Posted By: Metal_Thrasher

Re: Real DX9 Reflection - 12/31/04 13:42

Quote:

I am talking about the original... I want to use that one.



oh :P sorry
Posted By: Braxton

Re: Real DX9 Reflection - 12/31/04 13:46

I want the link to your C-Script one now... PLEASE!!!
Posted By: Metal_Thrasher

Re: Real DX9 Reflection - 12/31/04 13:47

Quote:

Well, HSB's code there is for taking the cobe map picture...the actual code for it is on the wiki page on the bottom of this page. I just used sky texture instead of a cobe map and I got a very pretty crome-effect.



You mean the one I was talking about here? with the crome effect?
Posted By: Braxton

Re: Real DX9 Reflection - 12/31/04 14:19

What are you talking about???
Posted By: MMike

Re: Real DX9 Reflection - 01/02/05 00:29

this is MY code For "Real" Cube map DX8

:


var cuberesolution=128; // set up the resolution of the cube here
//var cubeposition[3]=0,0,200; // set up the position of the cube here (you could also set cubeposition to the camera position)
var cubeposition=player.pos; // set up the position of the cube here (you could also set cubeposition to the camera position)
var west[3]=180,0,0;
var north[3]=90,0,0;
var east[3]=0,0,0;
var south[3]=-90,0,0;
var down[3]=90,-90,0;
var up[3]=90,90,0;




bmap cube_panel =<cube.tga>;

panel cube_map{

layer=1;
bmap = cube_panel;
flags = visible, overlay;
pos_x=0;
pos_y=0;


}
view Cv_w
{
layer = 2;


pos_y = 0;
size_x = 128;
size_y = 128;
arc = 90;
aspect = 1;
flags= visible;

}


view Cv_n
{
layer = 2;

pos_y = 0;
size_x = 128;
size_y = 128;
arc = 90;
aspect = 1;
flags= visible;

}
view Cv_e
{
layer = 2;

pos_y = 0;
size_x = 128;
size_y = 128;
arc = 90;
aspect = 1;
flags= visible;

}
view Cv_s
{
layer = 2;

pos_y = 0;
size_x = 128;
size_y = 128;
arc = 90;
aspect = 1;
flags= visible;

}
view Cv_d
{
layer = 2;

pos_y = 0;
size_x = 128;
size_y = 128;
arc = 90;
aspect = 1;
flags= visible;

}
view Cv_u
{
layer = 2;

pos_y = 0;
size_x = 128;
size_y = 128;
arc = 90;
aspect = 1;
flags= visible;

}



var n=0;
var v=0;
var r=0;
var cubeposition1;
function CUbereal {





while(1){


cubeposition=player.pos;


vec_set(cv_w.x,cubeposition1);
vec_set(cv_w.pan,west);
cv_w.x=player.x;
cv_w.y=player.y;

v=-128;
n=1;
cv_w.pos_x=v+128*n;
n=2;
cv_n.pos_x=v+128*n;
n=3;
cv_e.pos_x=v+128*n;
n=4;
cv_s.pos_x=v+128*n;
n=5;
cv_d.pos_x=v+128*n;
n=6;
cv_u.pos_x=v+128*n;


vec_set(cv_n.x,cubeposition1);
vec_set(cv_n.pan,north);
cv_n.x=player.x;
cv_n.y=player.y;

vec_set(cv_e.x,cubeposition1);
vec_set(cv_e.pan,east);
cv_e.x=player.x;
cv_e.y=player.y;

vec_set(cv_s.x,cubeposition1);
vec_set(cv_s.pan,south);
cv_s.x=player.x;
cv_s.y=player.y;

vec_set(cv_d.x,cubeposition1);
vec_set(cv_d.pan,down);
cv_d.x=player.x;
cv_d.y=player.y;


vec_set(cv_u.x,cubeposition1);
vec_set(cv_u.pan,up);
cv_u.x=player.x;
cv_u.y=player.y;








wait(1);

}


}

bmap bcube=<shot_0.bmp>;
bmap bcube1=<shot_1.bmp>;



function take_cube {
player.invisible=on;
CUbereal();
player.invisible=on;
video_set(768,128,32,2);wait(2);
screenshot("shot_",_shot_no);
wait(2);
//video_switch(800,650,32,1);
video_switch(7,32,1);



}
//on_c CUbereal;
on_t take_cube;


}



function mtl_envmap_view()
{
mat_set(mtl.matrix,matViewInv);
mtl.matrix41=0;
mtl.matrix42=0;
mtl.matrix43=0;
}




function mtl_envmap_init()
{


player.invisible=on;
take_cube();
player.invisible=on;
//bmap_purge(bcube); // Get rid of what is in tex memory
// read from disk // as Skin1, else it will accumulate and
bmap_load(bcube, "shot_0.bmp",0);



//...maybe you should copy the mat_model properties here...

mtl.skin1=bcube;

bmap_to_cubemap(mtl.skin1);
mtl.event=mtl_envmap_view;
mtl.enable_view=on;
mtl.enable_render=on;
player.invisible=off;



}


material mtl_envmap
{

event=mtl_envmap_init;

effect=
"
texture entSkin1;
texture mtlSkin1;
matrix matMtl;
technique envmap
{
pass p0
{
texture[0]=<entSkin1>;
texture[1]=<mtlSkin1>;

zWriteEnable=true;
alphaBlendEnable=false;

colorArg1[0]=Texture;
colorOp[0]=Modulate2x;
colorArg2[0]=Diffuse;

colorArg1[1]=Texture;
colorOp[1]=blendCurrentAlpha;
addressU[1]=Clamp;
addressV[1]=Clamp;
texCoordIndex[1]=cameraSpaceReflectionVector;
textureTransformFlags[1]=Count3;
textureTransform[1]=<matMtl>; // transform camera space back to world space
}
}
";
}

//starter lol
//{mtl_envmap.skin1=bcube;
//wait(1);

//}


action Reflections {

//VLight_orange();
//physics_lamp();

// my.pan+=8*time;
// my.roll+=8*time;


my.material=mtl_envmap;
}


function mem {

//player.invisible=on;
player.invisible=on;


bmap_purge(mtl_envmap.skin1);
mtl_envmap.skin1=mtl_envmap.skin1;
mtl_envmap_init();


}

on_t mem;







action player1
{my.material=mtl_envmap;
player = my;
//my.invisible = on;
my.passable=on;
while (1)
{
camera.x=player.x;
camera.y=player.y;

//vec_set (camera.x, my.x);
//vec_set (camera.y, my.y);
//vec_set (camera.pos, my.pos);
//vec_set (camera.pos, my.pos);

camera.pan = my.pan;
camera.tilt += 10 * mouse_force.y * time;
my.pan -= 10 * mouse_force.x * time;
temp.x = 25 * (key_w - key_s) * time;
temp.y = 25 * (key_a - key_d) * time;
//temp.z = 0;

ent_move (temp, nullvector);
wait (1);
}

}






you need a bmap called.. go check it above lazy "shot_0.bmp"

Oh and [T] to save the cube map to a file ... then all you need to do is A env shader, where the file you use as cube map is that one.. so its refreshed.. the shader name I have is reflections, but you assig it to the player or something like that .. action player1 then you must use orbital cam , to check the effect..
Posted By: Matt_Aufderheide

Re: Real DX9 Reflection - 01/02/05 12:48

I dont get this .. what is the screenshot() function? there isnt one here...
Posted By: MMike

Re: Real DX9 Reflection - 01/02/05 22:29

what? you don't have, I found that on old documents.. and i though you could use.. You can replace that with the new bmpa thing though.. mayge its the best sollution.
Posted By: Braxton

Re: Real DX9 Reflection - 01/03/05 12:18

So does anyone have a dll for the "original" DirectX9 reflection shader done in C++. If you do could you please give it to me, with instructions on how to use it. I am using Dev-C++ incase you wanted to know.
Posted By: Rhuarc

Re: Real DX9 Reflection - 01/03/05 12:53

Shaders are not programmed in C++, they are coded either in HLSL or ASM. They are then loaded via the rendering engine to the hardware. They are not made with a DLL.

If you are referring to the render to texture technique, that is not a shader in any way. Matt's DLL can be downloaded here:
http://www.conitecserver.com/ubbthreads/showflat.php?Cat=&Number=468764&page=0&view=collapsed&sb=5&o=&fpart=1#468764
I doubt he'd share the sourcecode with you though.

If you don't know the difference between a render to texture DLL and a Dx9 shader, I'd reccomend learning the basics before even thinking about shaders and rendering concepts.

-Rhuarc
Posted By: Braxton

Re: Real DX9 Reflection - 01/07/05 12:25

O thanks
Posted By: key_46

Re: Real DX9 Reflection - 01/23/05 22:04

I am trying use view.bmap and attach it in a bitmap an paint it in a cubemap, but the bmap attached to the view can't be locked and used, why?
© 2024 lite-C Forums