1
0
forked from metin2/client

Solution refactoring and restructuring, removed Boost dependency, removed unused tools

This commit is contained in:
2022-11-21 23:42:01 +02:00
parent 33f19f9ff6
commit 9ef9f39e88
817 changed files with 326 additions and 59698 deletions

View File

@ -0,0 +1,213 @@
///////////////////////////////////////////////////////////////////////
// Name: BoundaryShapeManager.cpp
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// Copyright (c) 2002-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may not
// be copied or disclosed except in accordance with the terms of that
// agreement.
///////////////////////////////////////////////////////////////////////
// Preprocessor
#include "StdAfx.h"
#include <windows.h>
#include "../eterbase/Random.h"
#include "BoundaryShapeManager.h"
using namespace std;
///////////////////////////////////////////////////////////////////////
// CBoundaryShapeManager::CBoundaryShapeManager
CBoundaryShapeManager::CBoundaryShapeManager()
{
}
///////////////////////////////////////////////////////////////////////
// CBoundaryShapeManager::~CBoundaryShapeManager
CBoundaryShapeManager::~CBoundaryShapeManager()
{
}
///////////////////////////////////////////////////////////////////////
// CBoundaryShapeManager::LoadBsfFile
bool CBoundaryShapeManager::LoadBsfFile(const char* pszFilename)
{
bool bSuccess = true;
try
{
FILE* pFile = fopen(pszFilename, "rb");
if (pFile)
{
// number of boundary shapes
unsigned int nNumBoundaries;
if (fread(&nNumBoundaries, sizeof(unsigned int), 1, pFile) == 1)
{
for (unsigned int i = 0; i < nNumBoundaries && bSuccess; ++i)
{
SBoundaryShape sShape;
// number of contours for this shape
unsigned int nNumContours;
if (fread(&nNumContours, sizeof(unsigned int), 1, pFile) == 1)
{
for (unsigned int j = 0; j < nNumContours && bSuccess; ++j)
{
// number of points in this contour
vector<SPoint> vPoints;
unsigned int nNumPoints;
if (fread(&nNumPoints, sizeof(unsigned int), 1, pFile) == 1)
{
// read the points
for (unsigned int k = 0; k < nNumPoints && bSuccess; ++k)
{
SPoint sPoint;
if (fread(sPoint.m_afData, sizeof(float), 3, pFile) == 3)
{
vPoints.push_back(sPoint);
// update extents
if (j == 0 && k == 0)
{
// first point of this shape
memcpy(sShape.m_afMin, sPoint.m_afData, 3 * sizeof(float));
memcpy(sShape.m_afMax, sPoint.m_afData, 3 * sizeof(float));
}
else
{
// check extents
for (int l = 0; l < 3; ++l)
{
if (sPoint.m_afData[l] < sShape.m_afMin[l])
sShape.m_afMin[l] = sPoint.m_afData[l];
else if (sPoint.m_afData[l] > sShape.m_afMax[l])
sShape.m_afMax[l] = sPoint.m_afData[l];
}
}
}
else
{
m_strCurrentError = "Error in CBoundaryShapeManager::LoadBsfFile(): Failed to read point";
bSuccess = false;
}
}
sShape.m_vContours.push_back(vPoints);
}
else
{
m_strCurrentError = "Error in CBoundaryShapeManager::LoadBsfFile(): Failed to read number of points";
bSuccess = false;
}
}
m_vBoundaries.push_back(sShape);
}
else
{
m_strCurrentError = "Error in CBoundaryShapeManager::LoadBsfFile(): Failed to read number of contours";
bSuccess = false;
}
}
}
else
{
m_strCurrentError = "Error in CBoundaryShapeManager::LoadBsfFile(): Failed to read number of boundaries";
bSuccess = false;
}
fclose(pFile);
}
else
{
m_strCurrentError = string("Error in CBoundaryShapeManager::LoadBsfFile(): Could not open ") + string(pszFilename);
bSuccess = false;
}
}
catch(...)
{
m_strCurrentError = "Error in CBoundaryShapeManager::LoadBsfFile(): Unknown exception";
}
return bSuccess;
}
///////////////////////////////////////////////////////////////////////
// CBoundaryShapeManager::PointInside
bool CBoundaryShapeManager::PointInside(float fX, float fY)
{
bool bInside = false;
for (DWORD i = 0; i < m_vBoundaries.size() && !bInside; ++i)
bInside = PointInShape(m_vBoundaries[i], fX, fY);
return bInside;
}
///////////////////////////////////////////////////////////////////////
// CBoundaryShapeManager::PointInShape
bool CBoundaryShapeManager::PointInShape(SBoundaryShape& sShape, float fX, float fY)
{
bool bInside = false;
for (DWORD k = 0; k < sShape.m_vContours.size(); ++k)
{
for (DWORD i = 0, j = sShape.m_vContours[k].size() - 1; i < sShape.m_vContours[k].size(); j = i++)
{
if ((((sShape.m_vContours[k][i][1] <= fY) && (fY < sShape.m_vContours[k][j][1])) ||
((sShape.m_vContours[k][j][1] <= fY) && (fY < sShape.m_vContours[k][i][1]))) &&
(fX < (sShape.m_vContours[k][i][0] - sShape.m_vContours[k][i][0]) * (fY - sShape.m_vContours[k][i][1]) / (sShape.m_vContours[k][j][1] - sShape.m_vContours[k][i][1]) + sShape.m_vContours[k][i][0]))
{
bInside = !bInside;
}
}
}
return bInside;
}
///////////////////////////////////////////////////////////////////////
// CBoundaryShapeManager::RandomPoint
bool CBoundaryShapeManager::RandomPoint(float& fX, float& fY)
{
bool bSuccess = false;
if (m_vBoundaries.size() > 0)
{
// pick a random boundary shape
int nIndex = random_range(0, m_vBoundaries.size() - 1);
SBoundaryShape& sShape = m_vBoundaries[nIndex];
// pick a point at random within its extents
fX = frandom(sShape.m_afMin[0], sShape.m_afMax[0]);
fY = frandom(sShape.m_afMin[1], sShape.m_afMax[1]);
// try it
bSuccess = PointInShape(sShape, fX, fY);
}
return bSuccess;
}

View File

@ -0,0 +1,67 @@
// Name: BoundaryShapeManager.h
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// Copyright (c) 2002-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may not
// be copied or disclosed except in accordance with the terms of that
// agreement.
//
// Release version 1.0
///////////////////////////////////////////////////////////////////////
// Preprocessor
#include <vector>
#include <string>
///////////////////////////////////////////////////////////////////////
// SPoint
struct SPoint
{
float& operator[](int i) { return m_afData[i]; }
float m_afData[3];
};
///////////////////////////////////////////////////////////////////////
// SBoundaryShape
struct SBoundaryShape
{
std::vector< std::vector<SPoint> > m_vContours;
float m_afMin[3];
float m_afMax[3];
};
///////////////////////////////////////////////////////////////////////
// CBoundaryShapeManager
class CBoundaryShapeManager
{
public:
CBoundaryShapeManager( );
virtual ~CBoundaryShapeManager( );
bool LoadBsfFile(const char* pFilename);
bool PointInside(float fX, float fY);
bool RandomPoint(float& fX, float& fY);
std::string GetCurrentError( ) { return m_strCurrentError; }
private:
bool PointInShape(SBoundaryShape& sShape, float fX, float fY);
std::vector<SBoundaryShape> m_vBoundaries;
std::string m_strCurrentError;
};

View File

@ -0,0 +1,162 @@
///////////////////////////////////////////////////////////////////////
// Constants
//
// (c) 2003 IDV, Inc.
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may
// not be copied or disclosed except in accordance with the terms of
// that agreement.
//
// Copyright (c) 2001-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
//
#pragma once
//#include "LibVector_Source/IdvVector.h"
//#include "../Common Source/Filename.h"
// used to isolate SpeedGrass usage
#define USE_SPEEDGRASS
// paths
//const CFilename c_strTreePath = "../data/TheValley/Trees/";
//const CFilename c_strDataPath = "../data/TheValley/";
// vertex shader constant locations
const int c_nShaderLightPosition = 16;
const int c_nShaderGrassBillboard = 4;
const int c_nShaderGrassLodParameters = 8;
const int c_nShaderCameraPosition = 9;
const int c_nShaderGrassWindDirection = 10;
const int c_nShaderGrassPeriods = 11;
const int c_nShaderLeafAmbient = 47;
const int c_nShaderLeafDiffuse = 48;
const int c_nShaderLeafSpecular = 49;
const int c_nShaderLeafLightingAdjustment = 50;
// lighting
//const float c_afLightDirBumpMapping[3] = { 0.8f, 0.0f, 0.4f };
//const float c_afLightDir[3] = { 0.7434f, 0.0f, 0.57f };
//const float c_afLightPos[3] = { c_afLightDir[0] * 1000.0f, c_afLightDir[1] * 1000.0f, c_afLightDir[2] * 1000.0f };
// stats
//const int c_nStatFrameRate = 0;
//const int c_nStatDrawTime = 1;
//const int c_nStatSceneTriangles = 2;
//const int c_nStatTriangleRate = 3;
//const int c_nStatNone = 4;
//const int c_nStatSummary = 5;
//const int c_nStatCount = 6;
// grass
const float c_fDefaultGrassFarLod = 300.0f;
const float c_fGrassFadeLength = 50.0f;
const float c_fMinBladeNoise = -0.2f;
const float c_fMaxBladeNoise = 0.2f;
const float c_fMinBladeThrow = 1.0f;
const float c_fMaxBladeThrow = 2.5f;
const float c_fMinBladeSize = 7.5f;
const float c_fMaxBladeSize = 10.0f;
const int c_nNumBladeMaps = 2;
const float c_fGrassBillboardWideScalar = 1.75f;
const float c_fWalkerHeight = 12.0f;
const int c_nDefaultGrassBladeCount = 33000;
const int c_nGrassRegionCount = 20;
// terrain
//const float c_fTerrainBaseRepeat = 1.0f;
//const float c_fTerrainDetail1Repeat = 80.0f;
//const float c_fTerrainDetail2Repeat = 8.0f;
// wind
//const int c_nNumWindMatrices = 4; // number of unique wind matrices
//const int c_nNumMatricesPerTree = 3; // number of individual matrices used per tree
//const float c_fShimmerSpeed = 50.0f; // controls how fast the shimmer map rotates
//const float c_fShimmerExponent = 3.0f; // controls linearity of shimmer speed
// lod
//const float c_fShadowCutoff = 5000.0f; // how far out shadows are no longer drawn (feet)
//const float c_fBillboardAlphaValue = 0.3294f; // value for glAlphaFunc() for single billboards
//const float c_fNearLod = 200.0f;
//const float c_fFarLod = 750.0f;
// misc
const float c_fPi = 3.1415926535897932384626433832795f;
const float c_fHalfPi = c_fPi * 0.5f;
const float c_fQuarterPi = c_fPi * 0.25f;
const float c_fTwoPi = 2.0f * c_fPi;
const float c_fDeg2Rad = 57.29578f; // divide degrees by this to get radians
const float c_f90 = 0.5f * c_fPi;
// branch vertex attribute sizes
//const int c_nBranchVertexTexture0Size = 4 * sizeof(float); // normal map coordinates + wind index + wind weight
//const int c_nBranchVertexTexture1Size = 3 * sizeof(float); // vertex tangents
//const int c_nBranchVertexTexture2Size = 3 * sizeof(float); // vertex binormals
//const int c_nBranchVertexTexture3Size = 2 * sizeof(float); // branch/frond shadow projection coordinates
//const int c_nBranchVertexNormalSize = 3 * sizeof(float); // (nx, ny, nz)
//const int c_nBranchVertexPositionSize = 3 * sizeof(float); // (x, y, z)
//
//const int c_nBranchVertexTotalSize = c_nBranchVertexTexture0Size +
// c_nBranchVertexTexture1Size +
// c_nBranchVertexTexture2Size +
// c_nBranchVertexTexture3Size +
// c_nBranchVertexNormalSize +
// c_nBranchVertexPositionSize;
// frond vertex attribute sizes
//const int c_nFrondVertexTexture0Size = 2 * sizeof(float); // normal map coordinates
//const int c_nFrondVertexNormalSize = 3 * sizeof(float); // (nx, ny, nz)
//const int c_nFrondVertexPositionSize = 3 * sizeof(float); // (x, y, z)
//
//const int c_nFrondVertexTotalSize = c_nFrondVertexTexture0Size +
// c_nFrondVertexNormalSize +
// c_nFrondVertexPositionSize;
// leaf vertex attribute sizes
//const int c_nLeafVertexTexture0Size = 2 * sizeof(float); // base map coordinate
//const int c_nLeafVertexTexture1Size = 2 * sizeof(float); // shimmer map coordinates (s & t) + shimmer-effect index
//const int c_nLeafVertexNormalSize = 3 * sizeof(float); // (nx, ny, nz)
//const int c_nLeafVertexPositionSize = 3 * sizeof(float); // (x, y, z)
//
//const int c_nLeafVertexTotalSize = c_nLeafVertexTexture0Size +
// c_nLeafVertexTexture1Size +
// c_nLeafVertexNormalSize +
// c_nLeafVertexPositionSize;
// grass vertex attribute sizes
const int c_nGrassVertexTexture0Size = 2 * sizeof(float); // base map coordinate
const int c_nGrassVertexTexture1Size = 4 * sizeof(float); // vertex index, blade size, wind weight, noise factor
const int c_nGrassVertexColorSize = 4 * sizeof(unsigned char); // (rgba)
const int c_nGrassVertexPositionSize = 3 * sizeof(float); // (x, y, z)
const int c_nGrassVertexTotalSize = c_nGrassVertexTexture0Size +
c_nGrassVertexTexture1Size +
c_nGrassVertexColorSize +
c_nGrassVertexPositionSize;
// terrain vertex attribute sizes
//const int c_nTerrainVertexTexture0Size = 2 * sizeof(float);
//const int c_nTerrainVertexTexture1Size = 2 * sizeof(float);
//const int c_nTerrainVertexTexture2Size = 2 * sizeof(float);
//const int c_nTerrainVertexPositionSize = 3 * sizeof(float); // (x, y, z)
//const int c_nTerrainVertexTotalSize = c_nTerrainVertexTexture0Size +
// c_nTerrainVertexTexture1Size +
// c_nTerrainVertexTexture2Size +
// c_nTerrainVertexPositionSize;
// crosshair
//const float c_fCrosshairSize = 25.0f;
//const float c_fCrosshairAlpha = 0.075f;

View File

@ -0,0 +1,769 @@
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT Class
//
// (c) 2003 IDV, Inc.
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may
// not be copied or disclosed except in accordance with the terms of
// that agreement.
//
// Copyright (c) 2001-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
#include "StdAfx.h"
#include "BoundaryShapeManager.h"
#ifdef USE_SPEEDGRASS
inline float VecInterpolate(float fStart, float fEnd, float fPercent)
{
return fStart + (fEnd - fStart) * fPercent;
}
#define VectorSinD(x) sinf((x) / 57.29578f)
#define VectorCosD(x) cosf((x) / 57.29578f)
using namespace std;
// macros
#ifndef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
// static variables
float CSpeedGrassRT::m_fLodFarDistance = 100.0f;
float CSpeedGrassRT::m_fLodTransitionLength = 37.5f;
float CSpeedGrassRT::m_afUnitBillboard[12] = { 0.0f };
float CSpeedGrassRT::m_afWindDir[4] = { 1.0f, 0.3f, 0.0f, 0.0f };
// camera
float CSpeedGrassRT::m_afCameraOut[3] = { 0.0f, 1.0f, 0.0f };
float CSpeedGrassRT::m_afCameraUp[3] = { 0.0f, 0.0f, 1.0f };
float CSpeedGrassRT::m_afCameraRight[3] = { 1.0f, 0.0f, 0.0f };
float CSpeedGrassRT::m_afCameraPos[3] = { 0.0f, 0.0f, 0.0f };
float CSpeedGrassRT::m_fFieldOfView = D3DXToRadian(40.0f);
float CSpeedGrassRT::m_fAspectRatio = 4.0f / 3.0f;
// culling
float CSpeedGrassRT::m_afFrustumBox[6] = { 0.0f };
float CSpeedGrassRT::m_afFrustumMin[2] = { FLT_MAX, FLT_MAX };
float CSpeedGrassRT::m_afFrustumMax[2] = { -FLT_MAX, -FLT_MAX };
float CSpeedGrassRT::m_afFrustumPlanes[5][4] = { 0.0f };
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::SBlade::SBlade
CSpeedGrassRT::SBlade::SBlade( ) :
m_fSize(1.0f),
m_fNoise(0.0f),
m_fThrow(0.0f),
m_ucWhichTexture(0)
{
m_afBottomColor[0] = m_afBottomColor[1] = m_afBottomColor[2] = 1.0f;
m_afTopColor[0] = m_afTopColor[1] = m_afTopColor[2] = 1.0f;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::SRegion::SRegion
CSpeedGrassRT::SRegion::SRegion( ) :
m_bCulled(false),
m_fCullingRadius(1.0f)
{
m_afCenter[0] = m_afCenter[1] = m_afCenter[2] = 0.5f;
m_afMin[0] = m_afMin[1] = m_afMin[2] = 0.0f;
m_afMax[0] = m_afMax[1] = m_afMax[2] = 1.0f;
m_VertexBuffer.Destroy();
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::CSpeedGrassRT
CSpeedGrassRT::CSpeedGrassRT( ) :
m_nNumRegions(0),
m_nNumRegionCols(0),
m_nNumRegionRows(0),
m_pRegions(NULL),
m_bAllRegionsCulled(false)
{
m_afBoundingBox[0] = m_afBoundingBox[1] = m_afBoundingBox[2] = 0.0f;
m_afBoundingBox[3] = m_afBoundingBox[4] = m_afBoundingBox[5] = 1.0f;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::~CSpeedGrassRT
CSpeedGrassRT::~CSpeedGrassRT( )
{
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::DeleteRegions
void CSpeedGrassRT::DeleteRegions(void)
{
delete[] m_pRegions;
m_pRegions = NULL;
m_nNumRegions = 0;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::GetRegions
const CSpeedGrassRT::SRegion* CSpeedGrassRT::GetRegions(unsigned int& uiNumRegions)
{
uiNumRegions = m_nNumRegions;
return m_pRegions;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::ParseBsfFile
bool CSpeedGrassRT::ParseBsfFile(const char* pFilename, unsigned int nNumBlades, unsigned int uiRows, unsigned int uiCols, float fCollisionDistance)
{
bool bSuccess = false;
// copy region settings
m_nNumRegionCols = int(uiCols);
m_nNumRegionRows = int(uiRows);
// initialize bounding box
m_afBoundingBox[0] = m_afBoundingBox[1] = m_afBoundingBox[2] = FLT_MAX;
m_afBoundingBox[3] = m_afBoundingBox[4] = m_afBoundingBox[5] = -FLT_MAX;
CBoundaryShapeManager cManager;
vector<SBlade> vSceneBlades;
if (cManager.LoadBsfFile(pFilename))
{
for (unsigned int i = 0; i < nNumBlades; ++i)
{
SBlade sBlade;
// try to place a blade
if (cManager.RandomPoint(sBlade.m_afPos[0], sBlade.m_afPos[1]))
{
sBlade.m_afPos[2] = Height(sBlade.m_afPos[0], sBlade.m_afPos[1], sBlade.m_afNormal);
// CVec3 cNormal(sBlade.m_afNormal[0], sBlade.m_afNormal[1], sBlade.m_afNormal[2]);
// cNormal.Normalize( );
// cNormal[2] = -cNormal[2];
// memcpy(sBlade.m_afNormal, cNormal, 3 * sizeof(float));
D3DXVECTOR3 v3Normal(sBlade.m_afNormal[0], sBlade.m_afNormal[1], sBlade.m_afNormal[2]);
D3DXVec3Normalize(&v3Normal, &v3Normal);
v3Normal.z = -v3Normal.z;
sBlade.m_afNormal[0] = v3Normal.x;
sBlade.m_afNormal[1] = v3Normal.y;
sBlade.m_afNormal[2] = v3Normal.z;
// check against overall scene bounding box
for (int nAxis = 0; nAxis < 3; ++nAxis)
{
m_afBoundingBox[nAxis] = min(m_afBoundingBox[nAxis], sBlade.m_afPos[nAxis]);
m_afBoundingBox[nAxis + 3] = max(m_afBoundingBox[nAxis + 3], sBlade.m_afPos[nAxis]);
}
// set bottom and top color
float fHeightPercent = Color(sBlade.m_afPos[0], sBlade.m_afPos[1], sBlade.m_afNormal, sBlade.m_afTopColor, sBlade.m_afBottomColor);
sBlade.m_fSize = VecInterpolate(c_fMinBladeSize, c_fMaxBladeSize, fHeightPercent);
// assign which blade texture map
sBlade.m_ucWhichTexture = GetRandom(0, c_nNumBladeMaps - 1);
// compute wind effects
sBlade.m_fNoise = GetRandom(c_fMinBladeNoise, c_fMaxBladeNoise);
sBlade.m_fThrow = GetRandom(c_fMinBladeThrow, c_fMaxBladeThrow);
// store all blades together
vSceneBlades.push_back(sBlade);
}
}
bSuccess = true;
}
else
fprintf(stderr, "%s\n", cManager.GetCurrentError( ).c_str( ));
if (bSuccess)
CreateRegions(vSceneBlades, fCollisionDistance);
return bSuccess;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::CustomPlacement
//
// Use this function to perform custom grass blade placement. Feel free
// to add parameters as necessary but be sure to call CreateRegions( )
// at the end of the function to set up the SpeedGrass region system.
bool CSpeedGrassRT::CustomPlacement(unsigned int uiRows, unsigned int uiCols)
{
// copy region settings (do not remove)
m_nNumRegionCols = int(uiCols);
m_nNumRegionRows = int(uiRows);
// initialize bounding box (do not remove)
m_afBoundingBox[0] = m_afBoundingBox[1] = m_afBoundingBox[2] = FLT_MAX;
m_afBoundingBox[3] = m_afBoundingBox[4] = m_afBoundingBox[5] = -FLT_MAX;
// place one blade as an example
vector<SBlade> vSceneBlades;
SBlade sBlade;
sBlade.m_afPos[0] = 0.0f;
sBlade.m_afPos[1] = 0.0f;
sBlade.m_afPos[2] = 0.0f;
sBlade.m_afNormal[0] = 0.0f;
sBlade.m_afNormal[1] = 0.0f;
sBlade.m_afNormal[2] = 1.0f;
// check against overall scene bounding box (always do this)
for (int nAxis = 0; nAxis < 3; ++nAxis)
{
m_afBoundingBox[nAxis] = min(m_afBoundingBox[nAxis], sBlade.m_afPos[nAxis]);
m_afBoundingBox[nAxis + 3] = max(m_afBoundingBox[nAxis + 3], sBlade.m_afPos[nAxis]);
}
// set bottom and top color
memcpy(sBlade.m_afBottomColor, sBlade.m_afNormal, 12);
memcpy(sBlade.m_afTopColor, sBlade.m_afNormal, 12);
// assign which blade texture map
sBlade.m_ucWhichTexture = GetRandom(0, c_nNumBladeMaps - 1);
// compute wind effects
sBlade.m_fNoise = GetRandom(c_fMinBladeNoise, c_fMaxBladeNoise);
sBlade.m_fThrow = GetRandom(c_fMinBladeThrow, c_fMaxBladeThrow);
// compute dimensions
sBlade.m_fSize = GetRandom(c_fMinBladeSize, c_fMaxBladeSize);
// store all blades together
vSceneBlades.push_back(sBlade);
// create regions based on blades (do not remove)
CreateRegions(vSceneBlades);
// true = success, false = error
return true;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::GetLodParams
void CSpeedGrassRT::GetLodParams(float& fFarDistance, float& fTransitionLength)
{
fFarDistance = m_fLodFarDistance;
fTransitionLength = m_fLodTransitionLength;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::SetLodParams
void CSpeedGrassRT::SetLodParams(float fFarDistance, float fTransitionLength)
{
m_fLodFarDistance = fFarDistance;
m_fLodTransitionLength = fTransitionLength;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::Cull
//
// Using a two-dimensional projection, determine which regions
// intersect with the view frustum (+Z is assumed to be up)
void CSpeedGrassRT::Cull(void)
{
// convert raw frustum min and max values into min and max region cell indices
int anFrustumCellsMin[2], anFrustumCellsMax[2];
ConvertCoordsToCell(m_afFrustumMin, anFrustumCellsMin);
ConvertCoordsToCell(m_afFrustumMax, anFrustumCellsMax);
// set all regions to culled, modify later
for (int i = 0; i < m_nNumRegions; ++i)
m_pRegions[i].m_bCulled = true;
int nRegionsDrawn = 0;
// is the entire set of regions culled?
if ((anFrustumCellsMin[0] < 0 && anFrustumCellsMax[0] < 0) ||
(anFrustumCellsMin[0] >= m_nNumRegionCols && anFrustumCellsMax[0] >= m_nNumRegionCols) ||
(anFrustumCellsMin[1] < 0 && anFrustumCellsMax[1] < 0) ||
(anFrustumCellsMin[1] >= m_nNumRegionRows && anFrustumCellsMax[1] >= m_nNumRegionRows))
m_bAllRegionsCulled = true;
else
{
// clip cell values
anFrustumCellsMin[0] = max(anFrustumCellsMin[0], 0);
anFrustumCellsMin[1] = max(anFrustumCellsMin[1], 0);
anFrustumCellsMax[0] = min(anFrustumCellsMax[0], m_nNumRegionCols - 1);
anFrustumCellsMax[1] = min(anFrustumCellsMax[1], m_nNumRegionRows - 1);
for (i = anFrustumCellsMin[0]; i <= anFrustumCellsMax[0]; ++i)
for (int j = anFrustumCellsMin[1]; j <= anFrustumCellsMax[1]; ++j)
{
SRegion* pRegion = m_pRegions + GetRegionIndex(j, i);
pRegion->m_bCulled = OutsideFrustum(pRegion);
}
m_bAllRegionsCulled = false;
}
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::SetWindDirection
void CSpeedGrassRT::SetWindDirection(const float* pWindDir)
{
memcpy(m_afWindDir, pWindDir, 3 * sizeof(float));
m_afWindDir[3] = 0.0f;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::GetWindDirection
const float* CSpeedGrassRT::GetWindDirection(void)
{
return m_afWindDir;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::GetCameraPos
const float* CSpeedGrassRT::GetCameraPos(void)
{
return m_afCameraPos;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::SetCamera
void CSpeedGrassRT::SetCamera(const float* pPosition, const double* pModelviewMatrix)
{
memcpy(m_afCameraPos, pPosition, 3 * sizeof(float));
// "right" vector
m_afCameraRight[0] = pModelviewMatrix[0];
m_afCameraRight[1] = pModelviewMatrix[4];
m_afCameraRight[2] = pModelviewMatrix[8];
// "up" vector
m_afCameraUp[0] = pModelviewMatrix[1];
m_afCameraUp[1] = pModelviewMatrix[5];
m_afCameraUp[2] = pModelviewMatrix[9];
// "out of screen" vector
m_afCameraOut[0] = pModelviewMatrix[2];
m_afCameraOut[1] = pModelviewMatrix[6];
m_afCameraOut[2] = pModelviewMatrix[10];
// with direction changed, billboard turns
ComputeUnitBillboard( );
// compute new frustum box
ComputeFrustum( );
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::SetPerspective
void CSpeedGrassRT::SetPerspective(float fAspectRatio, float fFieldOfView)
{
m_fAspectRatio = fAspectRatio;
m_fFieldOfView = D3DXToRadian(fAspectRatio * fFieldOfView);
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::CreateRegions
void CSpeedGrassRT::CreateRegions(const vector<SBlade>& vSceneBlades, float fCollisionDistance)
{
// create regions based on overall extents
DeleteRegions( );
m_nNumRegions = int(m_nNumRegionRows * m_nNumRegionCols);
m_pRegions = new SRegion[m_nNumRegions];
// run through all regions, computing extents for each
float fCellWidth = (m_afBoundingBox[3] - m_afBoundingBox[0]) / m_nNumRegionCols;
float fCellHeight = (m_afBoundingBox[4] - m_afBoundingBox[1]) / m_nNumRegionRows;
float fY = m_afBoundingBox[1];
for (int nRow = 0; nRow < m_nNumRegionRows; ++nRow)
{
float fX = m_afBoundingBox[0];
for (int nCol = 0; nCol < m_nNumRegionCols; ++nCol)
{
SRegion* pRegion = m_pRegions + GetRegionIndex(nRow, nCol);
// compute extents
pRegion->m_afMin[0] = fX;
pRegion->m_afMax[0] = fX + fCellWidth;
pRegion->m_afMin[1] = fY;
pRegion->m_afMax[1] = fY + fCellHeight;
// compute center
pRegion->m_afCenter[0] = 0.5f * (pRegion->m_afMin[0] + pRegion->m_afMax[0]);
pRegion->m_afCenter[1] = 0.5f * (pRegion->m_afMin[1] + pRegion->m_afMax[1]);
// compute culling radius
pRegion->m_fCullingRadius = 1.1f * sqrt(
((pRegion->m_afMax[0] - pRegion->m_afCenter[0]) * (pRegion->m_afMax[0] - pRegion->m_afCenter[0])) +
((pRegion->m_afMax[1] - pRegion->m_afCenter[1]) * (pRegion->m_afMax[1] - pRegion->m_afCenter[1]))
);
fX += fCellWidth;
}
fY += fCellHeight;
}
// assign each blade of grass to its particular region
for (vector<SBlade>::const_iterator iBlade = vSceneBlades.begin( ); iBlade != vSceneBlades.end( ); ++iBlade)
{
// convert position to row/col index
float fPercentAlongX = (iBlade->m_afPos[0] - m_afBoundingBox[0]) / (m_afBoundingBox[3] - m_afBoundingBox[0]);
float fPercentAlongY = (iBlade->m_afPos[1] - m_afBoundingBox[1]) / (m_afBoundingBox[4] - m_afBoundingBox[1]);
// clip values
unsigned int uiCol = min(fPercentAlongX * m_nNumRegionCols, m_nNumRegionCols - 1);
unsigned int uiRow = min(fPercentAlongY * m_nNumRegionRows, m_nNumRegionRows - 1);
m_pRegions[GetRegionIndex(uiRow, uiCol)].m_vBlades.push_back(*iBlade);
}
// compute z extents (now that the blades are in)
for (int i = 0; i < m_nNumRegions; ++i)
{
SRegion* pRegion = m_pRegions + i;
pRegion->m_afMin[2] = FLT_MAX;
pRegion->m_afMax[2] = -FLT_MAX;
for (vector<SBlade>::iterator iBlade = pRegion->m_vBlades.begin( ); iBlade != pRegion->m_vBlades.end( ); ++iBlade)
{
pRegion->m_afMin[2] = min(pRegion->m_afMin[2], iBlade->m_afPos[2]);
pRegion->m_afMax[2] = max(pRegion->m_afMax[2], iBlade->m_afPos[2] + iBlade->m_fSize);
}
pRegion->m_afCenter[0] = 0.5f * (pRegion->m_afMin[0] + pRegion->m_afMax[0]);
pRegion->m_afCenter[1] = 0.5f * (pRegion->m_afMin[1] + pRegion->m_afMax[1]);
pRegion->m_afCenter[2] = 0.5f * (pRegion->m_afMin[2] + pRegion->m_afMax[2]);
// compute culling radius
pRegion->m_fCullingRadius = 1.1f * sqrt(
((pRegion->m_afMax[0] - pRegion->m_afCenter[0]) * (pRegion->m_afMax[0] - pRegion->m_afCenter[0])) +
((pRegion->m_afMax[1] - pRegion->m_afCenter[1]) * (pRegion->m_afMax[1] - pRegion->m_afCenter[1])) +
((pRegion->m_afMax[2] - pRegion->m_afCenter[2]) * (pRegion->m_afMax[2] - pRegion->m_afCenter[2]))
);
}
// collision detection
if (fCollisionDistance > 0.0f)
{
fCollisionDistance *= fCollisionDistance;
for (int nRow = 0; nRow < m_nNumRegionRows; ++nRow)
{
float fX = m_afBoundingBox[0];
for (int nCol = 0; nCol < m_nNumRegionCols; ++nCol)
{
SRegion* pRegion = m_pRegions + GetRegionIndex(nRow, nCol);
// check each blade against all other blades in the region
for (DWORD i = 0; i < pRegion->m_vBlades.size( ); ++i)
{
float fX = pRegion->m_vBlades[i].m_afPos[0];
float fY = pRegion->m_vBlades[i].m_afPos[1];
bool bCollision = false;
for (DWORD j = 0; j < pRegion->m_vBlades.size( ) && !bCollision; ++j)
{
if (i != j)
{
float fDistance = (fX - pRegion->m_vBlades[j].m_afPos[0]) * (fX - pRegion->m_vBlades[j].m_afPos[0]) + (fY - pRegion->m_vBlades[j].m_afPos[1]) * (fY - pRegion->m_vBlades[j].m_afPos[1]);
if (fDistance < fCollisionDistance)
bCollision = true;
}
}
// delete the blade if necessary and adjust the main loop counter to compensate
if (bCollision)
pRegion->m_vBlades.erase(pRegion->m_vBlades.begin( ) + i--);
}
}
}
}
}
//////////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::RotateAxisFromIdentity
__forceinline void CSpeedGrassRT::RotateAxisFromIdentity(D3DXMATRIX * pMat, const float & c_fAngle, const D3DXVECTOR3 & c_rv3Axis)
{
float s = VectorSinD(c_fAngle);
float c = VectorCosD(c_fAngle);
float t = 1.0 - c;
float x = c_rv3Axis.x;
float y = c_rv3Axis.y;
float z = c_rv3Axis.z;
pMat->_11 = t * x * x + c;
pMat->_12 = t * x * y + s * z;
pMat->_13 = t * x * z - s * y;
pMat->_21 = t * x * y - s * z;
pMat->_22 = t * y * y + c;
pMat->_23 = t * y * z + s * x;
pMat->_31 = t * x * z + s * y;
pMat->_32 = t * y * z - s * x;
pMat->_33 = t * z * z + c;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::ComputeFrustum
void CSpeedGrassRT::ComputeFrustum(void)
{
// setup useful vectors
// CVec3 cCameraIn(-m_afCameraOut[0], -m_afCameraOut[1], -m_afCameraOut[2]);
// CVec3 cCameraUp(m_afCameraUp[0], m_afCameraUp[1], m_afCameraUp[2]);
// CVec3 cCameraRight(m_afCameraRight[0], m_afCameraRight[1], m_afCameraRight[2]);
// CVec3 cCameraPos(m_afCameraPos[0], m_afCameraPos[1], m_afCameraPos[2]);
// CVec3 cFarPoint = cCameraPos + cCameraIn * (m_fLodFarDistance + m_fLodTransitionLength);
D3DXVECTOR3 cCameraIn(-m_afCameraOut[0], -m_afCameraOut[1], -m_afCameraOut[2]);
D3DXVECTOR3 cCameraUp(m_afCameraUp[0], m_afCameraUp[1], m_afCameraUp[2]);
D3DXVECTOR3 cCameraRight(m_afCameraRight[0], m_afCameraRight[1], m_afCameraRight[2]);
D3DXVECTOR3 cCameraPos(m_afCameraPos[0], m_afCameraPos[1], m_afCameraPos[2]);
D3DXVECTOR3 cFarPoint = cCameraPos + cCameraIn * (m_fLodFarDistance + m_fLodTransitionLength);
// far plane
// memcpy(m_afFrustumPlanes[0], cCameraIn, 3 * sizeof(float));
// m_afFrustumPlanes[0][3] = -(cCameraIn ^ cFarPoint); // operator^ is dot product
m_afFrustumPlanes[0][0] = cCameraIn.x;
m_afFrustumPlanes[0][1] = cCameraIn.y;
m_afFrustumPlanes[0][2] = cCameraIn.z;
m_afFrustumPlanes[0][3] = -D3DXVec3Dot(&cCameraIn, &cFarPoint); // operator^ is dot product
// CRotTransform cRotate(true);
D3DXMATRIX cRotate;
D3DXMatrixIdentity(&cRotate);
D3DXVECTOR3 cNormal;
// upper plane
// cRotate.RotateAxisFromIdentity(VecRad2Deg(0.5f * m_fFieldOfView * m_fAspectRatio + c_fHalfPi) , cCameraRight);
// CVec3 cNormal = cCameraIn * cRotate;
// cNormal.Normalize( );
// memcpy(m_afFrustumPlanes[1], cNormal, 3 * sizeof(float));
// m_afFrustumPlanes[1][3] = -(cNormal ^ cCameraPos);
// left plane
// cRotate.RotateAxisFromIdentity(VecRad2Deg(0.5f * m_fFieldOfView + c_fHalfPi) , cCameraUp);
// cNormal = cCameraIn * cRotate;
// cNormal.Normalize( );
// memcpy(m_afFrustumPlanes[2], cNormal, 3 * sizeof(float));
// m_afFrustumPlanes[2][3] = -(cNormal ^ cCameraPos);
// lower plane
// cRotate.RotateAxisFromIdentity(-VecRad2Deg(0.5f * m_fFieldOfView * m_fAspectRatio + c_fHalfPi) , cCameraRight);
// cNormal = cCameraIn * cRotate;
// cNormal.Normalize( );
// memcpy(m_afFrustumPlanes[3], cNormal, 3 * sizeof(float));
// m_afFrustumPlanes[3][3] = -(cNormal ^ cCameraPos);
// right plane
// cRotate.RotateAxisFromIdentity(-VecRad2Deg(0.5f * m_fFieldOfView + c_fHalfPi) , cCameraUp);
// cNormal = cCameraIn * cRotate;
// cNormal.Normalize( );
// memcpy(m_afFrustumPlanes[4], cNormal, 3 * sizeof(float));
// m_afFrustumPlanes[4][3] = -(cNormal ^ cCameraPos);
RotateAxisFromIdentity(&cRotate, D3DXToDegree(0.5f * m_fFieldOfView * m_fAspectRatio + c_fHalfPi), cCameraRight);
D3DXVec3TransformCoord(&cNormal, &cCameraIn, &cRotate);
D3DXVec3Normalize(&cNormal, &cNormal);
m_afFrustumPlanes[1][0] = cNormal.x;
m_afFrustumPlanes[1][1] = cNormal.y;
m_afFrustumPlanes[1][2] = cNormal.z;
m_afFrustumPlanes[1][3] = -D3DXVec3Dot(&cNormal, &cCameraPos); // operator^ is dot product
RotateAxisFromIdentity(&cRotate, D3DXToDegree(0.5f * m_fFieldOfView + c_fHalfPi), cCameraUp);
D3DXVec3TransformCoord(&cNormal, &cCameraIn, &cRotate);
D3DXVec3Normalize(&cNormal, &cNormal);
m_afFrustumPlanes[2][0] = cNormal.x;
m_afFrustumPlanes[2][1] = cNormal.y;
m_afFrustumPlanes[2][2] = cNormal.z;
m_afFrustumPlanes[2][3] = -D3DXVec3Dot(&cNormal, &cCameraPos); // operator^ is dot product
RotateAxisFromIdentity(&cRotate, -D3DXToDegree(0.5f * m_fFieldOfView * m_fAspectRatio + c_fHalfPi), cCameraRight);
D3DXVec3TransformCoord(&cNormal, &cCameraIn, &cRotate);
D3DXVec3Normalize(&cNormal, &cNormal);
m_afFrustumPlanes[3][0] = cNormal.x;
m_afFrustumPlanes[3][1] = cNormal.y;
m_afFrustumPlanes[3][2] = cNormal.z;
m_afFrustumPlanes[3][3] = -D3DXVec3Dot(&cNormal, &cCameraPos); // operator^ is dot product
RotateAxisFromIdentity(&cRotate, -D3DXToDegree(0.5f * m_fFieldOfView + c_fHalfPi), cCameraUp);
D3DXVec3TransformCoord(&cNormal, &cCameraIn, &cRotate);
D3DXVec3Normalize(&cNormal, &cNormal);
m_afFrustumPlanes[4][0] = cNormal.x;
m_afFrustumPlanes[4][1] = cNormal.y;
m_afFrustumPlanes[4][2] = cNormal.z;
m_afFrustumPlanes[4][3] = -D3DXVec3Dot(&cNormal, &cCameraPos); // operator^ is dot product
// frustum points
float fFrustumHeight = (m_fLodFarDistance + m_fLodTransitionLength) * tanf(0.5f * m_fFieldOfView);
float fFrustumWidth = (m_fLodFarDistance + m_fLodTransitionLength) * tanf(0.5f * m_fFieldOfView * m_fAspectRatio);
// CVec3 acFrustum[5];
D3DXVECTOR3 acFrustum[5];
acFrustum[0] = cCameraPos;
acFrustum[1] = cFarPoint + cCameraRight * fFrustumWidth + cCameraUp * fFrustumHeight;
acFrustum[2] = cFarPoint - cCameraRight * fFrustumWidth + cCameraUp * fFrustumHeight;
acFrustum[3] = cFarPoint - cCameraRight * fFrustumWidth - cCameraUp * fFrustumHeight;
acFrustum[4] = cFarPoint + cCameraRight * fFrustumWidth - cCameraUp * fFrustumHeight;
// find min/max (x,y) coordinates
m_afFrustumMin[0] = m_afFrustumMin[1] = FLT_MAX;
m_afFrustumMax[0] = m_afFrustumMax[1] = -FLT_MAX;
for (int i = 0; i < 5; ++i)
{
m_afFrustumMin[0] = min(m_afFrustumMin[0], acFrustum[i][0]);
m_afFrustumMax[0] = max(m_afFrustumMax[0], acFrustum[i][0]);
m_afFrustumMin[1] = min(m_afFrustumMin[1], acFrustum[i][1]);
m_afFrustumMax[1] = max(m_afFrustumMax[1], acFrustum[i][1]);
}
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::ComputeUnitBillboard
void CSpeedGrassRT::ComputeUnitBillboard(void)
{
// float fAzimuth = D3DXToDegree(atan2(-m_afCameraOut[1], -m_afCameraOut[0]));
float fAzimuth = atan2(-m_afCameraOut[1], -m_afCameraOut[0]);
// CRotTransform cTrans;
// cTrans.RotateZ(fAzimuth);
//
// static CVec3 afCorner1(0.0f, 0.5f, 1.0f);
// static CVec3 afCorner2(0.0f, -0.5f, 1.0f);
// static CVec3 afCorner3(0.0f, -0.5f, 0.0f);
// static CVec3 afCorner4(0.0f, 0.5f, 0.0f);
//
// CVec3 afNewCorner1 = afCorner1 * cTrans;
// CVec3 afNewCorner2 = afCorner2 * cTrans;
// CVec3 afNewCorner3 = afCorner3 * cTrans;
// CVec3 afNewCorner4 = afCorner4 * cTrans;
//
// memcpy(m_afUnitBillboard + 0, afNewCorner1.m_afData, 3 * sizeof(float));
// memcpy(m_afUnitBillboard + 3, afNewCorner2.m_afData, 3 * sizeof(float));
// memcpy(m_afUnitBillboard + 6, afNewCorner3.m_afData, 3 * sizeof(float));
// memcpy(m_afUnitBillboard + 9, afNewCorner4.m_afData, 3 * sizeof(float));
D3DXMATRIX cTrans;
D3DXMatrixRotationZ(&cTrans, fAzimuth);
static D3DXVECTOR3 afCorner1(0.0f, 0.5f, 1.0f);
static D3DXVECTOR3 afCorner2(0.0f, -0.5f, 1.0f);
static D3DXVECTOR3 afCorner3(0.0f, -0.5f, 0.0f);
static D3DXVECTOR3 afCorner4(0.0f, 0.5f, 0.0f);
D3DXVECTOR3 afNewCorner1;
D3DXVECTOR3 afNewCorner2;
D3DXVECTOR3 afNewCorner3;
D3DXVECTOR3 afNewCorner4;
D3DXVec3TransformCoord(&afNewCorner1, &afCorner1, &cTrans);
D3DXVec3TransformCoord(&afNewCorner2, &afCorner2, &cTrans);
D3DXVec3TransformCoord(&afNewCorner3, &afCorner3, &cTrans);
D3DXVec3TransformCoord(&afNewCorner4, &afCorner4, &cTrans);
m_afUnitBillboard[0] = afNewCorner1.x;
m_afUnitBillboard[1] = afNewCorner1.y;
m_afUnitBillboard[2] = afNewCorner1.z;
m_afUnitBillboard[3] = afNewCorner2.x;
m_afUnitBillboard[4] = afNewCorner2.y;
m_afUnitBillboard[5] = afNewCorner2.z;
m_afUnitBillboard[6] = afNewCorner3.x;
m_afUnitBillboard[7] = afNewCorner3.y;
m_afUnitBillboard[8] = afNewCorner3.z;
m_afUnitBillboard[9] = afNewCorner4.x;
m_afUnitBillboard[10] = afNewCorner4.y;
m_afUnitBillboard[11] = afNewCorner4.z;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::ConvertCoordsToCell
void CSpeedGrassRT::ConvertCoordsToCell(const float* pCoords, int* pGridCoords) const
{
float fPercentAlongX = (pCoords[0] - m_afBoundingBox[0]) / (m_afBoundingBox[3] - m_afBoundingBox[0]);
float fPercentAlongY = (pCoords[1] - m_afBoundingBox[1]) / (m_afBoundingBox[4] - m_afBoundingBox[1]);
if (fPercentAlongX < 0.0f)
pGridCoords[0] = -1;
else if (fPercentAlongX > 1.0f)
pGridCoords[0] = m_nNumRegionCols;
else
pGridCoords[0] = fPercentAlongX * m_nNumRegionCols;
if (fPercentAlongY < 0.0f)
pGridCoords[1] = -1;
else if (fPercentAlongY > 1.0f)
pGridCoords[1] = m_nNumRegionRows;
else
pGridCoords[1] = fPercentAlongY * m_nNumRegionRows;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT::OutsideFrustum
__forceinline bool CSpeedGrassRT::OutsideFrustum(CSpeedGrassRT::SRegion* pRegion)
{
bool bOutside = false;
for (int i = 0; i < 5 && !bOutside; ++i)
if (m_afFrustumPlanes[i][0] * pRegion->m_afCenter[0] +
m_afFrustumPlanes[i][1] * pRegion->m_afCenter[1] +
m_afFrustumPlanes[i][2] * pRegion->m_afCenter[2] +
m_afFrustumPlanes[i][3] > pRegion->m_fCullingRadius)
bOutside = true;
return bOutside;
}
#endif // USE_SPEEDGRASS

View File

@ -0,0 +1,180 @@
///////////////////////////////////////////////////////////////////////
// CSpeedGrassRT Class
//
// (c) 2003 IDV, Inc.
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may
// not be copied or disclosed except in accordance with the terms of
// that agreement.
//
// Copyright (c) 2001-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
#pragma once
//#include <vector>
//#include "Constants.h"
//#include "../Common Source/IdvVertexBuffer.h"
#ifdef USE_SPEEDGRASS
// forward reference
class CIdvTerrain;
///////////////////////////////////////////////////////////////////////
// class CSpeedGrassRT declaration
class CSpeedGrassRT
{
public:
CSpeedGrassRT( );
virtual ~CSpeedGrassRT( );
///////////////////////////////////////////////////////////////////////
// struct SBlade
struct SBlade
{
SBlade( );
// geometry
float m_afPos[3];
float m_afNormal[3];
float m_fSize;
unsigned char m_ucWhichTexture;
// wind
float m_fNoise;
float m_fThrow;
// color
float m_afBottomColor[3];
float m_afTopColor[3];
};
///////////////////////////////////////////////////////////////////////
// struct SRegion
struct SRegion
{
SRegion( );
// dimensions
float m_afCenter[3];
float m_afMin[3];
float m_afMax[3];
// culling
bool m_bCulled;
float m_fCullingRadius;
// grass/brush blades
std::vector<SBlade> m_vBlades;
// CIdvVertexBuffer* m_pVertexBuffer;
CGraphicVertexBuffer m_VertexBuffer;
};
void DeleteRegions(void);
const SRegion* GetRegions(unsigned int& uiNumRegions);
bool ParseBsfFile(const char* pFilename, unsigned int nNumBlades, unsigned int uiRows, unsigned int uiCols, float fCollisionDistance = 0.0f);
bool CustomPlacement(unsigned int uiRows, unsigned int uiCols);
//////////////////////////////////////////////////////////////////////////
// Utility
static void RotateAxisFromIdentity(D3DXMATRIX * pMat, const float & c_fAngle, const D3DXVECTOR3 & c_rv3Axis);
///////////////////////////////////////////////////////////////////////
// Geometry
static const float* GetUnitBillboard(void) { return m_afUnitBillboard; }
///////////////////////////////////////////////////////////////////////
// LOD
static void GetLodParams(float& fFarDistance, float& fTransitionLength);
static void SetLodParams(float fFarDistance, float fTransitionLength);
///////////////////////////////////////////////////////////////////////
// Culling
bool AllRegionsAreCulled(void) const { return m_bAllRegionsCulled; }
void Cull(void);
///////////////////////////////////////////////////////////////////////
// Wind
static void SetWindDirection(const float* pWindDir);
static const float* GetWindDirection(void);
///////////////////////////////////////////////////////////////////////
// Camera
static const float* GetCameraPos(void);
static void SetCamera(const float* pPosition, const double* pModelviewMatrix);
static void SetPerspective(float fAspectRatio, float fFieldOfView);
///////////////////////////////////////////////////////////////////////
// Terrain hugging
virtual float Color(float fX, float fY, const float* pNormal, float* pTopColor, float* pBottomColor) const { return 0.0f; }
virtual float Height(float fX, float fY, float* pNormal) const { return 0.0f; }
protected:
void CreateRegions(const std::vector<SBlade>& vSceneBlades, float fCollisionDistance = 0.0f);
static void ComputeFrustum(void);
static void ComputeUnitBillboard(void);
void ConvertCoordsToCell(const float* pCoords, int* pGridCoords) const;
unsigned int GetRegionIndex(unsigned int uiRow, unsigned int uiCol) const { return uiRow * m_nNumRegionCols + uiCol; }
static bool OutsideFrustum(SRegion* pRegion);
// general
static float m_fLodFarDistance;
static float m_fLodTransitionLength;
static float m_afUnitBillboard[12];
static float m_afWindDir[4];
// regions
int m_nNumRegions;
int m_nNumRegionCols;
int m_nNumRegionRows;
SRegion* m_pRegions;
// camera
static float m_afCameraOut[3];
static float m_afCameraRight[3];
static float m_afCameraUp[3];
static float m_afCameraPos[3];
static float m_fFieldOfView;
static float m_fAspectRatio;
// culling
static float m_afFrustumBox[6];
static float m_afFrustumMin[2];
static float m_afFrustumMax[2];
static float m_afFrustumPlanes[5][4];
float m_afBoundingBox[6];
bool m_bAllRegionsCulled;
};
extern float VecInterpolate(float fStart, float fEnd, float fPercent);
#endif // USE_SPEEDGRASS

View File

@ -0,0 +1,322 @@
///////////////////////////////////////////////////////////////////////
// CSpeedGrassWrapper Class
//
// (c) 2003 IDV, Inc.
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may
// not be copied or disclosed except in accordance with the terms of
// that agreement.
//
// Copyright (c) 2001-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
#include "StdAfx.h"
#include <stdlib.h>
#include <stdio.h>
#include <vector>
//#include "../Common Source/extgl.h"
//#include "SpeedGrassWrapper.h"
//#include "Scene.h"
//#include "../Common Source/nv_dds.h"
//#include "../Common Source/Random.h"
//#include "TextureLayers.h"
using namespace std;
#ifdef USE_SPEEDGRASS
///////////////////////////////////////////////////////////////////////
// CSpeedGrassWrapper::CSpeedGrassWrapper
CSpeedGrassWrapper::CSpeedGrassWrapper() : m_pMapOutdoor(NULL), m_lpD3DTexure8(NULL)//m_uiTexture(0)
{
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassWrapper::~CSpeedGrassWrapper
CSpeedGrassWrapper::~CSpeedGrassWrapper( )
{
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassWrapper::Draw
int CSpeedGrassWrapper::Draw(float fDensity)
{
int nTriangleCount = 0;
// // determine which regions are visible
// Cull( );
//
// // setup opengl state
// glPushAttrib(GL_ENABLE_BIT);
// glDisable(GL_CULL_FACE);
// glDisable(GL_BLEND);
//
// glEnable(GL_TEXTURE_2D);
// glBindTexture(GL_TEXTURE_2D, m_uiTexture);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
//
// glEnable(GL_ALPHA_TEST);
// glAlphaFunc(GL_GREATER, 0.4f);
// glDisable(GL_LIGHTING);
//
// unsigned int uiCount = 0;
// unsigned int uiNumRegions = 0;
// const SRegion* pRegions = GetRegions(uiNumRegions);
//
// // setup for vertex buffer rendering (enable client buffers)
// CIdvVertexBuffer::Enable(true);
// if (uiNumRegions > 0)
// pRegions[0].m_pVertexBuffer->EnableClientStates( );
//
// // run through the regions and render those that aren't culled
// for (unsigned int i = 0; i < uiNumRegions; ++i)
// {
// if (!pRegions[i].m_bCulled)
// {
// pRegions[i].m_pVertexBuffer->Bind( );
// unsigned int uiNumBlades = int(fDensity * pRegions[i].m_vBlades.size( ));
// glDrawArrays(GL_QUADS, 0, uiNumBlades * 4);
// nTriangleCount += uiNumBlades * 2;
// }
// }
//
// // disable client buffers
// if (uiNumRegions > 0)
// pRegions[0].m_pVertexBuffer->DisableClientStates( );
// CIdvVertexBuffer::Disable(true);
//
// // restore opengl state
// glPopAttrib( );
return nTriangleCount;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassWrapper::InitFromBsfFile
bool CSpeedGrassWrapper::InitFromBsfFile(const char* pFilename,
unsigned int nNumBlades,
unsigned int uiRows,
unsigned int uiCols,
float fCollisionDistance)
{
bool bSuccess = false;
if (pFilename)
{
// use SpeedGrass's built-in parse function
if (ParseBsfFile(pFilename, nNumBlades, uiRows, uiCols, fCollisionDistance))
bSuccess = true;
}
InitGraphics( );
return bSuccess;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassWrapper::Color
float CSpeedGrassWrapper::Color(float fX, float fY, const float* pNormal, float* pTopColor, float* pBottomColor) const
{
const float c_fColorAdjust = 0.3f; // controls how much the color of the top vertices of each grass blade can vary
const float c_fColorThrow = 1.0f; // controls how much the r, g, and b components can vary
const float c_fColorRandomness = 0.01f; // controls how much the r, g, and b components can vary
const float c_TopLight = 0.75f;
float afLowColor[4] = { 0.0f }, afHighColor[4] = { 0.0f };
if (m_pMapOutdoor->GetBrushColor(fX, fY, afLowColor, afHighColor))
{
pBottomColor[0] = afLowColor[2];
pBottomColor[1] = afLowColor[1];
pBottomColor[2] = afLowColor[0];
float fColorThrow = GetRandom(0.0f, c_fColorThrow);
pTopColor[0] = VecInterpolate(pBottomColor[0], afHighColor[2], fColorThrow) + GetRandom(-c_fColorRandomness, c_fColorRandomness);
pTopColor[1] = VecInterpolate(pBottomColor[1], afHighColor[1], fColorThrow) + GetRandom(-c_fColorRandomness, c_fColorRandomness);
pTopColor[2] = VecInterpolate(pBottomColor[2], afHighColor[0], fColorThrow) + GetRandom(-c_fColorRandomness, c_fColorRandomness);
float fLargest = pTopColor[0];
if (pTopColor[1] > fLargest)
fLargest = pTopColor[1];
if (pTopColor[2] > fLargest)
fLargest = pTopColor[2];
if (fLargest > 1.0f)
{
pTopColor[0] /= fLargest;
pTopColor[1] /= fLargest;
pTopColor[2] /= fLargest;
}
pTopColor[0] = max(0.0f, pTopColor[0]);
pTopColor[1] = max(0.0f, pTopColor[1]);
pTopColor[2] = max(0.0f, pTopColor[2]);
}
return afLowColor[3];
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassWrapper::Height
float CSpeedGrassWrapper::Height(float fX, float fY, float* pNormal) const
{
float fHeight = 0.0f;
float afPos[3] = { fX, fY, 0.0f };
fHeight = m_pMapOutdoor->GetHeight(afPos);
pNormal[0] = 0.0f;
pNormal[1] = 0.0f;
pNormal[2] = 1.0f;
return fHeight;
}
///////////////////////////////////////////////////////////////////////
// CSpeedGrassWrapper::InitGraphics
void CSpeedGrassWrapper::InitGraphics(void)
{
// load texture
// m_uiTexture = LoadDDS((c_strDataPath + string("brush_2.dds")).c_str( ));
CGraphicImage * pImage = (CGraphicImage *) CResourceManager::Instance().GetResourcePointer("D:/ymir work/special/brush_2.dds");
m_GrassImageInstance.SetImagePointer(pImage);
m_lpD3DTexure8 = m_GrassImageInstance.GetTexturePointer()->GetD3DTexture();
// prepare static vertex buffers
for (int i = 0; i < m_nNumRegions; ++i)
{
SRegion* pRegion = m_pRegions + i;
// pRegion->m_pVertexBuffer = new CIdvVertexBuffer;
// setup up temporary buffer to copy later
const int c_nNumCorners = 4;
unsigned int uiNumBlades = pRegion->m_vBlades.size( );
unsigned int uiBufferSize = uiNumBlades * c_nNumCorners * c_nGrassVertexTotalSize;
unsigned char* pBuffer = new unsigned char[uiBufferSize];
// setup initial pointers for individual attribute copying
float* pTexCoords0 = reinterpret_cast<float*>(pBuffer + 0);
float* pTexCoords1 = reinterpret_cast<float*>(pTexCoords0 + c_nGrassVertexTexture0Size * uiNumBlades * c_nNumCorners / sizeof(float));
unsigned char* pColors = (unsigned char*) pTexCoords1 + c_nGrassVertexTexture1Size * uiNumBlades * c_nNumCorners;
float* pPositions = reinterpret_cast<float*>(pColors + c_nGrassVertexColorSize * uiNumBlades * c_nNumCorners);
for (vector<SBlade>::const_iterator iBlade = pRegion->m_vBlades.begin( ); iBlade != pRegion->m_vBlades.end( ); ++iBlade)
{
float fS1 = float(iBlade->m_ucWhichTexture) / c_nNumBladeMaps;
float fS2 = float(iBlade->m_ucWhichTexture + 1) / c_nNumBladeMaps;
for (int nCorner = 0; nCorner < c_nNumCorners; ++nCorner)
{
// texcoord 0
switch (nCorner)
{
case 0:
pTexCoords0[0] = fS2;
pTexCoords0[1] = 1.0f;
break;
case 1:
pTexCoords0[0] = fS1;
pTexCoords0[1] = 1.0f;
break;
case 2:
pTexCoords0[0] = fS1;
pTexCoords0[1] = 0.0f;
break;
case 3:
pTexCoords0[0] = fS2;
pTexCoords0[1] = 0.0f;
break;
default:
assert(false);
}
pTexCoords0 += c_nGrassVertexTexture0Size / sizeof(float);
// texcoord 1
switch (nCorner)
{
case 0:
pTexCoords1[0] = c_nShaderGrassBillboard;
pTexCoords1[2] = iBlade->m_fThrow;
break;
case 1:
pTexCoords1[0] = c_nShaderGrassBillboard + 1;
pTexCoords1[2] = iBlade->m_fThrow;
break;
case 2:
pTexCoords1[0] = c_nShaderGrassBillboard + 2;
pTexCoords1[2] = 0.0f;
break;
case 3:
pTexCoords1[0] = c_nShaderGrassBillboard + 3;
pTexCoords1[2] = 0.0f;
break;
default:
assert(false);
}
// same for all corners
pTexCoords1[1] = iBlade->m_fSize;
pTexCoords1[3] = iBlade->m_fNoise;
pTexCoords1 += c_nGrassVertexTexture1Size / sizeof(float);
// color
unsigned long ulColor = 0;
if (nCorner == 0 || nCorner == 1)
ulColor = (int(iBlade->m_afTopColor[0] * 255.0f) << 0) +
(int(iBlade->m_afTopColor[1] * 255.0f) << 8) +
(int(iBlade->m_afTopColor[2] * 255.0f) << 16) +
0xff000000;
else
ulColor = (int(iBlade->m_afBottomColor[0] * 255.0f) << 0) +
(int(iBlade->m_afBottomColor[1] * 255.0f) << 8) +
(int(iBlade->m_afBottomColor[2] * 255.0f) << 16) +
0xff000000;
memcpy(pColors, &ulColor, c_nGrassVertexColorSize);
pColors += c_nGrassVertexColorSize;
// position
memcpy(pPositions, iBlade->m_afPos, c_nGrassVertexPositionSize);
pPositions += c_nGrassVertexPositionSize / sizeof(float);
}
}
// assert((unsigned char*) pTexCoords0 - pBuffer == c_nGrassVertexTexture0Size * uiNumBlades * c_nNumCorners);
// assert(pTexCoords1 - pTexCoords0 == (c_nGrassVertexTexture1Size * uiNumBlades * c_nNumCorners) / sizeof(float));
// assert(pColors - (unsigned char*) pTexCoords1 == c_nGrassVertexColorSize * uiNumBlades * c_nNumCorners);
// assert((unsigned char*) pPositions - pColors == c_nGrassVertexPositionSize * uiNumBlades * c_nNumCorners);
// pRegion->m_pVertexBuffer->SetBuffer(pBuffer, uiBufferSize, true);
// pRegion->m_pVertexBuffer->SetStride(CIdvVertexBuffer::VERTEX_TEXCOORD0, 2, GL_FLOAT, 0, 0);
// pRegion->m_pVertexBuffer->SetStride(CIdvVertexBuffer::VERTEX_TEXCOORD1, 4, GL_FLOAT, 0, (unsigned char*) pTexCoords0 - pBuffer);
// pRegion->m_pVertexBuffer->SetStride(CIdvVertexBuffer::VERTEX_COLOR, 4, GL_UNSIGNED_BYTE, 0, (unsigned char*) pTexCoords1 - pBuffer);
// pRegion->m_pVertexBuffer->SetStride(CIdvVertexBuffer::VERTEX_POSITION, 3, GL_FLOAT, 0, pColors - pBuffer);
DWORD dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1;
// pRegion->m_VertexBuffer.Create();
delete[] pBuffer;
}
}
#endif // USE_SPEEDGRASS

View File

@ -0,0 +1,64 @@
///////////////////////////////////////////////////////////////////////
// CSpeedGrassWrapper Class
//
// (c) 2003 IDV, Inc.
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may
// not be copied or disclosed except in accordance with the terms of
// that agreement.
//
// Copyright (c) 2001-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
#pragma once
//#include "SpeedGrassRT.h"
#ifdef USE_SPEEDGRASS
//#include "../Common Source/IdvVertexBuffer.h"
//#include <vector>
// forward reference
//class CScene;
class CMapOutdoor;
///////////////////////////////////////////////////////////////////////
// class CSpeedGrassWrapper declaration
class CSpeedGrassWrapper : public CSpeedGrassRT
{
public:
CSpeedGrassWrapper( );
virtual ~CSpeedGrassWrapper( );
void SetMapOutdoor(CMapOutdoor* pMapOutdoor) { m_pMapOutdoor = pMapOutdoor; }
int Draw(float fDensity);
bool InitFromBsfFile(const char* pFilename,
unsigned int nNumBlades,
unsigned int uiRows,
unsigned int uiCols,
float fCollisionDistance);
private:
virtual float Color(float fX, float fY, const float* pNormal, float* pTopColor, float* pBottomColor) const;
virtual float Height(float fX, float fY, float* pNormal) const;
void InitGraphics(void);
CMapOutdoor * m_pMapOutdoor;
LPDIRECT3DTEXTURE8 m_lpD3DTexure8;
CGraphicImageInstance m_GrassImageInstance;
};
#endif // USE_SPEEDGRASS

View File

@ -0,0 +1,120 @@
///////////////////////////////////////////////////////////////////////
// SpeedTreeRT runtime configuration #defines
//
// (c) 2003 IDV, Inc.
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may
// not be copied or disclosed except in accordance with the terms of
// that agreement.
//
// Copyright (c) 2001-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
#pragma once
const int c_nNumWindMatrices = 4;
const int c_nNumInstancesPerModel = 10;
const float c_fForestSize = 200.0f;
const float c_fSpacingTolerance = 30.0f;
const int c_nMaxPlacementIterations = 500;
const int c_nDefaultAlphaTestValue = 84;
const float c_fNearLodFactor = 2.0f;
const float c_fFarLodFactor = 9.0f;
const float c_fBenchmarkPeriod = 1.0f;
// vertex shader constant locations
const int c_nVertexShader_LeafLightingAdjustment = 70;
const int c_nVertexShader_Light = 71;
const int c_nVertexShader_Material = 74;
const int c_nVertexShader_TreePos = 52;
const int c_nVertexShader_CompoundMatrix = 0;
const int c_nVertexShader_WindMatrices = 54;
const int c_nVertexShader_LeafTables = 4;
const int c_nVertexShader_Fog = 85;
// lighting
const float c_afLightPosition[4] = { -0.707f, 0.0f, 0.707f, 0.0f };
const float c_afLightAmbient[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
const float c_afLightDiffuse[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
const float c_afLightSpecular[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
const float c_afLightGlobalAmbient[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
// setup lighting (enable ONE of the two below)
#define WRAPPER_USE_STATIC_LIGHTING
//#define WRAPPER_USE_DYNAMIC_LIGHTING
#if defined WRAPPER_USE_STATIC_LIGHTING && defined WRAPPER_USE_DYNAMIC_LIGHTING
#error Please define exactly one lighting mode
#endif
// setup wind (enable ONE of the three below)
//#define WRAPPER_USE_GPU_WIND
//#define WRAPPER_USE_CPU_WIND
#define WRAPPER_USE_NO_WIND
#if defined WRAPPER_USE_GPU_WIND && defined WRAPPER_USE_CPU_WIND
#error Please define exactly one lighting mode
#elif defined WRAPPER_USE_GPU_WIND && defined WRAPPER_USE_NO_WIND
#error Please define exactly one lighting mode
#elif defined WRAPPER_USE_CPU_WIND && defined WRAPPER_USE_NO_WIND
#error Please define exactly one lighting mode
#endif
// leaf placement algorithm (enable ONE of the two below)
//#define WRAPPER_USE_GPU_LEAF_PLACEMENT
#define WRAPPER_USE_CPU_LEAF_PLACEMENT
#if defined WRAPPER_USE_GPU_LEAF_PLACEMENT && defined WRAPPER_USE_CPU_LEAF_PLACEMENT
#error Please define exactly one leaf placement algorithm
#endif
// texture coordinates (enable this define for DirectX-based engines)
#define WRAPPER_FLIP_T_TEXCOORD
// up vector
//#define WRAPPER_UP_POS_Y
#define WRAPPER_UP_POS_Z
#if defined WRAPPER_UP_POS_Y && defined WRAPPER_UP_POS_Z
#error Please define exactly one up vector
#endif
// loading from STF or clones/instances? (enable ONE of the two below)
//#define WRAPPER_FOREST_FROM_STF
#define WRAPPER_FOREST_FROM_INSTANCES
#if defined WRAPPER_FOREST_FROM_STF && defined WRAPPER_FOREST_FROM_INSTANCES
#error Please define exactly one loading mechanism
#endif
// billboard modes
#define WRAPPER_BILLBOARD_MODE
//#define WRAPPER_RENDER_HORIZONTAL_BILLBOARD
// render self-shadows
#define WRAPPER_RENDER_SELF_SHADOWS
// use fog
#define WRAPPER_USE_FOG
// derived constants
#ifdef WRAPPER_USE_GPU_WIND
#define BRANCHES_USE_SHADERS
#define FRONDS_USE_SHADERS
#define LEAVES_USE_SHADERS
#endif
#ifdef WRAPPER_USE_GPU_LEAF_PLACEMENT
#define LEAVES_USE_SHADERS
#endif

View File

@ -0,0 +1,316 @@
///////////////////////////////////////////////////////////////////////
// CSpeedTreeForest Class
///////////////////////////////////////////////////////////////////////
// Include Files
#include "StdAfx.h"
#include <vector>
#include "../eterBase/Filename.h"
#include "../eterBase/MappedFile.h"
#include "../eterPack/EterPackManager.h"
#include "SpeedTreeForest.h"
#include "SpeedTreeConfig.h"
#include <cfloat>
using namespace std;
///////////////////////////////////////////////////////////////////////
// CSpeedTreeForest constructor
CSpeedTreeForest::CSpeedTreeForest() : m_fWindStrength(0.0f)
{
CSpeedTreeRT::SetNumWindMatrices(c_nNumWindMatrices);
m_afForestExtents[0] = m_afForestExtents[1] = m_afForestExtents[2] = FLT_MAX;
m_afForestExtents[3] = m_afForestExtents[4] = m_afForestExtents[5] = -FLT_MAX;
}
///////////////////////////////////////////////////////////////////////
// CSpeedTreeForest destructor
CSpeedTreeForest::~CSpeedTreeForest()
{
Clear();
}
void CSpeedTreeForest::Clear()
{
TTreeMap::iterator itor = m_pMainTreeMap.begin();
UINT uiCount;
while (itor != m_pMainTreeMap.end())
{
CSpeedTreeWrapper * pMainTree = (itor++)->second;
CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount);
for (UINT i = 0; i < uiCount; ++i)
delete ppInstances[i];
delete pMainTree;
}
m_pMainTreeMap.clear();
}
CSpeedTreeWrapper * CSpeedTreeForest::GetMainTree(DWORD dwCRC)
{
TTreeMap::iterator itor = m_pMainTreeMap.find(dwCRC);
if (itor == m_pMainTreeMap.end())
return NULL;
return itor->second;
}
BOOL CSpeedTreeForest::GetMainTree(DWORD dwCRC, CSpeedTreeWrapper ** ppMainTree, const char * c_pszFileName)
{
TTreeMap::iterator itor = m_pMainTreeMap.find(dwCRC);
CSpeedTreeWrapper * pTree;
if (itor != m_pMainTreeMap.end())
pTree = itor->second;
else
{
CMappedFile file;
LPCVOID c_pvData;
// NOTE : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> return FALSE <20>ƴѰ<C6B4><D1B0><EFBFBD>? - [levites]
if (!CEterPackManager::Instance().Get(file, c_pszFileName, &c_pvData))
return FALSE;
pTree = new CSpeedTreeWrapper;
if (!pTree->LoadTree(c_pszFileName, (const BYTE *) c_pvData, file.Size()))
{
delete pTree;
return FALSE;
}
m_pMainTreeMap.insert(std::map<DWORD, CSpeedTreeWrapper *>::value_type(dwCRC, pTree));
file.Destroy();
}
*ppMainTree = pTree;
return TRUE;
}
CSpeedTreeWrapper* CSpeedTreeForest::CreateInstance(float x, float y, float z, DWORD dwTreeCRC, const char * c_szTreeName)
{
CSpeedTreeWrapper * pMainTree;
if (!GetMainTree(dwTreeCRC, &pMainTree, c_szTreeName))
return NULL;
CSpeedTreeWrapper* pTreeInst = pMainTree->MakeInstance();
pTreeInst->SetPosition(x, y, z);
pTreeInst->RegisterBoundingSphere();
return pTreeInst;
}
void CSpeedTreeForest::DeleteInstance(CSpeedTreeWrapper * pInstance)
{
if (!pInstance)
return;
CSpeedTreeWrapper * pParentTree = pInstance->InstanceOf();
if (!pParentTree)
return;
pParentTree->DeleteInstance(pInstance);
}
void CSpeedTreeForest::UpdateSystem(float fCurrentTime)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ <20><> <20><> <20>ѹ<EFBFBD>
static float fLastTime = fCurrentTime;
float fElapsedTime = fCurrentTime - fLastTime;
CSpeedTreeRT::SetTime(fElapsedTime);
m_fAccumTime += fElapsedTime;
SetupWindMatrices(m_fAccumTime);
}
///////////////////////////////////////////////////////////////////////
// CSpeedTreeForest::AdjustExtents
void CSpeedTreeForest::AdjustExtents(float x, float y, float z)
{
// min
m_afForestExtents[0] = __min(m_afForestExtents[0], x);
m_afForestExtents[1] = __min(m_afForestExtents[1], y);
m_afForestExtents[2] = __min(m_afForestExtents[2], z);
// max
m_afForestExtents[3] = __max(m_afForestExtents[3], x);
m_afForestExtents[4] = __max(m_afForestExtents[4], y);
m_afForestExtents[5] = __max(m_afForestExtents[5], z);
}
///////////////////////////////////////////////////////////////////////
// CSpeedTreeForest::SetWindStrength
void CSpeedTreeForest::SetWindStrength(float fStrength)
{
if (m_fWindStrength == fStrength)
return;
m_fWindStrength = fStrength;
TTreeMap::iterator itor = m_pMainTreeMap.begin();
UINT uiCount;
while (itor != m_pMainTreeMap.end())
{
CSpeedTreeWrapper * pMainTree = (itor++)->second;
CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount);
for (UINT i = 0; i < uiCount; ++i)
ppInstances[i]->GetSpeedTree()->SetWindStrength(m_fWindStrength);
}
}
///////////////////////////////////////////////////////////////////////
// CSpeedTreeForest::SetupWindMatrices
void CSpeedTreeForest::SetupWindMatrices(float fTimeInSecs)
{
// matrix computational data
static float afMatrixTimes[c_nNumWindMatrices] = { 0.0f };
static float afFrequencies[c_nNumWindMatrices][2] =
{
{ 0.15f, 0.17f },
{ 0.25f, 0.15f },
{ 0.19f, 0.05f },
{ 0.15f, 0.22f }
};
// compute time since last call
static float fTimeOfLastCall = 0.0f;
float fTimeSinceLastCall = fTimeInSecs - fTimeOfLastCall;
fTimeOfLastCall = fTimeInSecs;
// wind strength
static float fOldStrength = m_fWindStrength;
// increment matrix times
for (int i = 0; i < c_nNumWindMatrices; ++i)
afMatrixTimes[i] += fTimeSinceLastCall;
// compute maximum branch throw
float fBaseAngle = m_fWindStrength * 35.0f;
// build rotation matrices
for (int j = 0; j < c_nNumWindMatrices; ++j)
{
// adjust time to prevent "jumping"
if (m_fWindStrength != 0.0f)
afMatrixTimes[j] = (afMatrixTimes[j] * fOldStrength) / m_fWindStrength;
// compute percentages for each axis
float fBaseFreq = m_fWindStrength * 20.0f;
float fXPercent = sinf(fBaseFreq * afFrequencies[j % c_nNumWindMatrices][0] * afMatrixTimes[j]);
float fYPercent = cosf(fBaseFreq * afFrequencies[j % c_nNumWindMatrices][1] * afMatrixTimes[j]);
// build compound rotation matrix (rotate on 'x' then on 'y')
const float c_fDeg2Rad = 57.2957795f;
float fSinX = sinf(fBaseAngle * fXPercent / c_fDeg2Rad);
float fSinY = sinf(fBaseAngle * fYPercent / c_fDeg2Rad);
float fCosX = cosf(fBaseAngle * fXPercent / c_fDeg2Rad);
float fCosY = cosf(fBaseAngle * fYPercent / c_fDeg2Rad);
float afMatrix[16] = { 0.0f };
afMatrix[0] = fCosY;
afMatrix[2] = -fSinY;
afMatrix[4] = fSinX * fSinY;
afMatrix[5] = fCosX;
afMatrix[6] = fSinX * fCosY;
afMatrix[8] = fSinY * fCosX;
afMatrix[9] = -fSinX;
afMatrix[10] = fCosX * fCosY;
afMatrix[15] = 1.0f;
#ifdef WRAPPER_USE_CPU_WIND
CSpeedTreeRT::SetWindMatrix(j, afMatrix);
#endif
#ifdef WRAPPER_USE_GPU_WIND
// graphics API specific
UploadWindMatrix(c_nVertexShader_WindMatrices + j * 4, afMatrix);
#endif
}
// track wind strength
fOldStrength = m_fWindStrength;
}
///////////////////////////////////////////////////////////////////////
// CSpeedTreeForest::SetLodLimits
/*
void CSpeedTreeForest::SetLodLimits(void)
{
// find tallest tree
float fTallest = -1.0f;
TTreeMap::iterator itor = m_pMainTreeMap.begin();
UINT uiCount;
while (itor != m_pMainTreeMap.end())
{
CSpeedTreeWrapper * pMainTree = (itor++)->second;
CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount);
float fHeight;
fHeight = pMainTree->GetBoundingBox()[5] - pMainTree->GetBoundingBox()[0];
fTallest = __max(fHeight, fTallest);
for (UINT i = 0; i < uiCount; ++i)
{
fHeight = ppInstances[i]->GetBoundingBox()[5] - ppInstances[i]->GetBoundingBox()[0];
fTallest = __max(fHeight, fTallest);
}
}
itor = m_pMainTreeMap.begin();
while (itor != m_pMainTreeMap.end())
{
CSpeedTreeWrapper * pMainTree = (itor++)->second;
CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount);
pMainTree->GetSpeedTree()->SetLodLimits(fTallest * c_fNearLodFactor, fTallest * c_fFarLodFactor);
for (UINT i = 0; i < uiCount; ++i)
ppInstances[i]->GetSpeedTree()->SetLodLimits(fTallest * c_fNearLodFactor, fTallest * c_fFarLodFactor);
}
}
*/
void CSpeedTreeForest::SetLight(const float * afDirection, const float * afAmbient, const float * afDiffuse)
{
m_afLighting[0] = afDirection[0];
m_afLighting[1] = afDirection[1];
m_afLighting[2] = afDirection[2];
m_afLighting[3] = 1.0f;
m_afLighting[4] = afAmbient[0];
m_afLighting[5] = afAmbient[1];
m_afLighting[6] = afAmbient[2];
m_afLighting[7] = afAmbient[3];
m_afLighting[8] = afDiffuse[0];
m_afLighting[9] = afDiffuse[1];
m_afLighting[10] = afDiffuse[2];
m_afLighting[11] = afDiffuse[3];
}
void CSpeedTreeForest::SetFog(float fFogNear, float fFogFar)
{
const float c_fFogLinearScale = (1.0f / (fFogFar - fFogNear));
m_afFog[0] = fFogNear;
m_afFog[1] = fFogFar;
m_afFog[2] = c_fFogLinearScale;
m_afFog[3] = 0.0f;
}

View File

@ -0,0 +1,108 @@
///////////////////////////////////////////////////////////////////////
// CSpeedTreeForest Class
//
// (c) 2003 IDV, Inc.
//
// This class is provided to illustrate one way to incorporate
// SpeedTreeRT into an OpenGL application. All of the SpeedTreeRT
// calls that must be made on a per tree basis are done by this class.
// Calls that apply to all trees (i.e. static SpeedTreeRT functions)
// are made in the functions in main.cpp.
//
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may
// not be copied or disclosed except in accordance with the terms of
// that agreement.
//
// Copyright (c) 2001-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
#pragma once
///////////////////////////////////////////////////////////////////////
// Include Files
#include <SpeedTreeRT.h>
#include "SpeedTreeWrapper.h"
#include <vector>
#include <map>
///////////////////////////////////////////////////////////////////////
// Render bit vector
#define Forest_RenderBranches (1 << 0)
#define Forest_RenderLeaves (1 << 1)
#define Forest_RenderFronds (1 << 2)
#define Forest_RenderBillboards (1 << 3)
#define Forest_RenderAll ((1 << 4) - 1)
#define Forest_RenderToShadow (1 << 5)
#define Forest_RenderToMiniMap (1 << 6)
///////////////////////////////////////////////////////////////////////
// class CSpeedTreeForest declaration
class CSpeedTreeForest
{
public:
typedef std::map<DWORD, CSpeedTreeWrapper *> TTreeMap;
public:
CSpeedTreeForest();
virtual ~CSpeedTreeForest();
void ClearMainTree();
BOOL GetMainTree(DWORD dwCRC, CSpeedTreeWrapper ** ppMainTree, const char * c_pszFileName);
CSpeedTreeWrapper * GetMainTree(DWORD dwCRC);
void DeleteMainTree(DWORD dwCRC);
CSpeedTreeWrapper * CreateInstance(float x, float y, float z, DWORD dwTreeCRC, const char * c_pszTreeName);
void DeleteInstance(CSpeedTreeWrapper * pTree);
//void SetLodLimits(void);
void UpdateSystem(float fCurrentTime);
void Clear();
void SetLight(const float * afDirection, const float * afAmbient, const float * afDiffuse);
void SetFog(float fFogNear, float fFogFar);
//////////////////////////////////////////////////////////////////////////
const float * GetExtents(void) const { return m_afForestExtents; }
// wind management
float GetWindStrength(void) const { return m_fWindStrength; }
void SetWindStrength(float fStrength);
void SetupWindMatrices(float fTimeInSecs);
// overridden by specific graphics API
virtual void UploadWindMatrix(unsigned int uiLocation, const float* pMatrix) const = 0;
virtual void Render(unsigned long ulRenderBitVector) = 0;
protected:
TTreeMap m_pMainTreeMap;
float m_afLighting[12];
float m_afFog[4];
private:
void AdjustExtents(float x, float y, float z);
float m_afForestExtents[6]; // [0] = min x, [1] = min y..., [3] = max x, [4] = max y...
float m_fWindStrength; // 0.0 = no wind, 1.0 = full strength
float m_fAccumTime;
};

View File

@ -0,0 +1,344 @@
///////////////////////////////////////////////////////////////////////
// CSpeedTreeForestDirectX8 Class
//
// (c) 2003 IDV, Inc.
//
// This class is provided to illustrate one way to incorporate
// SpeedTreeRT into an OpenGL application. All of the SpeedTreeRT
// calls that must be made on a per tree basis are done by this class.
// Calls that apply to all trees (i.e. static SpeedTreeRT functions)
// are made in the functions in main.cpp.
//
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may
// not be copied or disclosed except in accordance with the terms of
// that agreement.
//
// Copyright (c) 2001-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
#include "StdAfx.h"
#include <stdio.h>
#include <d3d8.h>
#include <d3d8types.h>
#include <d3dx8.h>
#include "../eterBase/Timer.h"
#include "../eterlib/StateManager.h"
#include "../eterlib/Camera.h"
#include "SpeedTreeForestDirectX8.h"
#include "SpeedTreeConfig.h"
#include "VertexShaders.h"
///////////////////////////////////////////////////////////////////////
// CSpeedTreeForestDirectX8::CSpeedTreeForestDirectX8
CSpeedTreeForestDirectX8::CSpeedTreeForestDirectX8() : m_dwBranchVertexShader(0), m_dwLeafVertexShader(0)
{
}
///////////////////////////////////////////////////////////////////////
// CSpeedTreeForestDirectX8::~CSpeedTreeForestDirectX8
CSpeedTreeForestDirectX8::~CSpeedTreeForestDirectX8()
{
}
///////////////////////////////////////////////////////////////////////
// CSpeedTreeForestDirectX8::InitVertexShaders
bool CSpeedTreeForestDirectX8::InitVertexShaders(void)
{
NANOBEGIN
// load the vertex shaders
if (!m_dwBranchVertexShader)
m_dwBranchVertexShader = LoadBranchShader(m_pDx);
if (!m_dwLeafVertexShader)
m_dwLeafVertexShader = LoadLeafShader(m_pDx);
if (m_dwBranchVertexShader && m_dwLeafVertexShader)
{
CSpeedTreeWrapper::SetVertexShaders(m_dwBranchVertexShader, m_dwLeafVertexShader);
return true;
}
NANOEND
return false;
}
bool CSpeedTreeForestDirectX8::SetRenderingDevice(LPDIRECT3DDEVICE8 lpDevice)
{
m_pDx = lpDevice;
if (!InitVertexShaders())
return false;
const float c_afLightPosition[4] = { -0.707f, -0.300f, 0.707f, 0.0f };
const float c_afLightAmbient[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
const float c_afLightDiffuse[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
const float c_afLightSpecular[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
float afLight1[] =
{
c_afLightPosition[0], c_afLightPosition[1], c_afLightPosition[2], // pos
c_afLightDiffuse[0], c_afLightDiffuse[1], c_afLightDiffuse[2], // diffuse
c_afLightAmbient[0], c_afLightAmbient[1], c_afLightAmbient[2], // ambient
c_afLightSpecular[0], c_afLightSpecular[1], c_afLightSpecular[2], // specular
c_afLightPosition[3], // directional flag
1.0f, 0.0f, 0.0f // attenuation (constant, linear, quadratic)
};
CSpeedTreeRT::SetNumWindMatrices(c_nNumWindMatrices);
CSpeedTreeRT::SetLightAttributes(0, afLight1);
CSpeedTreeRT::SetLightState(0, true);
return true;
}
///////////////////////////////////////////////////////////////////////
// CSpeedTreeForestDirectX8::UploadWindMatrix
void CSpeedTreeForestDirectX8::UploadWindMatrix(UINT uiLocation, const float* pMatrix) const
{
STATEMANAGER.SetVertexShaderConstant(uiLocation, pMatrix, 4);
}
void CSpeedTreeForestDirectX8::UpdateCompundMatrix(const D3DXVECTOR3 & c_rEyeVec, const D3DXMATRIX & c_rmatView, const D3DXMATRIX & c_rmatProj)
{
// setup composite matrix for shader
D3DXMATRIX matBlend;
D3DXMatrixIdentity(&matBlend);
D3DXMATRIX matBlendShader;
D3DXMatrixMultiply(&matBlendShader, &c_rmatView, &c_rmatProj);
float afDirection[3];
afDirection[0] = matBlendShader.m[0][2];
afDirection[1] = matBlendShader.m[1][2];
afDirection[2] = matBlendShader.m[2][2];
CSpeedTreeRT::SetCamera(c_rEyeVec, afDirection);
D3DXMatrixTranspose(&matBlendShader, &matBlendShader);
STATEMANAGER.SetVertexShaderConstant(c_nVertexShader_CompoundMatrix, &matBlendShader, 4);
}
///////////////////////////////////////////////////////////////////////
// CSpeedTreeForestDirectX8::Render
void CSpeedTreeForestDirectX8::Render(unsigned long ulRenderBitVector)
{
UpdateSystem(CTimer::Instance().GetCurrentSecond());
if (m_pMainTreeMap.empty())
return;
if (!(ulRenderBitVector & Forest_RenderToShadow) && !(ulRenderBitVector & Forest_RenderToMiniMap))
UpdateCompundMatrix(CCameraManager::Instance().GetCurrentCamera()->GetEye(), ms_matView, ms_matProj);
DWORD dwLightState = STATEMANAGER.GetRenderState(D3DRS_LIGHTING);
DWORD dwColorVertexState = STATEMANAGER.GetRenderState(D3DRS_COLORVERTEX);
DWORD dwFogVertexMode = STATEMANAGER.GetRenderState(D3DRS_FOGVERTEXMODE);
#ifdef WRAPPER_USE_DYNAMIC_LIGHTING
STATEMANAGER.SetRenderState(D3DRS_LIGHTING, TRUE);
#else
STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE);
STATEMANAGER.SetRenderState(D3DRS_COLORVERTEX, TRUE);
#endif
TTreeMap::iterator itor;
UINT uiCount;
itor = m_pMainTreeMap.begin();
while (itor != m_pMainTreeMap.end())
{
CSpeedTreeWrapper * pMainTree = (itor++)->second;
CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount);
for (UINT i = 0; i < uiCount; ++i)
{
ppInstances[i]->Advance();
}
}
STATEMANAGER.SetVertexShaderConstant(c_nVertexShader_Light, m_afLighting, 3);
STATEMANAGER.SetVertexShaderConstant(c_nVertexShader_Fog, m_afFog, 1);
if (ulRenderBitVector & Forest_RenderToShadow)
{
//STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
}
else
{
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
STATEMANAGER.SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
STATEMANAGER.SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);
}
STATEMANAGER.SaveRenderState(D3DRS_ALPHATESTENABLE, TRUE);
STATEMANAGER.SaveRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
STATEMANAGER.SaveRenderState(D3DRS_CULLMODE, D3DCULL_CW);
// set up fog if it is enabled
if (STATEMANAGER.GetRenderState(D3DRS_FOGENABLE))
{
#ifdef WRAPPER_USE_GPU_WIND
STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_NONE); // GPU needs to work on all cards
#endif
}
// choose fixed function pipeline or custom shader for fronds and branches
STATEMANAGER.SetVertexShader(m_dwBranchVertexShader);
// render branches
if (ulRenderBitVector & Forest_RenderBranches)
{
itor = m_pMainTreeMap.begin();
while (itor != m_pMainTreeMap.end())
{
CSpeedTreeWrapper * pMainTree = (itor++)->second;
CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount);
pMainTree->SetupBranchForTreeType();
for (UINT i = 0; i < uiCount; ++i)
if (ppInstances[i]->isShow())
ppInstances[i]->RenderBranches();
}
}
// set render states
STATEMANAGER.SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
// render fronds
if (ulRenderBitVector & Forest_RenderFronds)
{
itor = m_pMainTreeMap.begin();
while (itor != m_pMainTreeMap.end())
{
CSpeedTreeWrapper * pMainTree = (itor++)->second;
CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount);
pMainTree->SetupFrondForTreeType();
for (UINT i = 0; i < uiCount; ++i)
if (ppInstances[i]->isShow())
ppInstances[i]->RenderFronds();
}
}
// render leaves
if (ulRenderBitVector & Forest_RenderLeaves)
{
STATEMANAGER.SetVertexShader(m_dwLeafVertexShader);
if (STATEMANAGER.GetRenderState(D3DRS_FOGENABLE))
{
#if defined WRAPPER_USE_GPU_WIND || defined WRAPPER_USE_GPU_LEAF_PLACEMENT
STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_NONE);
#endif
}
if (ulRenderBitVector & Forest_RenderToShadow || ulRenderBitVector & Forest_RenderToMiniMap)
{
STATEMANAGER.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_NOTEQUAL);
STATEMANAGER.SaveRenderState(D3DRS_ALPHAREF, 0x00000000);
}
itor = m_pMainTreeMap.begin();
while (itor != m_pMainTreeMap.end())
{
CSpeedTreeWrapper * pMainTree = (itor++)->second;
CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount);
pMainTree->SetupLeafForTreeType();
for (UINT i = 0; i < uiCount; ++i)
if (ppInstances[i]->isShow())
ppInstances[i]->RenderLeaves();
}
while (itor != m_pMainTreeMap.end())
(itor++)->second->EndLeafForTreeType();
if (ulRenderBitVector & Forest_RenderToShadow || ulRenderBitVector & Forest_RenderToMiniMap)
{
STATEMANAGER.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
STATEMANAGER.RestoreRenderState(D3DRS_ALPHAREF);
}
}
// render billboards
#ifndef WRAPPER_NO_BILLBOARD_MODE
if (ulRenderBitVector & Forest_RenderBillboards)
{
STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE);
STATEMANAGER.SetRenderState(D3DRS_COLORVERTEX, FALSE);
itor = m_pMainTreeMap.begin();
while (itor != m_pMainTreeMap.end())
{
CSpeedTreeWrapper * pMainTree = (itor++)->second;
CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount);
pMainTree->SetupBranchForTreeType();
for (UINT i = 0; i < uiCount; ++i)
if (ppInstances[i]->isShow())
ppInstances[i]->RenderBillboards();
}
}
#endif
STATEMANAGER.SetRenderState(D3DRS_LIGHTING, dwLightState);
STATEMANAGER.SetRenderState(D3DRS_COLORVERTEX, dwColorVertexState);
STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, dwFogVertexMode);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> TextureStage 1<><31> COLOROP<4F><50> ALPHAOP<4F><50> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>´<EFBFBD>. (<28>ȱ׷<C8B1><D7B7><EFBFBD> <20>˰<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>..)
if (!(ulRenderBitVector & Forest_RenderToShadow))
{
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
}
STATEMANAGER.RestoreRenderState(D3DRS_ALPHATESTENABLE);
STATEMANAGER.RestoreRenderState(D3DRS_ALPHAFUNC);
STATEMANAGER.RestoreRenderState(D3DRS_CULLMODE);
}

View File

@ -0,0 +1,64 @@
///////////////////////////////////////////////////////////////////////
// CSpeedTreeForestOpenGL Class
//
// (c) 2003 IDV, Inc.
//
// This class is provided to illustrate one way to incorporate
// SpeedTreeRT into an OpenGL application. All of the SpeedTreeRT
// calls that must be made on a per tree basis are done by this class.
// Calls that apply to all trees (i.e. static SpeedTreeRT functions)
// are made in the functions in main.cpp.
//
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may
// not be copied or disclosed except in accordance with the terms of
// that agreement.
//
// Copyright (c) 2001-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
#pragma once
///////////////////////////////////////////////////////////////////////
// Include Files
//#include <map>
#define SPEEDTREE_DATA_FORMAT_DIRECTX
#include "SpeedTreeForest.h"
#include "SpeedTreeMaterial.h"
///////////////////////////////////////////////////////////////////////
// class CSpeedTreeForestDirectX8 declaration
class CSpeedTreeForestDirectX8 : public CSpeedTreeForest, public CGraphicBase, public CSingleton<CSpeedTreeForestDirectX8>
{
public:
CSpeedTreeForestDirectX8();
virtual ~CSpeedTreeForestDirectX8();
void UploadWindMatrix(unsigned int uiLocation, const float* pMatrix) const;
void UpdateCompundMatrix(const D3DXVECTOR3 & c_rEyeVec, const D3DXMATRIX & c_rmatView, const D3DXMATRIX & c_rmatProj);
void Render(unsigned long ulRenderBitVector = Forest_RenderAll);
bool SetRenderingDevice(LPDIRECT3DDEVICE8 pDevice);
private:
bool InitVertexShaders();
private:
LPDIRECT3DDEVICE8 m_pDx; // the rendering context
DWORD m_dwBranchVertexShader; // branch/frond vertex shaders
DWORD m_dwLeafVertexShader; // leaf vertex shader
};

View File

@ -0,0 +1,468 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Distribute|Win32">
<Configuration>Distribute</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="MfcDebug|Win32">
<Configuration>MfcDebug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="MfcRelease|Win32">
<Configuration>MfcRelease</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="VTune|Win32">
<Configuration>VTune</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<ProjectName>SpeedTreeLib</ProjectName>
<ProjectGuid>{0FDDD886-1EB5-4655-80C3-EF08087FAEFD}</ProjectGuid>
<RootNamespace>SpeedTreeLib</RootNamespace>
<SccProjectName>SAK</SccProjectName>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
<SccProvider>SAK</SccProvider>
<Keyword>MFCProj</Keyword>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>17.0.32203.90</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<VcpkgUseStatic>true</VcpkgUseStatic>
<VcpkgConfiguration>$(Configuration)</VcpkgConfiguration>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">
<VcpkgUseStatic>true</VcpkgUseStatic>
<VcpkgConfiguration>$(Configuration)</VcpkgConfiguration>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<VcpkgUseStatic>true</VcpkgUseStatic>
<VcpkgConfiguration>$(Configuration)</VcpkgConfiguration>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<AdditionalIncludeDirectories>$(SolutionDir)extern\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>.\Release/SpeedTreeLib.pch</PrecompiledHeaderOutputFile>
<AssemblerListingLocation>.\Release/</AssemblerListingLocation>
<ObjectFileName>.\Release/</ObjectFileName>
<ProgramDataBaseFileName>.\Release/</ProgramDataBaseFileName>
<BrowseInformation />
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>Default</CompileAs>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0412</Culture>
</ResourceCompile>
<Lib>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<AdditionalIncludeDirectories>$(SolutionDir)extern\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>.\Distribute/SpeedTreeLib.pch</PrecompiledHeaderOutputFile>
<AssemblerOutput>All</AssemblerOutput>
<AssemblerListingLocation>.\Distribute/</AssemblerListingLocation>
<ObjectFileName>.\Distribute/</ObjectFileName>
<ProgramDataBaseFileName>.\Distribute/</ProgramDataBaseFileName>
<BrowseInformation />
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>Default</CompileAs>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0412</Culture>
</ResourceCompile>
<Lib>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">
<ClCompile>
<AdditionalOptions>/Gs %(AdditionalOptions)</AdditionalOptions>
<Optimization>Disabled</Optimization>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<AdditionalIncludeDirectories>.;../../extern/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader />
<PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>.\VTune/SpeedTreeLib.pch</PrecompiledHeaderOutputFile>
<AssemblerOutput>All</AssemblerOutput>
<AssemblerListingLocation>.\VTune/</AssemblerListingLocation>
<ObjectFileName>.\VTune/</ObjectFileName>
<ProgramDataBaseFileName>.\VTune/</ProgramDataBaseFileName>
<BrowseInformation />
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>Default</CompileAs>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0412</Culture>
</ResourceCompile>
<Lib>
<OutputFile>.\VTune\SpeedTreeLib.lib</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<AdditionalIncludeDirectories>.;../../extern/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeaderOutputFile>.\SpeedTreeLib___Win32_MfcRelease/SpeedTreeLib.pch</PrecompiledHeaderOutputFile>
<AssemblerOutput>All</AssemblerOutput>
<AssemblerListingLocation>.\SpeedTreeLib___Win32_MfcRelease/</AssemblerListingLocation>
<ObjectFileName>.\SpeedTreeLib___Win32_MfcRelease/</ObjectFileName>
<ProgramDataBaseFileName>.\SpeedTreeLib___Win32_MfcRelease/</ProgramDataBaseFileName>
<BrowseInformation />
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0412</Culture>
</ResourceCompile>
<Lib>
<OutputFile>.\SpeedTreeLib___Win32_MfcRelease\SpeedTreeLib.lib</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.;../../extern/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeaderOutputFile>.\SpeedTreeLib___Win32_MfcDebug/SpeedTreeLib.pch</PrecompiledHeaderOutputFile>
<AssemblerListingLocation>.\SpeedTreeLib___Win32_MfcDebug/</AssemblerListingLocation>
<ObjectFileName>.\SpeedTreeLib___Win32_MfcDebug/</ObjectFileName>
<ProgramDataBaseFileName>.\SpeedTreeLib___Win32_MfcDebug/</ProgramDataBaseFileName>
<BrowseInformation />
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0412</Culture>
</ResourceCompile>
<Lib>
<OutputFile>.\SpeedTreeLib___Win32_MfcDebug\SpeedTreeLib.lib</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(SolutionDir)extern\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader />
<PrecompiledHeaderOutputFile>.\Debug/SpeedTreeLib.pch</PrecompiledHeaderOutputFile>
<AssemblerListingLocation>.\Debug/</AssemblerListingLocation>
<ObjectFileName>.\Debug/</ObjectFileName>
<ProgramDataBaseFileName>.\Debug/</ProgramDataBaseFileName>
<BrowseInformation />
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<CompileAs>Default</CompileAs>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0412</Culture>
</ResourceCompile>
<Lib>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="BoundaryShapeManager.cpp">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</PrecompiledHeader>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">MaxSpeed</Optimization>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">
</PrecompiledHeader>
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">MaxSpeed</Optimization>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</PrecompiledHeader>
<FavorSizeOrSpeed Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">Size</FavorSizeOrSpeed>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="SpeedGrassRT.cpp">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</PrecompiledHeader>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">MaxSpeed</Optimization>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">
</PrecompiledHeader>
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">MaxSpeed</Optimization>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</PrecompiledHeader>
<FavorSizeOrSpeed Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">Size</FavorSizeOrSpeed>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="SpeedGrassWrapper.cpp">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</PrecompiledHeader>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">MaxSpeed</Optimization>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">
</PrecompiledHeader>
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">MaxSpeed</Optimization>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</PrecompiledHeader>
<FavorSizeOrSpeed Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">Size</FavorSizeOrSpeed>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="SpeedTreeForest.cpp">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</PrecompiledHeader>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">MaxSpeed</Optimization>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">
</PrecompiledHeader>
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">MaxSpeed</Optimization>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</PrecompiledHeader>
<FavorSizeOrSpeed Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">Size</FavorSizeOrSpeed>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="SpeedTreeForestDirectX8.cpp">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</PrecompiledHeader>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">MaxSpeed</Optimization>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">
</PrecompiledHeader>
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">MaxSpeed</Optimization>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</PrecompiledHeader>
<FavorSizeOrSpeed Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">Size</FavorSizeOrSpeed>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="SpeedTreeWrapper.cpp">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</PrecompiledHeader>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">MaxSpeed</Optimization>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">
</PrecompiledHeader>
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">MaxSpeed</Optimization>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</PrecompiledHeader>
<FavorSizeOrSpeed Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">Size</FavorSizeOrSpeed>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="StdAfx.cpp">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">MaxSpeed</Optimization>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">Create</PrecompiledHeader>
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">MaxSpeed</Optimization>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<FavorSizeOrSpeed Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">Size</FavorSizeOrSpeed>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BoundaryShapeManager.h" />
<ClInclude Include="Constants.h" />
<ClInclude Include="SpeedGrassRT.h" />
<ClInclude Include="SpeedGrassWrapper.h" />
<ClInclude Include="SpeedTreeConfig.h" />
<ClInclude Include="SpeedTreeForest.h" />
<ClInclude Include="SpeedTreeForestDirectX8.h" />
<ClInclude Include="SpeedTreeMaterial.h" />
<ClInclude Include="SpeedTreeWrapper.h" />
<ClInclude Include="StdAfx.h" />
<ClInclude Include="VertexShaders.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{87ccc415-625a-4d07-8825-3413ed466a45}</UniqueIdentifier>
<Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{1c6df347-ff1c-4aeb-95c6-e15d2ce6c906}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="BoundaryShapeManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SpeedGrassRT.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SpeedGrassWrapper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SpeedTreeForest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SpeedTreeForestDirectX8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SpeedTreeWrapper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="StdAfx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BoundaryShapeManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Constants.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SpeedGrassRT.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SpeedGrassWrapper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SpeedTreeConfig.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SpeedTreeForest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SpeedTreeForestDirectX8.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SpeedTreeMaterial.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SpeedTreeWrapper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="StdAfx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="VertexShaders.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -0,0 +1,79 @@
///////////////////////////////////////////////////////////////////////
// CSpeedTreeMaterial Class
//
// (c) 2003 IDV, Inc.
//
// This class is provided to illustrate one way to incorporate
// SpeedTreeRT into an OpenGL application. All of the SpeedTreeRT
// calls that must be made on a per tree basis are done by this class.
// Calls that apply to all trees (i.e. static SpeedTreeRT functions)
// are made in the functions in main.cpp.
//
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may
// not be copied or disclosed except in accordance with the terms of
// that agreement.
//
// Copyright (c) 2001-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
#pragma once
///////////////////////////////////////////////////////////////////////
// Include Files
#include <d3d8.h>
#include <d3d8types.h>
#include <d3dx8.h>
///////////////////////////////////////////////////////////////////////
// class CSpeedTreeMaterial declaration/definiton
class CSpeedTreeMaterial
{
public:
CSpeedTreeMaterial()
{
m_cMaterial.Ambient.r = m_cMaterial.Diffuse.r = m_cMaterial.Specular.r = m_cMaterial.Emissive.r = 1.0f;
m_cMaterial.Ambient.g = m_cMaterial.Diffuse.g = m_cMaterial.Specular.g = m_cMaterial.Emissive.g = 1.0f;
m_cMaterial.Ambient.b = m_cMaterial.Diffuse.b = m_cMaterial.Specular.b = m_cMaterial.Emissive.b = 1.0f;
m_cMaterial.Ambient.a = m_cMaterial.Diffuse.a = m_cMaterial.Specular.a = m_cMaterial.Emissive.a = 1.0f;
m_cMaterial.Power = 5.0f;
}
void Set(const float * pMaterialArray)
{
memcpy(&m_cMaterial.Diffuse, pMaterialArray, 3 * sizeof(float));
m_cMaterial.Diffuse.a = 1.0f;
memcpy(&m_cMaterial.Ambient, pMaterialArray + 3, 3 * sizeof(float));
m_cMaterial.Ambient.a = 1.0f;
memcpy(&m_cMaterial.Specular, pMaterialArray + 6, 3 * sizeof(float));
m_cMaterial.Specular.a = 1.0f;
memcpy(&m_cMaterial.Emissive, pMaterialArray + 9, 3 * sizeof(float));
m_cMaterial.Emissive.a = 1.0f;
m_cMaterial.Power = pMaterialArray[12];
}
D3DMATERIAL8 * Get()
{
return &m_cMaterial;
}
private:
D3DMATERIAL8 m_cMaterial; // the material object
};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,203 @@
///////////////////////////////////////////////////////////////////////
// SpeedTreeRTExample Class
//
// (c) 2003 IDV, Inc.
//
// This class is provided to illustrate one way to incorporate
// SpeedTreeRT into an OpenGL application. All of the SpeedTreeRT
// calls that must be made on a per tree basis are done by this class.
// Calls that apply to all trees (i.e. static SpeedTreeRT functions)
// are made in the functions in main.cpp.
//
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may
// not be copied or disclosed except in accordance with the terms of
// that agreement.
//
// Copyright (c) 2001-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
//
#pragma once
#pragma warning (disable : 4786)
///////////////////////////////////////////////////////////////////////
// Include files
#include "SpeedTreeMaterial.h"
#include <SpeedTreeRT.h>
#include <d3d8.h>
#include <d3d8types.h>
#include <d3dx8.h>
#include <vector>
#include "../eterLib/GrpObjectInstance.h"
#include "../eterLib/GrpImageInstance.h"
#ifndef SAFE_DELETE
#define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } }
#endif
#ifndef SAFE_DELETE_ARRAY
#define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p) = NULL; } }
#endif
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = NULL; } }
#endif
///////////////////////////////////////////////////////////////////////
// class CSpeedTreeWrapper declaration
#pragma warning(push)
#pragma warning(disable:4100)
class CSpeedTreeWrapper : public CGraphicObjectInstance
{
enum
{
ID = TREE_OBJECT
};
int GetType() const { return ID; }
// Collision Data
protected:
virtual void OnUpdateCollisionData(const CStaticCollisionDataVector * pscdVector);
virtual void OnUpdateHeighInstance(CAttributeInstance * pAttributeInstance) {}
virtual bool OnGetObjectHeight(float fX, float fY, float * pfHeight) { return false; }
// Bounding Sphere
public:
virtual bool GetBoundingSphere(D3DXVECTOR3 & v3Center, float & fRadius);
public:
static bool ms_bSelfShadowOn;
public:
// methods from CGraphicObjectInstance
virtual void SetPosition(float x, float y, float z);
virtual void CalculateBBox();
virtual void OnRender(); // Render <20>ÿ<EFBFBD> <20>޼ҵ<DEBC>, <20>׷<EFBFBD><D7B7><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>䳪 Ư<><C6AF><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><ECBFA1> <20><><EFBFBD><EFBFBD> Render <20><><EFBFBD><EFBFBD> <20>θ<EFBFBD><CEB8><EFBFBD>
// <20><> <20>̿ܿ<CCBF><DCBF><EFBFBD> RenderBranches, RenderFronds <20><><EFBFBD><EFBFBD> <20>޼ҵ带 CSpeedTreeForest<73><74><EFBFBD><EFBFBD> ȣ<><C8A3><EFBFBD>Ѵ<EFBFBD>.
virtual void OnBlendRender() {}
virtual void OnRenderToShadowMap() {}
virtual void OnRenderShadow() {}
virtual void OnRenderPCBlocker();
public:
CSpeedTreeWrapper();
virtual ~CSpeedTreeWrapper();
const float * GetPosition();
static void SetVertexShaders(DWORD dwBranchVertexShader, DWORD dwLeafVertexShader);
// geometry
bool LoadTree(const char * pszSptFile, const BYTE * c_pbBlock = NULL, unsigned int uiBlockSize = 0, unsigned int nSeed = 1, float fSize = -1.0f, float fSizeVariance = -1.0f);
const float * GetBoundingBox(void) const { return m_afBoundingBox; }
void GetTreeSize(float & r_fSize, float & r_fVariance);
UINT GetCollisionObjectCount();
void GetCollisionObject(unsigned int nIndex, CSpeedTreeRT::ECollisionObjectType& eType, float* pPosition, float* pDimensions);
// rendering
void SetupBranchForTreeType(void) const;
void SetupFrondForTreeType(void) const;
void SetupLeafForTreeType(void) const;
void EndLeafForTreeType(void);
#ifdef WRAPPER_USE_GPU_LEAF_PLACEMENT
void UploadLeafTables(unsigned int uiLocation) const;
#endif
void RenderBranches(void) const;
void RenderFronds(void) const;
void RenderLeaves(void) const;
void RenderBillboards(void) const;
// instancing
CSpeedTreeWrapper ** GetInstances(unsigned int& nCount);
CSpeedTreeWrapper * InstanceOf(void) const { return m_pInstanceOf; }
CSpeedTreeWrapper * MakeInstance();
void DeleteInstance(CSpeedTreeWrapper * pInstance);
CSpeedTreeRT * GetSpeedTree(void) const { return m_pSpeedTree; }
// lighting
const CSpeedTreeMaterial & GetBranchMaterial(void) const { return m_cBranchMaterial; }
const CSpeedTreeMaterial & GetFrondMaterial(void) const { return m_cFrondMaterial; }
const CSpeedTreeMaterial & GetLeafMaterial(void) const { return m_cLeafMaterial; }
float GetLeafLightingAdjustment(void) const { return m_pSpeedTree->GetLeafLightingAdjustment( ); }
// wind
void SetWindStrength(float fStrength) { m_pSpeedTree->SetWindStrength(fStrength); }
void Advance(void);
// utility
LPDIRECT3DTEXTURE8 GetBranchTexture(void) const;
void CleanUpMemory(void);
private:
void SetupBuffers(void);
void SetupBranchBuffers(void);
void SetupFrondBuffers(void);
void SetupLeafBuffers(void);
void PositionTree(void) const;
static bool LoadTexture(const char* pFilename, CGraphicImageInstance & rImage);
void SetShaderConstants(const float* pMaterial) const;
private:
// SpeedTreeRT data
CSpeedTreeRT* m_pSpeedTree; // the SpeedTree object
CSpeedTreeRT::STextures* m_pTextureInfo; // texture info cache
bool m_bIsInstance; // is this an instance?
std::vector<CSpeedTreeWrapper*> m_vInstances; // what is an instance of us
CSpeedTreeWrapper* m_pInstanceOf; // which tree is this an instance of
// geometry cache
CSpeedTreeRT::SGeometry* m_pGeometryCache; // cache for pulling geometry from SpeedTree avoids lots of reallocation
// branch buffers
LPDIRECT3DVERTEXBUFFER8 m_pBranchVertexBuffer; // branch vertex buffer
unsigned int m_unBranchVertexCount; // number of vertices in branches
LPDIRECT3DINDEXBUFFER8 m_pBranchIndexBuffer; // branch index buffer
unsigned short* m_pBranchIndexCounts; // number of indexes per branch LOD level
// frond buffers
LPDIRECT3DVERTEXBUFFER8 m_pFrondVertexBuffer; // frond vertex buffer
unsigned int m_unFrondVertexCount; // number of vertices in frond
LPDIRECT3DINDEXBUFFER8 m_pFrondIndexBuffer; // frond index buffer
unsigned short* m_pFrondIndexCounts; // number of indexes per frond LOD level
// leaf buffers
unsigned short m_usNumLeafLods; // the number of leaf LODs
LPDIRECT3DVERTEXBUFFER8* m_pLeafVertexBuffer; // leaf vertex buffer
bool* m_pLeavesUpdatedByCpu; // stores which LOD's have been updated already per frame
// tree properties
float m_afPos[3]; // tree position
float m_afBoundingBox[6]; // tree bounding box
// materials
CSpeedTreeMaterial m_cBranchMaterial; // branch material
CSpeedTreeMaterial m_cLeafMaterial; // leaf material
CSpeedTreeMaterial m_cFrondMaterial; // frond material
// branch texture
CGraphicImageInstance m_BranchImageInstance;
CGraphicImageInstance m_ShadowImageInstance; // shadow texture object (used if shadows are enabled)
CGraphicImageInstance m_CompositeImageInstance;
static DWORD ms_dwBranchVertexShader;
static DWORD ms_dwLeafVertexShader;
};
#pragma warning(pop)

View File

@ -0,0 +1,6 @@
// stdafx.cpp : source file that includes just the standard includes
// SpeedTreeLib.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"

19
src/SpeedTreeLib/StdAfx.h Normal file
View File

@ -0,0 +1,19 @@
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <assert.h>
//#include <crtdbg.h>
//#include "Forest.h"
#include "SpeedTreeForestDirectX8.h"
// Armadillo nanomite protection
#if !defined(NANOBEGIN) && !defined(NANOEND)
#ifdef _DEBUG
#define NANOBEGIN
#define NANOEND
#else
#include <armadillo/SecuredSections.h>
#endif
#endif

View File

@ -0,0 +1,332 @@
///////////////////////////////////////////////////////////////////////
// SpeedTreeRT DirectX Example
//
// (c) 2003 IDV, Inc.
//
// This example demonstrates how to render trees using SpeedTreeRT
// and DirectX. Techniques illustrated include ".spt" file parsing,
// static lighting, dynamic lighting, LOD implementation, cloning,
// instancing, and dynamic wind effects.
//
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may
// not be copied or disclosed except in accordance with the terms of
// that agreement.
//
// Copyright (c) 2001-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
///////////////////////////////////////////////////////////////////////
// Includes
#pragma once
#include "SpeedTreeConfig.h"
#include <map>
#include <string>
///////////////////////////////////////////////////////////////////////
// Branch & Frond Vertex Formats
static DWORD D3DFVF_SPEEDTREE_BRANCH_VERTEX =
D3DFVF_XYZ | // always have the position
#ifdef WRAPPER_USE_DYNAMIC_LIGHTING // precomputed colors or geometric normals
D3DFVF_NORMAL |
#else
D3DFVF_DIFFUSE |
#endif
#ifdef WRAPPER_RENDER_SELF_SHADOWS
D3DFVF_TEX2 | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE2(1) // shadow texture coordinates
#else
D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0) // always have first texture layer coords
#endif
#ifdef WRAPPER_USE_GPU_WIND
| D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE2(2) // GPU Only - wind weight and index passed in second texture layer
#endif
;
///////////////////////////////////////////////////////////////////////
// FVF Branch Vertex Structure
struct SFVFBranchVertex
{
D3DXVECTOR3 m_vPosition; // Always Used
#ifdef WRAPPER_USE_DYNAMIC_LIGHTING
D3DXVECTOR3 m_vNormal; // Dynamic Lighting Only
#else
DWORD m_dwDiffuseColor; // Static Lighting Only
#endif
FLOAT m_fTexCoords[2]; // Always Used
#ifdef WRAPPER_RENDER_SELF_SHADOWS
FLOAT m_fShadowCoords[2]; // Texture coordinates for the shadows
#endif
#ifdef WRAPPER_USE_GPU_WIND
FLOAT m_fWindIndex; // GPU Only
FLOAT m_fWindWeight;
#endif
};
///////////////////////////////////////////////////////////////////////
// Branch/Frond Vertex Program
static const char g_achSimpleVertexProgram[] =
{
"vs.1.1\n" // identity shader version
"mov oT0.xy, v7\n" // always pass texcoord0 through
#ifdef WRAPPER_RENDER_SELF_SHADOWS
"mov oT1.xy, v8\n" // pass shadow texcoords through if enabled
#endif
// retrieve and convert wind matrix index
"mov a0.x, v9.x\n"
// perform wind interpolation
"m4x4 r1, v0, c[54+a0.x]\n" // compute full wind effect
"sub r2, r1, v0\n" // compute difference between full wind and none
"mov r3.x, v9.y\n" // mad can't access two v's at once, use r3.x as tmp
"mad r1, r2, r3.x, v0\n" // perform interpolation
"add r2, c[52], r1\n" // translate to tree's position
"m4x4 oPos, r2, c[0]\n" // project to screen
#ifdef WRAPPER_USE_FOG
"dp4 r1, r2, c[2]\n" // find distance to vertex
"sub r2.x, c[85].y, r1.z\n" // linear fogging
"mul oFog, r2.x, c[85].z\n" // write to fog register
#endif
#ifdef WRAPPER_USE_STATIC_LIGHTING
"mov oD0, v5\n" // pass color through
#else
"mov r1, c[74]\n" // can only use one const register per instruction
"mul r5, c[73], r1\n" // diffuse values
"mov r1, c[75]\n" // can only use one const register per instruction
"mul r4, c[72], r1\n" // ambient values
"dp3 r2, v3, c[71]\n" // dot light direction with normal
// "max r2.x, r2.x, c[70].x\n" // limit it
"mad oD0, r2.x, r5, r4\n" // compute the final color
#endif
};
///////////////////////////////////////////////////////////////////////
// LoadBranchShader
static DWORD LoadBranchShader(LPDIRECT3DDEVICE8 pDx)
{
#ifndef WRAPPER_USE_GPU_WIND
return D3DFVF_SPEEDTREE_BRANCH_VERTEX;
#endif
// branch shader declaration
DWORD pBranchShaderDecl[] =
{
D3DVSD_STREAM(0),
D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
#ifdef WRAPPER_USE_DYNAMIC_LIGHTING
D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT3),
#else
D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR),
#endif
D3DVSD_REG(D3DVSDE_TEXCOORD0, D3DVSDT_FLOAT2),
#ifdef WRAPPER_RENDER_SELF_SHADOWS
D3DVSD_REG(D3DVSDE_TEXCOORD1, D3DVSDT_FLOAT2),
#endif
#ifdef WRAPPER_USE_GPU_WIND
D3DVSD_REG(D3DVSDE_TEXCOORD2, D3DVSDT_FLOAT2),
#endif
D3DVSD_END( )
};
// assemble shader
DWORD dwShader;
LPD3DXBUFFER pCode, pError;
if (D3DXAssembleShader(g_achSimpleVertexProgram, sizeof(g_achSimpleVertexProgram) - 1, 0, NULL, &pCode, &pError) == D3D_OK)
{
if (pDx->CreateVertexShader(pBranchShaderDecl, (DWORD*) pCode->GetBufferPointer( ), &dwShader, 0) != D3D_OK)
{
char szError[1024];
sprintf(szError, "Failed to create branch vertex shader.");
MessageBox(NULL, szError, "Vertex Shader Error", MB_ICONSTOP);
}
}
else
{
char szError[1024];
sprintf(szError, "Failed to assemble branch vertex shader.\nThe error reported is [ %s ].\n", pError->GetBufferPointer( ));
MessageBox(NULL, szError, "Vertex Shader Error", MB_ICONSTOP);
}
if (pCode)
pCode->Release();
return dwShader;
}
///////////////////////////////////////////////////////////////////////
// Leaf Vertex Formats
static DWORD D3DFVF_SPEEDTREE_LEAF_VERTEX =
D3DFVF_XYZ | // always have the position
#ifdef WRAPPER_USE_DYNAMIC_LIGHTING // precomputed colors or geometric normals
D3DFVF_NORMAL |
#else
D3DFVF_DIFFUSE |
#endif
D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0) // always have first texture layer coords
#if defined WRAPPER_USE_GPU_WIND || defined WRAPPER_USE_GPU_LEAF_PLACEMENT
| D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE4(2) // GPU Only - wind weight and index passed in second texture layer
#endif
;
///////////////////////////////////////////////////////////////////////
// FVF Leaf Vertex Structure
struct SFVFLeafVertex
{
D3DXVECTOR3 m_vPosition; // Always Used
#ifdef WRAPPER_USE_DYNAMIC_LIGHTING
D3DXVECTOR3 m_vNormal; // Dynamic Lighting Only
#else
DWORD m_dwDiffuseColor; // Static Lighting Only
#endif
FLOAT m_fTexCoords[2]; // Always Used
#if defined WRAPPER_USE_GPU_WIND || defined WRAPPER_USE_GPU_LEAF_PLACEMENT
FLOAT m_fWindIndex; // Only used when GPU is involved
FLOAT m_fWindWeight;
FLOAT m_fLeafPlacementIndex;
FLOAT m_fLeafScalarValue;
#endif
};
///////////////////////////////////////////////////////////////////////
// Leaf Vertex Program
static const char g_achLeafVertexProgram[] =
{
"vs.1.1\n" // identity shader version
"mov oT0.xy, v7\n" // always pass texcoord0 through
#ifdef WRAPPER_USE_GPU_WIND
// retrieve and convert wind matrix index
"mov a0.x, v9.x\n"
// perform wind interpolation
"m4x4 r1, v0, c[54+a0.x]\n" // compute full wind effect
"sub r2, r1, v0\n" // compute difference between full wind and none
"mov r3.x, v9.y\n" // mad can't access two v's at once, use r3.x as tmp
"mad r0, r2, r3.x, v0\n" // perform interpolation
#else
"mov r0, v0\n" // wind already handled, pass the vertex through
#endif
#ifdef WRAPPER_USE_GPU_LEAF_PLACEMENT
"mov a0.x, v9.z\n" // place the leaves
"mul r1, c[a0.x], v9.w\n"
"add r0, r1, r0\n"
#endif
"add r0, c[52], r0\n" // translate to tree's position
"m4x4 oPos, r0, c[0]\n" // project to screen
#ifdef WRAPPER_USE_FOG
"dp4 r1, r0, c[2]\n" // find distance to vertex
"sub r2.x, c[85].y, r1.z\n" //
"mul oFog, r2.x, c[85].z\n"
#endif
#ifdef WRAPPER_USE_STATIC_LIGHTING
"mov oD0, v5\n" // pass color through
#else
"mov r1, c[74]\n" // can only use one const register per instruction
"mul r5, c[73], r1\n" // diffuse values
"mov r1, c[75]\n" // can only use one const register per instruction
"mul r4, c[72], r1\n" // ambient values
"dp3 r2.x, v3, c[71]\n" // dot light direction with normal
"max r2.x, r2.x, c[70].x\n" // limit it
"mad oD0, r2.x, r5, r4\n" // compute the final color
#endif
};
///////////////////////////////////////////////////////////////////////
// LoadLeafShader
static DWORD LoadLeafShader(LPDIRECT3DDEVICE8 pDx)
{
DWORD dwShader = D3DFVF_SPEEDTREE_LEAF_VERTEX;
#if defined WRAPPER_USE_GPU_LEAF_PLACEMENT || defined WRAPPER_USE_GPU_WIND
// leaf shader declaration
DWORD pLeafShaderDecl[ ] =
{
D3DVSD_STREAM(0),
D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
#ifdef WRAPPER_USE_DYNAMIC_LIGHTING
D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT3),
#else
D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR),
#endif
D3DVSD_REG(D3DVSDE_TEXCOORD0, D3DVSDT_FLOAT2),
D3DVSD_REG(D3DVSDE_TEXCOORD2, D3DVSDT_FLOAT4),
D3DVSD_END( )
};
// assemble shader
LPD3DXBUFFER pCode, pError;
if (D3DXAssembleShader(g_achLeafVertexProgram, sizeof(g_achLeafVertexProgram) - 1, 0, NULL, &pCode, &pError) == D3D_OK)
{
if (pDx->CreateVertexShader(pLeafShaderDecl, (DWORD*) pCode->GetBufferPointer( ), &dwShader, 0) != D3D_OK)
{
Tracef("Failed to create leaf vertex shader.");
/*
char szError[1024];
sprintf(szError, "Failed to create leaf vertex shader.");
MessageBox(NULL, szError, "Vertex Shader Error", MB_ICONSTOP);
*/
}
}
else
{
Tracef("Failed to assemble leaf vertex shader. The error reported is [ %s ].\n", pError->GetBufferPointer( ));
/*
char szError[1024];
sprintf(szError, "Failed to assemble leaf vertex shader. The error reported is [ %s ].\n", pError->GetBufferPointer( ));
MessageBox(NULL, szError, "Vertex Shader Error", MB_ICONSTOP);
*/
}
if (pCode)
pCode->Release( );
#else
dwShader = D3DFVF_SPEEDTREE_LEAF_VERTEX;
#endif
return dwShader;
}