Normal Mapped Terrains
by Matt Vitelli · in Torque Game Engine Advanced · 12/08/2006 (3:15 pm) · 58 replies
This is from some work I've done with normal mapping and terrains. Enjoy!




#2
Please share :D
Regards,
Dreamer
12/08/2006 (4:20 pm)
Oh wow, I've been trying for weeks to get something like that going, care to share some code on how that was achieved? Best I've been able to do is get a buggy implementation of detail textures going and even thats still not quite right :(Please share :D
Regards,
Dreamer
#3
12/08/2006 (4:33 pm)
I might submit it as a resource soon.
#5
12/08/2006 (4:42 pm)
It's legacy terrain, but I might add this to Atlas.
#6
12/08/2006 (10:55 pm)
Cool stuff Matt, have any desire to send me the code? I'd love to integrate this into a side project I'm working on just for kicks. :)
#7
12/09/2006 (5:32 am)
I'd be more than happy to send you the code.
#8
12/09/2006 (10:23 am)
Thanks! My email's tima@garagegames.com :)
#9
smorrey@gmail.com
Regards,
Dreamer
12/09/2006 (10:40 am)
Oh hey can I get a copy of that too please, I'm dying to see how this works.smorrey@gmail.com
Regards,
Dreamer
#10
12/10/2006 (8:33 pm)
The emails have been sent. Be sure to keep me updated. :)
#12
12/12/2006 (6:17 pm)
Looks fantastic. If your still sending out copies of it I would love a copy as well. I've been trying to get normal mapped terrrain in TSE, but unable to get it working. Even though this is for legacy, would likely help figure out what the problem is. email: erasmushurt2002@yahoo.com.
#13
12/25/2006 (6:14 pm)
Same here. We are currently using TSE, but trying to achieve even mildly detailed terrain is a nightmare. Would you be so kind to email info to: addictive@ihug.co.nz
#14
12/27/2006 (7:53 pm)
As with me, dion@simpleblack.com thanks!
#15
Any chance of getting the code also?
Dennis@thetrollcave.com
Thanks!
12/28/2006 (8:31 am)
Looks great!Any chance of getting the code also?
Dennis@thetrollcave.com
Thanks!
#16
TerrainV
12/28/2006 (8:38 am)
TerrainP//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
#define IN_HLSL
#include "../shdrConsts.h"
struct ConnectData
{
float2 texCoord : TEXCOORD0;
float2 fogCoord : TEXCOORD1;
float2 lightMapCoord : TEXCOORD2;
float2 detCoord : TEXCOORD3;
float2 bumpCoord : TEXCOORD4;
float3 eye : TEXCOORD5;
float3 light : TEXCOORD6;
};
struct Fragout
{
float4 col : COLOR0;
};
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
Fragout main( ConnectData IN,
uniform sampler2D diffuseMap : register(S0),
uniform sampler2D fogMap : register(S1),
uniform sampler2D lightMap : register(S2),
uniform sampler2D detailMap : register(S3),
uniform sampler2D bumpMap : register(S4),
uniform float4 ambient : register(PC_AMBIENT_COLOR),
uniform float4 specular : register(PC_MAT_SPECCOLOR),
uniform float shine : register(PC_MAT_SPECPOWER)
)
{
Fragout OUT;
const float3 diffuse = {1,1,1};
float2 uv = IN.bumpCoord;
// view and light directions
float3 v = normalize(IN.eye);
float3 l = normalize(IN.light);
float4 diffuseColor = tex2D(diffuseMap, IN.texCoord);
diffuseColor *= tex2D(lightMap, IN.lightMapCoord) * 4.0;
float4 lm = tex2D(lightMap, IN.lightMapCoord);
float4 fogColor = tex2D(fogMap, IN.fogCoord);
float4 detailColor = tex2D(detailMap, IN.detCoord);
float4 normal=tex2D(bumpMap,uv);
normal.xyz=normalize(normal.xyz-0.5);
normal.y=-normal.y;
float height = tex2D(bumpMap,uv).w * 0.06 - 0.03;
uv += height * v.xy;
float diff=saturate(dot(l,normal.xyz));
float spec=saturate(dot(normalize(l-v),normal.xyz));
OUT.col = lerp( diffuseColor * (detailColor) * (diff), fogColor, fogColor.a );
return OUT;
}TerrainV
#define IN_HLSL
#include "../shdrConsts.h"
//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
struct VertData
{
float2 texCoord : TEXCOORD0;
float4 position : POSITION;
float3 tangent : TEXCOORD2;
float3 binormal : TEXCOORD3;
float3 N : TEXCOORD4;
float3 normal : NORMAL;
};
struct ConnectData
{
float4 hpos : POSITION;
float2 texCoord : TEXCOORD0;
float2 fogCoord : TEXCOORD1;
float2 lightMapCoord : TEXCOORD2;
float2 detCoords : TEXCOORD3;
float2 bumpCoord : TEXCOORD4;
float3 light : TEXCOORD6;
float3 eye : TEXCOORD5;
};
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
ConnectData main( VertData IN,
uniform float4x4 modelview : register(C0),
uniform float3 eyePos : register(VC_EYE_POS),
uniform float3 fogData : register(VC_FOGDATA),
uniform float1 terrainsize : register(C54),
uniform float4x4 texMat : register(VC_TEX_TRANS1),
uniform float3 lightpos : register(VC_LIGHT_DIR1),
uniform float4x4 objTrans : register(VC_OBJ_TRANS)
)
{
ConnectData OUT;
float4 pos=float4(IN.position.x,IN.position.y,IN.position.z,1.0);
OUT.hpos=mul(modelview, pos);
OUT.texCoord = IN.texCoord;
OUT.lightMapCoord = IN.position * terrainsize.x;
OUT.fogCoord.x = 1.0 - ( distance( IN.position, eyePos ) / fogData.z );
OUT.fogCoord.y = (IN.position.z - fogData.x) * fogData.y;
OUT.detCoords = IN.position.xy / 2;
OUT.bumpCoord = IN.position.xy / 2;
float3x3 tangentspace=float3x3(IN.tangent,IN.binormal,IN.normal);
// vertex position in view space (with model transformations)
float3 vpos=mul(modelview, pos).xyz;
// view in tangent space
float3 objectspace_view_vector = mul( IN.texCoord, eyePos ) - IN.position;
OUT.eye = mul( tangentspace, objectspace_view_vector );
OUT.eye = - OUT.eye;
OUT.light.xyz = -lightpos;
OUT.light.xyz = mul(tangentspace, OUT.light);
OUT.light = OUT.light / 2.0 + 0.5;
return OUT;
}
#17
12/28/2006 (8:39 am)
This is based off some of Ray G's shaders.
#18
01/12/2007 (6:11 am)
Does this work for Atlas, or just the Legacy Terrain?
#19
01/12/2007 (6:20 am)
It only works with legacy. Getting something like this working in Atlas would be fairly easy.
#20
01/12/2007 (5:27 pm)
I've tried to get it working with Atlas, and with the old system in place for atlas, it woudl have been very easy. With Atlas 2 though it's quite a bit different. Adding it into the shader doesn't work. There is a hole in Atlas2 for doing things like this so we tried to plug a shader in through there but could never get it working properly. If anyone figures out how to get that going on Atlas 2 terrain please share a general overview of how you got it going if you would. We've had several people take stabs at it to no avail. I finally just gave up on getting it working, figuring I'll wait on the 4.2 release and start again if there are any atlas changes.
Torque 3D Owner James Bond