Game Development Community

TSE Relief Mapping?

by Tim Betts · in Torque Game Engine Advanced · 11/02/2005 (10:37 am) · 156 replies

Hey shader junkies, so, we've had bump maps, normal maps, then parallax mapping, so what about the next challenge - relief mapping ? anyone even attempted to get this puppy working on TSE? Now I'm no shader programmer unfortunately, but it would look like that this approach (http://fabio.policarpo.nom.br/relief/index.htm) will yield far more accurate mapping than parallax mapping. Very exciting work. Any guru's willing to step up :) ?

Cheers -- Tim.
#101
06/15/2007 (11:31 am)
I didn't think the "translucent" flag was available for a CustomMaterial. It's not listed in the TDN documentation for it, anyway. Experimentation will tell.
#102
06/15/2007 (11:34 am)
Some of the custom water materials use it, so it does work.
#103
06/21/2007 (7:54 am)
So what color in the hightmap is an unaffected surface? white, black, or 50% grey?
#104
06/24/2007 (8:04 pm)
Technically I don't think any part of the heightmap is unaffected. However, 50% gray should probably be a good neutral spot.
#105
08/10/2007 (11:13 am)
Ok, so after a bit of testing I was able to get this down to a shader model 2.0 limit. The instruction count comes in at a startling 64 instructions. Just 1 instruction away from being shader model 3.0. I essentially ripped out the for arguments and offloaded the linear and binary searches to separate functions. These functions were called as much as possible to get the quality as high as could possibly be on the hardware setting. Because of the instruction limit, I had to strip out specular exponents and probably a lot that would make the overall scene look better. If you want to add these things in, be my guest. Just be sure to lower the binary and linear steps if you plan on doing so. ;)

i63.photobucket.com/albums/h138/eternaldark112/reliefmapping2-1.png
ReliefP
//Copyright 2007 Matt Vitelli
#define IN_HLSL
#include "shdrConsts.h"

struct v2f
{
	float4 hpos     : POSITION;
	float3 eye      : TEXCOORD0;
	float3 light    : TEXCOORD1;
	float2 texcoord : TEXCOORD2;
};
float3 getLinearStepVal(
	in float4 t,
	in float3 s,
	in float3 ds
)
{

if (s.z<t.w)
s+=ds;

return s;
}

float3 getBinaryStepVal(
	in float4 t,
	in float3 s,
	in float3 ds
)
{
ds*=0.5;
		if (s.z<t.w)
			s+=2*ds;
		s-=ds;

return s;
}
// use linear and binary search
float3 ray_intersect_rm(
      in float4 t,
      in float3 s, 
      in float3 ds)
{
  
   ds/=5;
   float3 linVal1 = getLinearStepVal(t,s,ds);
   float3 linVal2 = getLinearStepVal(t,linVal1,ds);
   float3 linVal3 = getLinearStepVal(t,linVal2,ds);
   float3 linVal4 = getLinearStepVal(t,linVal3,ds);
   float3 linVal5 = getLinearStepVal(t,linVal4,ds);
   float3 binVal1 = getBinaryStepVal(t,linVal5,ds);
   float3 binVal2 = getBinaryStepVal(t,binVal1,ds);
   float3 binVal3 = getBinaryStepVal(t,binVal2,ds);

   return binVal3;
}

float4 main(
	v2f IN,
	uniform sampler2D texmap    : register(S0),
	uniform sampler2D reliefmap : register(S1)
	) : COLOR
{
	
	// view direction
	float3 v = normalize(IN.eye);
	
	// serach start point and serach vector with depth bias
	float3 s = float3(IN.texcoord,0);
	v.xy *= 0.05*(2*v.z-v.z*v.z);
	v /= v.z;
	float4 t = tex2D(reliefmap,s);
	// ray intersect depth map
	float3 tx = ray_intersect_rm(t,s,v);

	// displace start position to intersetcion point
	s.xy += v.xy*tx.z;

	// get normal, lightmap and color at intersection point
	t = tex2D(reliefmap,tx.xy)*2-1;
	float4 c = tex2D(texmap,tx.xy);

	// light direction
	float3 l = normalize(IN.light);
	
	// view direction
	v = normalize(IN.eye);
	v.z = -v.z;

	// compute diffuse and specular terms
	float diff = saturate(dot(l,t.xyz));

	// compute final color
	float4 finalcolor;
	finalcolor.xyz = c*diff;
	finalcolor.w = 1;
        finalcolor /= 2;
	return finalcolor;
}
#106
09/27/2007 (12:06 pm)
Ok the last time i checked it was 2006 now in 2007 still no working light in parallax mapping, relief mapping and no doc's to help get you there, by what i'v seen the crew at GG know how to do it but keep it for there own projects? Refund is looking good.
#107
09/27/2007 (12:46 pm)
GG are only supplying the engine, its upto you as a developer to develop any new features :)

Agreed though, would love to see this resource updated.
#108
09/27/2007 (12:48 pm)
Well, Parallax Mapping and Relief Mapping aren't officially support by the engine. If you use standard TGEA Normal Mapping then everything works fine. If you want to implement Parallax Mapping then that's a custom feature for your game, and not something GG is "required" to support. Perhaps someone around the community here can help you out if you ask?
#109
09/27/2007 (12:54 pm)
Sorry I never updated this shader that I ported almost 2 years ago (for free), when TGEA was in beta (and it was still called TSE). If you don't like having this free shader that does something TGEA doesn't do out of the box, then don't use it. If you do like having it, it should be very easy to port to TGEA, I just don't feel like it. I haven't been using TGEA for a while, so I don't have a good reason to spend my time figuring out what is wrong. If you scroll up in this blog a bit, I think Matt Vitelli has mentioned how to make it work properly.
#110
09/27/2007 (4:33 pm)
Actually, I think it should work fine out of the box. There really have been no changes to the shader library since the TGEA switch. The only change Milestone 4/TGEA brought was the lighting and shadow shaders and variables.
#111
09/27/2007 (6:39 pm)
The Shader works fine, as it did before. Only thing it doesn't have is lighting, which was introduced later.
#112
09/27/2007 (7:22 pm)
I'm not sure I understand the problem is this not working in 1.03? I know it works in 1.02. Although yeah it could be a little better but hey it is free.

although correct me if I'm wrong but I think there has always been an issue with getting the light from torque into the custom shaders. I could be wrong on this though.
#113
09/27/2007 (8:11 pm)
OK without trying to be smart, How do you add the add the lighting system to a simple custom shader? looking forward to no reply's that have nothing to do with adding light, The Parallax shader is support by GG and should have the right information, if GG can't do it with the engine there selling then it should not be sold, if they can GG should have support information up so we can to? i look forward to no real information.
#114
09/27/2007 (8:59 pm)
David, no parallax shaders are or ever have been supported by Garage Games. To answer your question as best I can, all I can say is take a look at the Custom Material Lighting page. To be honest though, I've had a hell of a time integrating it into the parallax shader and have yet to succeed.
#115
09/27/2007 (9:41 pm)
Matt, i know no parallax shaders are or ever have been supported by Garage Games, Its lack of information which is ment to be supported, there is little to none, a few real simple shaders using the lighting system like the glitter shader. and alot of user's whould be fine? anyone can learn but its hard without the right tools?
#116
09/28/2007 (1:21 am)
Matt, what type of problems are you running into?
#117
09/28/2007 (8:17 am)
Well, after reading this post I read the documentation again and had another go at dynamic lighting with parallax mapping. I'm happy to say I got it working, so I have no problems anymore. Next I'll have a go at giving relief mapping dynamic lighting capabilities.
#118
09/28/2007 (8:23 am)
Matt care to share?
#119
09/28/2007 (8:26 am)
Or a point in the right direction?, Well done btw
#120
09/28/2007 (9:25 am)
Certainly, though keep in mind I'm new to dynamic lighting, so it's horribly unoptimized. Download here.