Browse Source

Played with terrain and add ref

ogre-port2
Macoy Madson 6 months ago
parent
commit
26fe8ab045
6 changed files with 873 additions and 16 deletions
  1. +3
    -1
      Content/assets/World_Material.001.material.xml
  2. +853
    -0
      Content/shaders/sand.shader
  3. BIN
      assets/short04_diffuse.png
  4. BIN
      references/gaf+03.pdf
  5. +11
    -14
      src/Main.cpp
  6. +6
    -1
      src/Terrain.cpp

+ 3
- 1
Content/assets/World_Material.001.material.xml View File

@ -1,7 +1,9 @@
<Material>
<Shader source="shaders/model.shader" />
<Shader source="shaders/sand.shader" />
<ShaderFlag name="_F01_Skinning" />
<!-- <ShaderFlag name="_F04_EnvMapping"/> -->
<Uniform name="matDiffuseCol" a="1.0" b="0.16163891" c="0" d="1" />
<Sampler name="albedoMap" map="textures/TestGrid_Sandy.png" />
<!-- <Sampler name="envMap" map="models/skybox/skybox.dds" /> -->
</Material>

+ 853
- 0
Content/shaders/sand.shader View File

@ -0,0 +1,853 @@
[[FX]]
// Supported Flags
/* ---------------
_F01_Skinning
_F02_NormalMapping
_F03_ParallaxMapping
_F04_EnvMapping
_F05_AlphaTest
*/
// Samplers
sampler2D albedoMap = sampler_state
{
Texture = "textures/common/white.tga";
};
sampler2D normalMap = sampler_state
{
Texture = "textures/common/defnorm.tga";
};
samplerCube ambientMap = sampler_state
{
Address = Clamp;
Filter = Bilinear;
MaxAnisotropy = 1;
};
samplerCube envMap = sampler_state
{
Address = Clamp;
Filter = Bilinear;
MaxAnisotropy = 1;
};
// Uniforms
float4 matDiffuseCol <
string desc_abc = "abc: diffuse color";
string desc_d = "d: alpha for opacity";
> = {1.0, 1.0, 1.0, 1.0};
float4 matSpecParams <
string desc_abc = "abc: specular color";
string desc_d = "d: gloss";
> = {0.04, 0.04, 0.04, 0.5};
float4 matLightDirectionParams <
string desc_abc = "abc: Light direction";
> = {-0.301, -0.6858, -0.6626};
// Contexts
context ATTRIBPASS
{
VertexShader = compile GLSL VS_GENERAL;
PixelShader = compile GLSL FS_ATTRIBPASS;
}
context SHADOWMAP
{
VertexShader = compile GLSL VS_SHADOWMAP;
PixelShader = compile GLSL FS_SHADOWMAP;
}
context LIGHTING
{
VertexShader = compile GLSL VS_GENERAL;
PixelShader = compile GLSL FS_LIGHTING;
ZWriteEnable = false;
BlendMode = Add;
}
context AMBIENT
{
VertexShader = compile GLSL VS_GENERAL;
PixelShader = compile GLSL FS_AMBIENT;
}
OpenGL4
{
context ATTRIBPASS
{
VertexShader = compile GLSL VS_GENERAL_GL4;
PixelShader = compile GLSL FS_ATTRIBPASS_GL4;
}
context SHADOWMAP
{
VertexShader = compile GLSL VS_SHADOWMAP_GL4;
PixelShader = compile GLSL FS_SHADOWMAP_GL4;
}
context LIGHTING
{
VertexShader = compile GLSL VS_GENERAL_GL4;
PixelShader = compile GLSL FS_LIGHTING_GL4;
ZWriteEnable = false;
BlendMode = Add;
}
context AMBIENT
{
VertexShader = compile GLSL VS_GENERAL_GL4;
PixelShader = compile GLSL FS_AMBIENT_GL4;
}
}
[[VS_GENERAL]]
// =================================================================================================
#ifdef _F03_ParallaxMapping
#define _F02_NormalMapping
#endif
#include "shaders/utilityLib/vertCommon.glsl"
#ifdef _F01_Skinning
#include "shaders/utilityLib/vertSkinning.glsl"
#endif
uniform mat4 viewProjMat;
uniform vec3 viewerPos;
attribute vec3 vertPos;
attribute vec2 texCoords0;
attribute vec3 normal;
#ifdef _F02_NormalMapping
attribute vec4 tangent;
#endif
varying vec4 pos, vsPos;
varying vec2 texCoords;
#ifdef _F02_NormalMapping
varying mat3 tsbMat;
#else
varying vec3 tsbNormal;
#endif
#ifdef _F03_ParallaxMapping
varying vec3 eyeTS;
#endif
void main( void )
{
#ifdef _F01_Skinning
mat4 skinningMat = calcSkinningMat();
mat3 skinningMatVec = getSkinningMatVec( skinningMat );
#endif
// Calculate normal
#ifdef _F01_Skinning
vec3 _normal = normalize( calcWorldVec( skinVec( normal, skinningMatVec ) ) );
#else
vec3 _normal = normalize( calcWorldVec( normal ) );
#endif
// Calculate tangent and bitangent
#ifdef _F02_NormalMapping
#ifdef _F01_Skinning
vec3 _tangent = normalize( calcWorldVec( skinVec( tangent.xyz, skinningMatVec ) ) );
#else
vec3 _tangent = normalize( calcWorldVec( tangent.xyz ) );
#endif
vec3 _bitangent = cross( _normal, _tangent ) * tangent.w;
tsbMat = calcTanToWorldMat( _tangent, _bitangent, _normal );
#else
tsbNormal = _normal;
#endif
// Calculate world space position
#ifdef _F01_Skinning
pos = calcWorldPos( skinPos( vec4( vertPos, 1.0 ), skinningMat ) );
#else
pos = calcWorldPos( vec4( vertPos, 1.0 ) );
#endif
vsPos = calcViewPos( pos );
// Calculate tangent space eye vector
#ifdef _F03_ParallaxMapping
eyeTS = calcTanVec( viewerPos - pos.xyz, _tangent, _bitangent, _normal );
#endif
// Calculate texture coordinates and clip space position
texCoords = texCoords0;
gl_Position = viewProjMat * pos;
}
[[VS_GENERAL_GL4]]
// =================================================================================================
#ifdef _F03_ParallaxMapping
#define _F02_NormalMapping
#endif
#include "shaders/utilityLib/vertCommon.glsl"
#ifdef _F01_Skinning
#include "shaders/utilityLib/vertSkinningGL4.glsl"
#endif
uniform mat4 viewProjMat;
uniform vec3 viewerPos;
layout( location = 0 ) in vec3 vertPos;
layout( location = 1 ) in vec3 normal;
layout( location = 5 ) in vec2 texCoords0;
#ifdef _F02_NormalMapping
layout ( location = 2 ) in vec4 tangent;
#endif
out vec4 pos, vsPos;
out vec2 texCoords;
#ifdef _F02_NormalMapping
out mat3 tsbMat;
#else
out vec3 tsbNormal;
#endif
#ifdef _F03_ParallaxMapping
out vec3 eyeTS;
#endif
void main( void )
{
#ifdef _F01_Skinning
mat4 skinningMat = calcSkinningMat();
mat3 skinningMatVec = getSkinningMatVec( skinningMat );
#endif
// Calculate normal
#ifdef _F01_Skinning
vec3 _normal = normalize( calcWorldVec( skinVec( normal, skinningMatVec ) ) );
#else
vec3 _normal = normalize( calcWorldVec( normal ) );
#endif
// Calculate tangent and bitangent
#ifdef _F02_NormalMapping
#ifdef _F01_Skinning
vec3 _tangent = normalize( calcWorldVec( skinVec( tangent.xyz, skinningMatVec ) ) );
#else
vec3 _tangent = normalize( calcWorldVec( tangent.xyz ) );
#endif
vec3 _bitangent = cross( _normal, _tangent ) * tangent.w;
tsbMat = calcTanToWorldMat( _tangent, _bitangent, _normal );
#else
tsbNormal = _normal;
#endif
// Calculate world space position
#ifdef _F01_Skinning
pos = calcWorldPos( skinPos( vec4( vertPos, 1.0 ), skinningMat ) );
#else
pos = calcWorldPos( vec4( vertPos, 1.0 ) );
#endif
vsPos = calcViewPos( pos );
// Calculate tangent space eye vector
#ifdef _F03_ParallaxMapping
eyeTS = calcTanVec( viewerPos - pos.xyz, _tangent, _bitangent, _normal );
#endif
// Calculate texture coordinates and clip space position
texCoords = texCoords0;
gl_Position = viewProjMat * pos;
}
[[FS_ATTRIBPASS]]
// =================================================================================================
#ifdef _F03_ParallaxMapping
#define _F02_NormalMapping
#endif
#include "shaders/utilityLib/fragDeferredWrite.glsl"
uniform vec3 viewerPos;
uniform vec4 matDiffuseCol;
uniform vec4 matSpecParams;
uniform sampler2D albedoMap;
#ifdef _F02_NormalMapping
uniform sampler2D normalMap;
#endif
varying vec4 pos;
varying vec2 texCoords;
#ifdef _F02_NormalMapping
varying mat3 tsbMat;
#else
varying vec3 tsbNormal;
#endif
#ifdef _F03_ParallaxMapping
varying vec3 eyeTS;
#endif
void main( void )
{
vec3 newCoords = vec3( texCoords, 0 );
#ifdef _F03_ParallaxMapping
const float plxScale = 0.03;
const float plxBias = -0.015;
// Iterative parallax mapping
vec3 eye = normalize( eyeTS );
for( int i = 0; i < 4; ++i )
{
vec4 nmap = texture2D( normalMap, newCoords.st * vec2( 1, -1 ) );
float height = nmap.a * plxScale + plxBias;
newCoords += (height - newCoords.p) * nmap.z * eye;
}
#endif
// Flip texture vertically to match the GL coordinate system
newCoords.t *= -1.0;
vec4 albedo = texture2D( albedoMap, newCoords.st ) * matDiffuseCol;
#ifdef _F05_AlphaTest
if( albedo.a < 0.01 ) discard;
#endif
#ifdef _F02_NormalMapping
vec3 normalMap = texture2D( normalMap, newCoords.st ).rgb * 2.0 - 1.0;
vec3 normal = tsbMat * normalMap;
#else
vec3 normal = tsbNormal;
#endif
vec3 newPos = pos.xyz;
#ifdef _F03_ParallaxMapping
newPos += vec3( 0.0, newCoords.p, 0.0 );
#endif
setMatID( 1.0 );
setPos( newPos - viewerPos );
setNormal( normalize( normal ) );
setAlbedo( albedo.rgb );
setSpecParams( matSpecParams.rgb, matSpecParams.a );
}
[[FS_ATTRIBPASS_GL4]]
// =================================================================================================
#ifdef _F03_ParallaxMapping
#define _F02_NormalMapping
#endif
#include "shaders/utilityLib/fragDeferredWriteGL4.glsl"
uniform vec3 viewerPos;
uniform vec4 matDiffuseCol;
uniform vec4 matSpecParams;
uniform sampler2D albedoMap;
#ifdef _F02_NormalMapping
uniform sampler2D normalMap;
#endif
in vec4 pos;
in vec2 texCoords;
#ifdef _F02_NormalMapping
in mat3 tsbMat;
#else
in vec3 tsbNormal;
#endif
#ifdef _F03_ParallaxMapping
in vec3 eyeTS;
#endif
void main( void )
{
vec3 newCoords = vec3( texCoords, 0 );
#ifdef _F03_ParallaxMapping
const float plxScale = 0.03;
const float plxBias = -0.015;
// Iterative parallax mapping
vec3 eye = normalize( eyeTS );
for( int i = 0; i < 4; ++i )
{
vec4 nmap = texture( normalMap, newCoords.st * vec2( 1, -1 ) );
float height = nmap.a * plxScale + plxBias;
newCoords += (height - newCoords.p) * nmap.z * eye;
}
#endif
// Flip texture vertically to match the GL coordinate system
newCoords.t *= -1.0;
vec4 albedo = texture( albedoMap, newCoords.st ) * matDiffuseCol;
#ifdef _F05_AlphaTest
if( albedo.a < 0.01 ) discard;
#endif
#ifdef _F02_NormalMapping
vec3 normalMap = texture( normalMap, newCoords.st ).rgb * 2.0 - 1.0;
vec3 normal = tsbMat * normalMap;
#else
vec3 normal = tsbNormal;
#endif
vec3 newPos = pos.xyz;
#ifdef _F03_ParallaxMapping
newPos += vec3( 0.0, newCoords.p, 0.0 );
#endif
setMatID( 1.0 );
setPos( newPos - viewerPos );
setNormal( normalize( normal ) );
setAlbedo( albedo.rgb );
setSpecParams( matSpecParams.rgb, matSpecParams.a );
}
[[VS_SHADOWMAP]]
// =================================================================================================
#include "shaders/utilityLib/vertCommon.glsl"
#include "shaders/utilityLib/vertSkinning.glsl"
uniform mat4 viewProjMat;
uniform vec4 lightPos;
attribute vec3 vertPos;
varying vec3 lightVec;
#ifdef _F05_AlphaTest
attribute vec2 texCoords0;
varying vec2 texCoords;
#endif
void main( void )
{
#ifdef _F01_Skinning
vec4 pos = calcWorldPos( skinPos( vec4( vertPos, 1.0 ) ) );
#else
vec4 pos = calcWorldPos( vec4( vertPos, 1.0 ) );
#endif
#ifdef _F05_AlphaTest
texCoords = texCoords0;
#endif
lightVec = lightPos.xyz - pos.xyz;
gl_Position = viewProjMat * pos;
}
[[VS_SHADOWMAP_GL4]]
// =================================================================================================
#include "shaders/utilityLib/vertCommon.glsl"
#include "shaders/utilityLib/vertSkinningGL4.glsl"
uniform mat4 viewProjMat;
uniform vec4 lightPos;
layout( location = 0 ) in vec3 vertPos;
out vec3 lightVec;
#ifdef _F05_AlphaTest
layout( location = 5 ) in vec2 texCoords0;
out vec2 texCoords;
#endif
void main( void )
{
#ifdef _F01_Skinning
vec4 pos = calcWorldPos( skinPos( vec4( vertPos, 1.0 ) ) );
#else
vec4 pos = calcWorldPos( vec4( vertPos, 1.0 ) );
#endif
#ifdef _F05_AlphaTest
texCoords = texCoords0;
#endif
lightVec = lightPos.xyz - pos.xyz;
gl_Position = viewProjMat * pos;
}
[[FS_SHADOWMAP]]
// =================================================================================================
uniform vec4 lightPos;
uniform float shadowBias;
varying vec3 lightVec;
#ifdef _F05_AlphaTest
uniform vec4 matDiffuseCol;
uniform sampler2D albedoMap;
varying vec2 texCoords;
#endif
void main( void )
{
#ifdef _F05_AlphaTest
vec4 albedo = texture2D( albedoMap, texCoords * vec2( 1, -1 ) ) * matDiffuseCol;
if( albedo.a < 0.01 ) discard;
#endif
float dist = length( lightVec ) / lightPos.w;
gl_FragDepth = dist + shadowBias;
// Clearly better bias but requires SM 3.0
//gl_FragDepth = dist + abs( dFdx( dist ) ) + abs( dFdy( dist ) ) + shadowBias;
}
[[FS_SHADOWMAP_GL4]]
// =================================================================================================
uniform vec4 lightPos;
uniform float shadowBias;
in vec3 lightVec;
#ifdef _F05_AlphaTest
uniform vec4 matDiffuseCol;
uniform sampler2D albedoMap;
in vec2 texCoords;
#endif
void main( void )
{
#ifdef _F05_AlphaTest
vec4 albedo = texture( albedoMap, texCoords * vec2( 1, -1 ) ) * matDiffuseCol;
if( albedo.a < 0.01 ) discard;
#endif
float dist = length( lightVec ) / lightPos.w;
// gl_FragDepth = dist + shadowBias;
// Clearly better bias but requires SM 3.0
gl_FragDepth = dist + abs( dFdx( dist ) ) + abs( dFdy( dist ) ) + shadowBias;
}
[[FS_LIGHTING]]
// =================================================================================================
#ifdef _F03_ParallaxMapping
#define _F02_NormalMapping
#endif
#include "shaders/utilityLib/fragLighting.glsl"
uniform vec4 matDiffuseCol;
uniform vec4 matSpecParams;
uniform sampler2D albedoMap;
#ifdef _F02_NormalMapping
uniform sampler2D normalMap;
#endif
varying vec4 pos, vsPos;
varying vec2 texCoords;
#ifdef _F02_NormalMapping
varying mat3 tsbMat;
#else
varying vec3 tsbNormal;
#endif
#ifdef _F03_ParallaxMapping
varying vec3 eyeTS;
#endif
void main( void )
{
vec3 newCoords = vec3( texCoords, 0 );
#ifdef _F03_ParallaxMapping
const float plxScale = 0.03;
const float plxBias = -0.015;
// Iterative parallax mapping
vec3 eye = normalize( eyeTS );
for( int i = 0; i < 4; ++i )
{
vec4 nmap = texture2D( normalMap, newCoords.st * vec2( 1, -1 ) );
float height = nmap.a * plxScale + plxBias;
newCoords += (height - newCoords.p) * nmap.z * eye;
}
#endif
// Flip texture vertically to match the GL coordinate system
newCoords.t *= -1.0;
vec4 albedo = texture2D( albedoMap, newCoords.st ) * matDiffuseCol;
#ifdef _F05_AlphaTest
if( albedo.a < 0.01 ) discard;
#endif
#ifdef _F02_NormalMapping
vec3 normalMap = texture2D( normalMap, newCoords.st ).rgb * 2.0 - 1.0;
vec3 normal = tsbMat * normalMap;
#else
vec3 normal = tsbNormal;
#endif
vec3 newPos = pos.xyz;
#ifdef _F03_ParallaxMapping
newPos += vec3( 0.0, newCoords.p, 0.0 );
#endif
gl_FragColor.rgb =
calcPhongSpotLight( newPos, normalize( normal ), albedo.rgb, matSpecParams.rgb,
matSpecParams.a, -vsPos.z, 0.3 );
}
[[FS_LIGHTING_GL4]]
// =================================================================================================
#ifdef _F03_ParallaxMapping
#define _F02_NormalMapping
#endif
#include "shaders/utilityLib/fragLightingGL4.glsl"
uniform vec4 matDiffuseCol;
uniform vec4 matSpecParams;
uniform vec4 matLightDirectionParams;
uniform sampler2D albedoMap;
#ifdef _F02_NormalMapping
uniform sampler2D normalMap;
#endif
in vec4 pos, vsPos;
in vec2 texCoords;
#ifdef _F02_NormalMapping
in mat3 tsbMat;
#else
in vec3 tsbNormal;
#endif
#ifdef _F03_ParallaxMapping
in vec3 eyeTS;
#endif
out vec4 fragColor;
void main( void )
{
vec3 newCoords = vec3( texCoords, 0 );
#ifdef _F03_ParallaxMapping
const float plxScale = 0.03;
const float plxBias = -0.015;
// Iterative parallax mapping
vec3 eye = normalize( eyeTS );
for( int i = 0; i < 4; ++i )
{
vec4 nmap = texture( normalMap, newCoords.st * vec2( 1, -1 ) );
float height = nmap.a * plxScale + plxBias;
newCoords += (height - newCoords.p) * nmap.z * eye;
}
#endif
// Flip texture vertically to match the GL coordinate system
newCoords.t *= -1.0;
vec4 albedo = texture( albedoMap, newCoords.st ) * matDiffuseCol;
#ifdef _F05_AlphaTest
if( albedo.a < 0.01 ) discard;
#endif
#ifdef _F02_NormalMapping
vec3 normalMap = texture( normalMap, newCoords.st ).rgb * 2.0 - 1.0;
vec3 normal = tsbMat * normalMap;
#else
vec3 normal = tsbNormal;
#endif
vec3 newPos = pos.xyz;
#ifdef _F03_ParallaxMapping
newPos += vec3( 0.0, newCoords.p, 0.0 );
#endif
fragColor.rgb = calcPhongSpotLight( newPos, normalize( normal ),
albedo.rgb, matSpecParams.rgb,
matSpecParams.a, -vsPos.z, 0.3 );
}
[[FS_AMBIENT]]
// =================================================================================================
#ifdef _F03_ParallaxMapping
#define _F02_NormalMapping
#endif
#include "shaders/utilityLib/fragLighting.glsl"
uniform sampler2D albedoMap;
uniform samplerCube ambientMap;
#ifdef _F02_NormalMapping
uniform sampler2D normalMap;
#endif
#ifdef _F04_EnvMapping
uniform samplerCube envMap;
#endif
varying vec4 pos;
varying vec2 texCoords;
#ifdef _F02_NormalMapping
varying mat3 tsbMat;
#else
varying vec3 tsbNormal;
#endif
#ifdef _F03_ParallaxMapping
varying vec3 eyeTS;
#endif
void main( void )
{
vec3 newCoords = vec3( texCoords, 0 );
#ifdef _F03_ParallaxMapping
const float plxScale = 0.03;
const float plxBias = -0.015;
// Iterative parallax mapping
vec3 eye = normalize( eyeTS );
for( int i = 0; i < 4; ++i )
{
vec4 nmap = texture2D( normalMap, newCoords.st * vec2( 1, -1 ) );
float height = nmap.a * plxScale + plxBias;
newCoords += (height - newCoords.p) * nmap.z * eye;
}
#endif
// Flip texture vertically to match the GL coordinate system
newCoords.t *= -1.0;
vec4 albedo = texture2D( albedoMap, newCoords.st );
#ifdef _F05_AlphaTest
if( albedo.a < 0.01 ) discard;
#endif
#ifdef _F02_NormalMapping
vec3 normalMap = texture2D( normalMap, newCoords.st ).rgb * 2.0 - 1.0;
vec3 normal = tsbMat * normalMap;
#else
vec3 normal = tsbNormal;
#endif
gl_FragColor.rgb = albedo.rgb * textureCube( ambientMap, normal ).rgb;
#ifdef _F04_EnvMapping
vec3 refl = textureCube( envMap, reflect( pos.xyz - viewerPos, normalize( normal ) ) ).rgb;
gl_FragColor.rgb = refl * 1.5;
#endif
}
[[FS_AMBIENT_GL4]]
// =================================================================================================
#ifdef _F03_ParallaxMapping
#define _F02_NormalMapping
#endif
#include "shaders/utilityLib/fragLightingGL4.glsl"
uniform sampler2D albedoMap;
uniform samplerCube ambientMap;
#ifdef _F02_NormalMapping
uniform sampler2D normalMap;
#endif
#ifdef _F04_EnvMapping
uniform samplerCube envMap;
#endif
in vec4 pos;
in vec2 texCoords;
#ifdef _F02_NormalMapping
in mat3 tsbMat;
#else
in vec3 tsbNormal;
#endif
#ifdef _F03_ParallaxMapping
in vec3 eyeTS;
#endif
out vec4 fragColor;
void main( void )
{
vec3 newCoords = vec3( texCoords, 0 );
#ifdef _F03_ParallaxMapping
const float plxScale = 0.03;
const float plxBias = -0.015;
// Iterative parallax mapping
vec3 eye = normalize( eyeTS );
for( int i = 0; i < 4; ++i )
{
vec4 nmap = texture( normalMap, newCoords.st * vec2( 1, -1 ) );
float height = nmap.a * plxScale + plxBias;
newCoords += (height - newCoords.p) * nmap.z * eye;
}
#endif
// Flip texture vertically to match the GL coordinate system
newCoords.t *= -1.0;
vec4 albedo = texture( albedoMap, newCoords.st );
#ifdef _F05_AlphaTest
if( albedo.a < 0.01 ) discard;
#endif
#ifdef _F02_NormalMapping
vec3 normalMap = texture( normalMap, newCoords.st ).rgb * 2.0 - 1.0;
vec3 normal = tsbMat * normalMap;
#else
vec3 normal = tsbNormal;
#endif
fragColor.rgb = albedo.rgb * texture( ambientMap, normal ).rgb;
#ifdef _F04_EnvMapping
vec3 refl = texture( envMap, reflect( pos.xyz - viewerPos, normalize( normal ) ) ).rgb;
fragColor.rgb = refl * 1.5;
#endif
}

BIN
assets/short04_diffuse.png View File

Before After
Width: 1024  |  Height: 1025  |  Size: 770 KiB Width: 2048  |  Height: 2048  |  Size: 2.7 MiB

BIN
references/gaf+03.pdf View File


+ 11
- 14
src/Main.cpp View File

@ -309,20 +309,17 @@ int main()
// Terrain
{
createCollisionHeightfield(physicsWorld,
glm::vec3(-17.f, -30.f, 250.f + ((20.f * 5.f) * 0.f)));
createCollisionHeightfield(physicsWorld,
glm::vec3(-17.f, -30.f, 250.f + ((20.f * 5.f) * 1.f)));
createCollisionHeightfield(physicsWorld,
glm::vec3(-17.f, -30.f, 250.f + ((20.f * 5.f) * 2.f)));
createCollisionHeightfield(physicsWorld,
glm::vec3(-17.f, -30.f, 250.f + ((20.f * 5.f) * 3.f)));
createCollisionHeightfield(physicsWorld,
glm::vec3(-17.f, -30.f, 250.f + ((20.f * 5.f) * 4.f)));
createCollisionHeightfield(physicsWorld,
glm::vec3(-17.f, -30.f, 250.f + ((20.f * 5.f) * 5.f)));
createCollisionHeightfield(physicsWorld,
glm::vec3(-17.f, -30.f, 250.f + ((20.f * 5.f) * 6.f)));
const float scalingFactor = 20.f * 5.f;
// In this case nothing will be faster going z first, but it's a good habit to have
for (int z = 0; z < 10; ++z)
{
for (int x = 0; x < 10; ++x)
{
createCollisionHeightfield(
physicsWorld,
glm::vec3(-17.f + (scalingFactor * x), -30.f, 250.f + (scalingFactor * z)));
}
}
}
// objTest();


+ 6
- 1
src/Terrain.cpp View File

@ -109,7 +109,12 @@ void createCollisionHeightfield(PhysicsWorld& world, const glm::vec3& worldPosit
{
for (int cellX = 0; cellX < g_TerrainGridSize; cellX++)
{
float noiseScale = 0.7f;
// float noiseScale = 0.7f; // Tricky hills
float noiseScale = 0.5f; // Go fast hills
// Close to flat, with some nice slopes. Hard to get off the ground at all
// float noiseScale = 0.2f;
// float noiseScale = 1.0f; // Very technical hills
// float noiseScale = 0.6f; // Medium hills
float noiseX = (cellX + xNoiseSpaceOffset) * noiseScale;
float noiseZ = (cellZ + zNoiseSpaceOffset) * noiseScale;


Loading…
Cancel
Save