Advertisement

Parallax mapping...

Started by June 28, 2004 05:27 AM
11 comments, last by RipTorn 20 years, 5 months ago
@darkwing: I got those textures from this page.
Sure they are low-res and jpeg-compressed, but I'm pretty sure I cannot create better ones by myself.
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
the radeon chips support displacement mapping in hardware, but I think geforce fx's fall back to a software implementation - but I'm not sure on this.

last year I posted in the forums what I was trying, it was effecitvly paralax-mapping (which became popular about a month later :) mixied with layers.. my hardware was limited to only 5 layers though.. and it wasn't enormously quick..

link

so it can be done, but I didn't feel it was worth it.


I never got round to explaining it because I was very busy and, as I said, simple parallax became extremly popular about one month later when someone posted it on opengl.org...

I might be able to find the shaders however...
Advertisement
ok I found the shaders...

this should show how close to my cards limits I was ;)

(Cg)

vertex shader
struct input{    float4 position			: POSITION;    float3 normal			: NORMAL;	float4 tangent			: TEXCOORD0;	float2 tex			: TEXCOORD1;};struct output{	float4	position		: POSITION;	float4	texCoords		: TEXCOORD0;	float3	lightVector		: TEXCOORD1;	float3	viewVector		: TEXCOORD2;	float2	projectTexCoord1	: TEXCOORD3;	float2	projectTexCoord2	: TEXCOORD4;	float2	projectTexCoord3	: TEXCOORD5;	float2	projectTexCoord4	: TEXCOORD6;	float2	projectTexCoord5	: TEXCOORD7;};output main(input IN,            uniform float4x4 ModelViewProj,            uniform float4x4 ModelView,            uniform float4x4 ModelViewINV,            uniform float4	lightPos,	            uniform float4	viewPos,	            uniform float	lightFalloffINV,	    uniform float	TIME){    output OUT;	OUT.lightVector		= (lightPos - IN.position) * lightFalloffINV;	OUT.viewVector		= (IN.position - viewPos) ;   	OUT.position		= mul(ModelViewProj, IN.position);	float3 tangent2		= cross(IN.tangent.xyz,IN.normal)*IN.tangent.w;	float3x3 tangent	= {IN.tangent.xyz,tangent2,IN.normal};	float3 normal		= mul(ModelView,float4(IN.normal,0)).xyz;	float3 direction	= normalize(mul(ModelView,IN.position).xyz);	float3 delta		= direction*0.05f / dot(normal,direction);	delta			= mul(ModelViewINV,float4(delta,0));	float2	texCoordDelta	= mul(tangent,delta).xy;	OUT.projectTexCoord1	= IN.tex + texCoordDelta*0.2;	OUT.projectTexCoord2	= IN.tex + texCoordDelta*0.4;	OUT.projectTexCoord3	= IN.tex + texCoordDelta*0.6;	OUT.projectTexCoord4	= IN.tex + texCoordDelta*0.8;	OUT.projectTexCoord5	= IN.tex + texCoordDelta;	OUT.lightVector		= mul(tangent,OUT.lightVector);	OUT.viewVector		= mul(tangent,OUT.viewVector);		OUT.texCoords		= float4(IN.tex,texCoordDelta);    return OUT;}


pixie shader
half4 main(	half4 texCoords			: TEXCOORD0,            	half3 lightVector		: TEXCOORD1,		half3 viewVector		: TEXCOORD2,		float2	projectTexCoord1	: TEXCOORD3,		float2	projectTexCoord2	: TEXCOORD4,		float2	projectTexCoord3	: TEXCOORD5,		float2	projectTexCoord4	: TEXCOORD6,		float2	projectTexCoord5	: TEXCOORD7,                        	uniform float4 lightColour,            	uniform float specularPower,                        	uniform sampler2D texture	: TEXUNIT0,            	uniform sampler2D bumpTexture	: TEXUNIT1): COLOR{	float bumpLevel1		= tex2D(bumpTexture, texCoords.xy).a;	bumpLevel1 = clamp(bumpLevel1,0.0,0.167);	float bumpLevel2		= tex2D(bumpTexture, projectTexCoord1).a;	float bumpLevel2Sat=saturate((bumpLevel2-0.167)*6);	float bumpLevel3		= tex2D(bumpTexture, projectTexCoord2).a;	float bumpLevel3Sat=saturate((bumpLevel3-0.333)*6);	float bumpLevel4		= tex2D(bumpTexture, projectTexCoord3).a;	float bumpLevel4Sat=saturate((bumpLevel4-0.5)*6);	float bumpLevel5		= tex2D(bumpTexture, projectTexCoord4).a;	float bumpLevel5Sat=saturate((bumpLevel5-0.667)*6);	float bumpLevel6		= tex2D(bumpTexture, projectTexCoord5).a;	float bumpLevel6Sat=saturate((bumpLevel6-0.833)*6);	float bumpLevel = bumpLevel1;	bumpLevel=bumpLevel*(1-bumpLevel2Sat)+bumpLevel2Sat *0.333;	bumpLevel=bumpLevel*(1-bumpLevel3Sat)+bumpLevel3Sat *0.5;	bumpLevel=bumpLevel*(1-bumpLevel4Sat)+bumpLevel4Sat *0.667;	bumpLevel=bumpLevel*(1-bumpLevel5Sat)+bumpLevel5Sat *0.833;	bumpLevel=bumpLevel*(1-bumpLevel6Sat)+bumpLevel6Sat;	float2 offset =bumpLevel * texCoords.zw;	float2 texCoordBump  		= texCoords +offset;    	half4 detailColour		= tex2D(texture, texCoordBump);    	half4 normal4			= tex2D(bumpTexture, texCoordBump);    	half falloff			= 1/(dot(lightVector.xyz,lightVector.xyz)+0.5)+half(lightColour.w);    	half3 normal			= normalize(normal4.xyz*2-1);        	half3 colour			= half3(lightColour.xyz)*detailColour.xyz;        	half3 lightVectorNorm		= normalize(lightVector.xyz);        	half3 reflection		= reflect(lightVectorNorm,normal); 	half specular			= dot(normalize(viewVector),reflection); 	half diffuse			= dot(normal.xyz,lightVectorNorm);		half4 result			= lit(diffuse, specular, half(specularPower)); 	half intensity			= (result.y+result.z) * falloff * saturate(4* diffuse);	return half4(colour*intensity,detailColour.w);}


yeah.

This topic is closed to new replies.

Advertisement