About Store Forum Documentation Contact
Donations:
345$/mo



Post Reply 
Shader based on "Test Blend Light"
Author Message
cmontiel Offline
Member

Post: #1
Shader based on "Test Blend Light"
I am trying to fade in my characters when they enter in scene. "Test Blend Light" technique would be perfect but I am using material ambient color in some materials and this tech doesn't take into account.

I've created a custom shader but I'm not able to return the same final color:

Code:
BUFFER(CustBuffer) //Maybe they should be declared as uniform?
    Vec GlobalAmbient;
    Vec LightDirection;
    Vec LightColor;
BUFFER_END

/******************************************************************************/
// VERTEX SHADER
/******************************************************************************/
void VS
(
   // vertex input
   VtxInput vtx,

   // output
   out Vec2 outTex:TEXCOORD0,
   out Flt  outLum:TEXCOORD1,
   out Vec4 outVtx:POSITION
)
{
   VecI2 bone          =vtx.bone();
   Vec   view_space_pos=          TransformPos(vtx.pos4(), bone, vtx.weight());
   Vec   view_space_nrm=Normalize(TransformDir(vtx.nrm (), bone, vtx.weight()));

   outTex=vtx.tex();
   outLum=Dot(LightDirection, view_space_nrm);
   outVtx=Project(view_space_pos);
}
/******************************************************************************/
// PIXEL SHADER
/******************************************************************************/
Vec4 PS
(
   Vec2 DiffuseTex:TEXCOORD0,
   Flt  inLum:TEXCOORD1

):COLOR
{
    Flt intensity = Sat(inLum);
        // Whitout a light in scene this works !
    Vec color = Tex(Col, DiffuseTex ).rgb * MaterialColor().rgb * (GlobalAmbient + MaterialAmbient());
        // But my scenes have one directional light.
    color = >>>>> color (+?) (*?)  something with LightColor and intensity <<<<<<
    return Vec4(color,MaterialColor().a);
}
/******************************************************************************/
// TECHNIQUE
/******************************************************************************/
TECHNIQUE(Main, VS(), PS());
/******************************************************************************/

@Esenthel , Can you say how the final color "Test Blend Light" is calculated. I would be interesting if you can say how to apply alpha testing + depth writing too.

IRC: irc.freenode.net
Channel: #Esenthel
(This post was last modified: 02-14-2013 04:22 AM by cmontiel.)
02-14-2013 04:21 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Shader based on "Test Blend Light"
try:
*(GlobalAmbient + MaterialAmbient() + intensity*LightColor)

alpha testing:
Vec4 tex_col=Tex(Col, IO_tex);
if(tex_col.a<0.5)discard;

depth writing should automatically work when you have material technique set to one of "test blend light" values
02-19-2013 01:14 PM
Find all posts by this user Quote this message in a reply
Post Reply