Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: MiniMesh lighting  (Read 1585 times)
aeon
Customers
Community Member
*****
Posts: 364


WWW
« on: December 29, 2009, 09:38:48 AM »

I don't know if this has been asked recently but I've been playing around with MiniMeshes and I can't for the life of me get them lit.  I've tried setting the lighting and material on the mesh itself before creating the MiniMesh from it.  I've tried applying a material directly to the MiniMesh yet all I get is a non-lit meshes.  As if it's locked on CONST_TV_LIGHTINGMODE.TV_LIGHTING_NONE

Has anyone else gotten lighting to work?  Does anyone have a shader that does it?
Logged

AriusEso
Customers
Community Member
*****
Posts: 940

Esoteric


« Reply #1 on: December 29, 2009, 09:53:52 AM »

I don't know if this has been asked recently but I've been playing around with MiniMeshes and I can't for the life of me get them lit.  I've tried setting the lighting and material on the mesh itself before creating the MiniMesh from it.  I've tried applying a material directly to the MiniMesh yet all I get is a non-lit meshes.  As if it's locked on CONST_TV_LIGHTINGMODE.TV_LIGHTING_NONE

Has anyone else gotten lighting to work?  Does anyone have a shader that does it?

Iirc the default lighting in TV only works with directional lighting. I assume that is what you're trying to do but thought i'd mention it incase you were using point/spot.

Unfortunately I don't have a shader to hand. But you can do any kind of lighting if you shader them, even normal mapping etc.

Also, long time no see. Welcome back Cheesy.
Logged

-...-

AriusEso
Customers
Community Member
*****
Posts: 940

Esoteric


« Reply #2 on: December 29, 2009, 10:04:59 AM »

I knew I had one somewhere. In order for this to work, you must set the lighting mode on the base mesh to tangent, add a normal map, set the colour mode on the minimesh to true and give each element a colour( can just be white ).

Code:
float4x3 World[52] : MINIMESH_WORLD;
float4x4 ViewProj  : VIEWPROJECTION;
float4   Colour[52]: MINIMESH_COLOR;
float3   cp        : VIEWPOS;
texture  colour    : TEXTURE0;
texture  bump      : TEXTURE1;

float3 LightPos;
float  Radius;

sampler2D cs = sampler_state
{
Texture   = (colour);
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};

sampler2D bs = sampler_state
{
Texture   = (bump);
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};

struct VertexIN
{
float4 Position: POSITION;
float3 t       : TANGENT;
float3 b       : BINORMAL;
float3 n       : NORMAL;
float2 UV      : TEXCOORD0;
float2 Index   : TEXCOORD3;
};

struct FragmentIN
{
float4 Position: POSITION;
float2 UV      : TEXCOORD0;
float3 LightVec: TEXCOORD1;
float3 vv      : TEXCOORD2;
float  At      : TEXCOORD3;

float4 Colour  : COLOR0;
};

float CalculateLyon(float3 VV, float3 LV, float3 NV)
{
float3 HalfWay     = normalize(VV + LV);
float3 Difference  = HalfWay - NV;
float  SS          = saturate(dot(Difference, Difference) * 60);
return pow(1 - SS, 3);
}

void VertexProgram(in VertexIN IN, out FragmentIN OUT)
{
float4x3 WorldMatrix  = World[IN.Index.x];
float3   WorldPos     = mul(IN.Position, WorldMatrix);
         OUT.Position = mul(float4(WorldPos, 1), ViewProj);
         OUT.UV       = IN.UV;
         OUT.Colour   = Colour[IN.Index.x];

float3x3 TBN          = float3x3(IN.t, IN.b, IN.n);
float3x3 WTTS         = mul(TBN, WorldMatrix);

float3   PosWorld     = mul(IN.Position, WorldMatrix);
         OUT.LightVec = mul(WTTS, (LightPos - PosWorld));
         OUT.vv       = mul(WTTS, cp - PosWorld);
         OUT.At       = distance(PosWorld, LightPos);
}

float4 FragmentProgram(in FragmentIN IN): COLOR0
{
float3 viewVec = normalize(IN.vv);
float2 nuv     = (tex2D(bs, IN.UV).a * 0.05f - (0.05f * 0.5f)) * viewVec + IN.UV;

float3  np      = 2 * tex2D(bs, nuv) - 1;
float3  ld      = normalize(IN.LightVec);
float   d       = saturate(dot(np, ld) * 0.5f + 0.5f) * clamp(1 - length(IN.At) / Radius, 0, 1);
float   s       = CalculateLyon(viewVec, ld, np);

float4  Pixel   = (d * float4(tex2D(cs, nuv).rgb, 1) + s) * IN.Colour;
return  Pixel * IN.Colour;
}

technique render
{
pass pass0
{
VertexShader     = compile vs_2_0 VertexProgram();
PixelShader      = compile ps_3_0 FragmentProgram();
}
}

I don't have one for directional lighting, so you'd have to modify it etc.

Edit: Scanning my eyes over it, looks like you might want to put a parallax/height map in the normal maps alpha channel. Might look odd if you leave it blank.
Logged

-...-

aeon
Customers
Community Member
*****
Posts: 364


WWW
« Reply #3 on: December 29, 2009, 10:18:50 AM »

I knew I had one somewhere. In order for this to work, you must set the lighting mode on the base mesh to tangent, add a normal map, set the colour mode on the minimesh to true and give each element a colour( can just be white ).

Thanks AriusEso, I'll have a try at this when I get home from work today.
Logged

AriusEso
Customers
Community Member
*****
Posts: 940

Esoteric


« Reply #4 on: December 29, 2009, 10:27:01 AM »

It's the one I used here: http://www.youtube.com/watch?v=E_NASpV5u7A

So it should pretty much just plug and play.
Logged

-...-

aeon
Customers
Community Member
*****
Posts: 364


WWW
« Reply #5 on: December 29, 2009, 03:17:26 PM »

shader worked wonderfully, my only issue is the specular highlight.  Is there a way to turn it off or remove it from the shader?  I like the normal mapping but the specular needs to go.
Logged

ZaPPZion
Moderator
Community Member
*****
Posts: 555


« Reply #6 on: December 29, 2009, 06:00:23 PM »

remove the +s from this line?
float4  Pixel   = (d * float4(tex2D(cs, nuv).rgb, 1) + s) * IN.Colour;
Logged

Check out my website: www.bartkuipers.com
aeon
Customers
Community Member
*****
Posts: 364


WWW
« Reply #7 on: December 29, 2009, 06:32:25 PM »

remove the +s from this line?
float4  Pixel   = (d * float4(tex2D(cs, nuv).rgb, 1) + s) * IN.Colour;

nope
Logged

AriusEso
Customers
Community Member
*****
Posts: 940

Esoteric


« Reply #8 on: December 30, 2009, 01:19:03 PM »

Hmm, removing the s should work. The specular is just that lyon function.

I noticed I made a slight mistake:

Code:
float4  Pixel   = (d * float4(tex2D(cs, nuv).rgb, 1) + s) * IN.Colour;
return  Pixel * IN.Colour;

Probably shouldn't be * IN.Colour on both lines. But that shouldn't effect highlights.
Logged

-...-

aeon
Customers
Community Member
*****
Posts: 364


WWW
« Reply #9 on: December 31, 2009, 11:11:31 PM »

Hmm, removing the s should work. The specular is just that lyon function.

I noticed I made a slight mistake:

Code:
float4  Pixel   = (d * float4(tex2D(cs, nuv).rgb, 1) + s) * IN.Colour;
return  Pixel * IN.Colour;

Probably shouldn't be * IN.Colour on both lines. But that shouldn't effect highlights.

Removing the + s  and the extra * IN.Colour from the return called fixed it.  Thanks AriusEso!
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks