Moar lights for bump.fx?

Posted By: fogman

Moar lights for bump.fx? - 11/15/10 17:38

Hola,

I´m very close to the first release of :schutzkontakt.
Close means not more than a week.

I´m using the normalmapping shader bump.fx that comes with gamestudio. This shader supports up to three dynamic lights.
However, three lights are too less because the player needs a flashlight.

Currently it´s a fast hack but it works surprisingly well - except for that ugly flickering that occurs whenever there are four lights in action.

I would like to have four lights supported, this should really be enough. I´ve already tried to add a fourth light, no luck so far, as I got no shader background.
Also I don´t really get the include / default.fx stuff.
Theoretically it should be easy to add another light, but I need some entry point.

So does anyone has an idea where I could start?

Posted By: painkiller

Re: Moar lights for bump.fx? - 11/15/10 17:45

in the wiki there is a normal mapping shader which supports up to 6 lights, but I suppose it slower than bump.fx http://www.opserver.de/wiki/index.php/Normalmapping_Shader
Posted By: the_clown

Re: Moar lights for bump.fx? - 11/15/10 18:22

Hmm, this shader wont work for level blocks I guess?

EDIT: Tried. It gives me very ugly artifacts. Dunno if it's the shader or the usage for level blocks, gonna try it with models later.
Posted By: fogman

Re: Moar lights for bump.fx? - 12/30/10 11:46

Still no luck...
So - I would even pay some bucks for an enhanced version.
Posted By: RedPhoenix

Re: Moar lights for bump.fx? - 01/09/11 12:56

Code:
// Lambert bump mapping
// (c) oP group 2008  Version 2.1
//edited by redphoenix 01.11 -> supporting 4 lights on shader version 3

#include <define>
#include <transform>
#include <fog>
#include <pos>
#include <normal>
#include <tangent>
#include <lights>
#include <color>


#include <phong>

texture entSkin1;	// texture
texture entSkin2;	// normal map or lightmap
texture entSkin3;	// normal map on blocks

sampler sBaseTex = sampler_state { Texture = <entSkin1>; MipFilter = Linear;	};
sampler sSkin2 = sampler_state { Texture = <entSkin2>; MipFilter = None;	};
sampler sSkin3 = sampler_state { Texture = <entSkin3>; MipFilter = None;	};


struct bumpOut
{
	float4 Pos: POSITION;
	float  Fog:	FOG;
	//float4 Ambient:  COLOR0;
	float4 Tex12:    TEXCOORD0;	
	//float3 PosView:  TEXCOORD1;
	float3 Light1:	 TEXCOORD1;	
	float3 Light2:	 TEXCOORD2;
	float3 Light3:	 TEXCOORD3;	
	float3 Light4:	 TEXCOORD4;	
	float3 Diffuse1: TEXCOORD5;		
	float3 Diffuse2: TEXCOORD6;		
	float3 Diffuse3: TEXCOORD7;		
	float3 Diffuse4: TEXCOORD8;		
};

bumpOut bump_VS(vertexIn In)
{
	bumpOut Out;

	Out.Pos	= DoTransform(In.Pos);
	Out.Tex12 = float4(In.Tex1,In.Tex2);
	Out.Fog	= DoFog(In.Pos);
	//Out.Ambient = DoAmbient();	

	CreateTangents(In.Normal,In.Tangent);
   float3 PosWorld = DoPos(In.Pos).xyz;
	//Out.PosView = DoTangent(vecViewPos-PosWorld);
	Out.Light1 = DoTangent(vecLightPos[0].xyz-PosWorld);
	Out.Light2 = DoTangent(vecLightPos[1].xyz-PosWorld);
	Out.Light3 = DoTangent(vecLightPos[2].xyz-PosWorld);
	Out.Light4 = DoTangent(vecLightPos[3].xyz-PosWorld);
	
  float3 Normal = DoNormal(In.Normal);
	Out.Diffuse1 = DoLightFactorBump(vecLightPos[0],PosWorld,Normal) * vecLightColor[0].xyz;
	Out.Diffuse2 = DoLightFactorBump(vecLightPos[1],PosWorld,Normal) * vecLightColor[1].xyz;
	Out.Diffuse3 = DoLightFactorBump(vecLightPos[2],PosWorld,Normal) * vecLightColor[2].xyz;
	Out.Diffuse4 = DoLightFactorBump(vecLightPos[3],PosWorld,Normal) * vecLightColor[3].xyz;
	
	return Out;		
}

float3 DoDiffuse(bumpOut In,float3 Normal)
{
	float3 Diffuse = In.Diffuse1 * saturate(dot(normalize(In.Light1.xyz),Normal));
	Diffuse += In.Diffuse2 * saturate(dot(normalize(In.Light2.xyz),Normal));
	Diffuse += In.Diffuse3 * saturate(dot(normalize(In.Light3.xyz),Normal));
	Diffuse += In.Diffuse4 * saturate(dot(normalize(In.Light4.xyz),Normal));
	return Diffuse * vecDiffuse.xyz;
}

float4 diffuseBump_PS(bumpOut In): COLOR
{
	float4 myambient = (vecAmbient * vecLight) + float4(vecEmissive.xyz*vecColor.xyz,vecLight.w);
	float4 Base = tex2D(sBaseTex,In.Tex12.xy);
	float3 Normalmap = tex2D(sSkin2,In.Tex12.xy).rgb*2-1;
   float3 Diffuse = DoDiffuse(In,Normalmap);	
	return Base * DoColor(Diffuse,myambient);
}

float4 diffuseBumpLM_PS(bumpOut In): COLOR
{
	float4 myambient = (vecAmbient * vecLight) + float4(vecEmissive.xyz*vecColor.xyz,vecLight.w);
	float4 Base = tex2D(sBaseTex,In.Tex12.xy);
	float4 Lightmap = tex2D(sSkin2,In.Tex12.zw);
	float3 Normalmap = tex2D(sSkin3,In.Tex12.xy).rgb*2-1;
   float3 Diffuse = DoDiffuse(In,Normalmap);	
	return Base * DoLightmap(Diffuse,Lightmap,myambient);
}

technique bump
{
	pass one
	{		
		VertexShader = compile vs_3_0 bump_VS();
		PixelShader = compile ps_3_0 diffuseBump_PS();
	}
}

technique bump_lm
{
	pass one
	{		
		VertexShader = compile vs_3_0 bump_VS();
		PixelShader = compile ps_3_0 diffuseBumpLM_PS();
	}
}

technique fallback { pass one { } }


Posted By: fogman

Re: Moar lights for bump.fx? - 01/09/11 17:56

Thank you very much again.
© 2024 lite-C Forums