Home Technical Talk

ji styles shader...QUICK question....

fritz
polycounter lvl 18
Offline / Send Message
fritz polycounter lvl 18
hello, i'm using this shader. right now it only supports 3 lights. however, i need 5. after messing around a bit, i can go into the code itself and add more lights in the parameter section. but, in the technique section...just under where you add your maps, there's the area where you choose your light set up ie: "skinshader_complete_2lights" etc.

i can't get that to show the new light set up that i added ie: "skinshader_complete_5 lights". it only registers 3 choices.

anyone mess w/the code to add more lights? if so, could you post the code for that section? i'm real codedumb.

thanks

Replies

  • Rob Galanakis
    His site seems to be down and I don't have the shader handy.

    Post it up here or at http://rafb.net/paste/ and I can set it up for you.
  • fritz
    Offline / Send Message
    fritz polycounter lvl 18
    really? oh dude. thanks. yeah, dunno why his site is down.
    here it is:

    */
    //=============================Globals==============================
    half4x4 WorldIT : WorldInverse < string UIWidget = "None"; >;
    half4x4 WorldVP : WorldViewProjection < string UIWidget = "None"; >;
    half4x4 World : World < string UIWidget = "None"; >;
    half4x4 ViewIT : ViewInverse < string UIWidget = "None"; >;


    //================================UI================================
    half4 LightPosition1 : POSITION
    <
    string Object = "PointLight";
    string UIName = "Light 1";
    string Space = "World";
    int refID = 0;
    > = {1403.0f, 1441.0f, 1690.0f, 0.0f};


    half4 LightColour1 : LIGHTCOLOR
    <
    int LightRef = 0;
    > = { 1.0f, 1.0f, 1.0f, 0.0f };


    half4 LightPosition2 : POSITION
    <
    string Object = "PointLight";
    string UIName = "Light 2";
    string Space = "World";
    int refID = 1;
    > = {1403.0f, 1441.0f, 1690.0f, 0.0f};


    half4 LightColour2 : LIGHTCOLOR
    <
    int LightRef = 1;
    > = { 1.0f, 1.0f, 1.0f, 0.0f };


    half4 LightPosition3 : POSITION
    <
    string Object = "PointLight";
    string UIName = "Light 3";
    string Space = "World";
    int refID = 2;
    > = {1403.0f, 1441.0f, 1690.0f, 0.0f};


    half4 LightColour3 : LIGHTCOLOR
    <
    int LightRef = 2;
    > = { 1.0f, 1.0f, 1.0f, 0.0f };


    half4 Ambience : AMBIENCE
    <
    string UIWidget = "Color";
    string UIName = "Ambient Tint*";
    > = {0.0f, 0.0f, 0.0f, 1.0f};


    half SpecPower
    <
    string UIWidget = "Slider";
    half UIMin = 0.0;
    half UIMax = 100.0;
    half UIStep = 0.01;
    string UIName = "Specular Power";
    > = 0.5;


    half SpecGloss
    <
    string UIWidget = "Slider";
    half UIMin = 0.0;
    half UIMax = 100.0;
    half UIStep = 0.01;
    string UIName = "Specular Glossiness";
    > = 8.0;


    half SpecFresnel
    <
    string UIWidget = "Slider";
    half UIMin = 0.0;
    half UIMax = 100.0;
    half UIStep = 0.01;
    string UIName = "Specular Fresnel";
    > = 1.0;



    half FresnelPower
    <
    string UIWidget = "Slider";
    half UIMin = 0.0;
    half UIMax = 100.0;
    half UIStep = 0.01;
    string UIName = "Specular Fresnel Power";
    > = 1.0;


    half FresnelGloss
    <
    string UIWidget = "Slider";
    half UIMin = 0.0;
    half UIMax = 100.0;
    half UIStep = 0.01;
    string UIName = "Specular Fresnel Gloss";
    > = 1.0;


    half TransMultiplier
    <
    string UIWidget = "Slider";
    half UIMin = 0.0;
    half UIMax = 100.0;
    half UIStep = 0.01;
    string UIName = "Translucent Power";
    > = 1.0;


    half TransRampIn
    <
    string UIWidget = "Slider";
    half UIMin = -100.0;
    half UIMax = 100.0;
    half UIStep = 0.01;
    string UIName = "Translucent Ramp In";
    > = -0.25;


    half TransRampOff
    <
    string UIWidget = "slider";
    half UIMin = -100.0;
    half UIMax = 100.0;
    half UIStep = 0.01;
    string UIName = "Translucent Ramp Off";
    > = 0.5;


    half TransBloom
    <
    string UIWidget = "slider";
    half UIMin = -100.0;
    half UIMax = 100.0;
    half UIStep = 0.01;
    string UIName = "Trans. Attenuation Bloom";
    > = 3.0;


    half TransBloomDist
    <
    string UIWidget = "slider";
    half UIMin = -100.0;
    half UIMax = 100.0;
    half UIStep = 0.1;
    string UIName = "Trans. Attenuation Focus";
    > = 0.7;


    texture DiffTex
    <
    string name = "Blank_Diff.tga";
    string UIName = "Diffuse Map";
    string TextureType = "2D";
    >;


    texture SpecTex
    <
    string name = "Blank_Spec.tga";
    string UIName = "Specular Map RGBA";
    string TextureType = "2D";
    >;


    texture TransTex
    <
    string name = "Blank_Trans.tga";
    string UIName = "Translucency Map RGBA";
    string TextureType = "2D";
    >;


    texture NormalTex
    <
    string name = "Blank_Normal.tga";
    string UIName = "Normal Map";
    string TextureType = "2D";
    >;


    //============================Texture samplers==============================
    sampler2D DiffSampler = sampler_state
    {
    Texture = <DiffTex>;
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;
    AddressU = WRAP;
    AddressV = WRAP;
    };


    sampler2D SpecSampler = sampler_state
    {
    Texture = <SpecTex>;
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;
    AddressU = WRAP;
    AddressV = WRAP;
    };


    sampler2D TransSampler = sampler_state
    {
    Texture = <TransTex>;
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;
    AddressU = WRAP;
    AddressV = WRAP;
    };


    sampler2D NormalSampler = sampler_state
    {
    Texture = <NormalTex>;
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;
    AddressU = WRAP;
    AddressV = WRAP;
    };


    //============================Input Structures============================
    //application data passed to vertex shader
    struct ApplicationData
    {
    half3 Position : POSITION;
    half4 UV : TEXCOORD0;
    half3 Normal : NORMAL;
    half3 Tangent : TANGENT;
    half3 Binormal : BINORMAL;
    };


    //vertex shader data passed to pixel shader
    struct VertexOutput
    {
    half4 Position : POSITION;
    half4 TexCoord : TEXCOORD0;
    half3 NMLightVec : TEXCOORD1;
    half3 WorldNormal : TEXCOORD2;
    half3 EyeVec : TEXCOORD3;
    half TransAtten : TEXCOORD4;
    };


    //=======================Lambertian shading property=======================
    half4 lambert( half3 DotLN)
    {
    half4 Diffuse = half4(saturate(DotLN).xyz,1);
    return Diffuse;
    }
    //=======================Translucency component=======================
    half4 TransAttenOcclusion( half3 LightPosition,
    half3 PosWorld)
    {
    TransBloomDist = TransBloomDist * 0.1;

    half4 TransAttOcclude = TransBloom / (( TransBloom * 0.035 ) + ( TransBloomDist * distance ( LightPosition.xyz, PosWorld )));
    half4 AttOccMaxDepth = max(1,TransAttOcclude);
    return AttOccMaxDepth;
    }


    half4 TransPass( half3 WN,
    half3 LV,
    half4 TransAttOcc,
    half2 TexUV)
    {
    half3 DotLN = dot(LV,WN);
    half Translucence = smoothstep((-TransRampOff * max(1,(saturate(TransAttOcc)+1) )) * tex2D(TransSampler,TexUV).a,1.0,DotLN)
    - smoothstep(TransRampIn,1.0,DotLN);
    return saturate(Translucence);
    }


    //================Specular component 1 (front on)=======================
    half4 SpecularFrontOn( half3 Normals,
    half3 EyeVec,
    half3 LightVec,
    half4 Power,
    half4 Gloss)
    {
    half3 SpecReflect = (2 * dot(Normals,LightVec) * Normals - LightVec);
    half4 Specular = pow(saturate(dot(SpecReflect, EyeVec)), Gloss) * Power;

    return Specular;
    }


    //===================Specular component 2 (fresnel)=====================
    half4 FresnelMask( half3 Normals,
    half3 EyeVec)
    {
    half4 Fresnel = dot(EyeVec,Normals) * SpecFresnel;
    return saturate(Fresnel);
    }


    //==============================Vertex shader================================
    VertexOutput VertexShader(ApplicationData IN,uniform half4 LightPosition)
    {
    VertexOutput OUT;

    half3x3 TangentToObject;
    TangentToObject[0] = IN.Binormal.xyz;
    TangentToObject[1] = -IN.Tangent.xyz;
    TangentToObject[2] = IN.Normal.xyz;

    half4 ObjectLightPosition = mul(LightPosition, WorldIT);
    half3 ObjectLightVec = ObjectLightPosition.xyz - IN.Position.xyz;
    half4 ObjectSpaceEyePos = mul(ViewIT[3], WorldIT);
    half3 ObjectEyeVec = ObjectSpaceEyePos.xyz - IN.Position.xyz;

    OUT.NMLightVec = mul(TangentToObject, ObjectLightVec );
    OUT.EyeVec = mul(TangentToObject, ObjectEyeVec);
    OUT.TexCoord = IN.UV;

    half3 Normal = IN.Normal;
    half4 Pos = half4(IN.Position.xyz,1);
    half3 PosWorld = mul(Pos, World).xyz;

    OUT.WorldNormal = mul(Normal, WorldIT).xyz;
    OUT.Position = mul(Pos, WorldVP);
    OUT.TransAtten = TransAttenOcclusion(LightPosition,PosWorld);
    return OUT;
    }


    //================================Pixel shader - Complete================================
    half4 PixelShader_Complete(VertexOutput IN, uniform half4 LightColour) : COLOR
    {
    half3 normalmap = (tex2D(NormalSampler, IN.TexCoord).xyz -0.5);
    half3 LV = normalize(IN.NMLightVec);
    half3 EV = normalize(IN.EyeVec);
    half3 WN = normalize(normalmap);
    half2 TexUV = IN.TexCoord.xy;
    half3 DotLN = dot(LV,WN);
    half4 TransAttOcc = IN.TransAtten;
    half4 FresnelStrength = saturate(1 - FresnelMask(WN,EV)) * FresnelPower + 1;
    half4 FresnelGlossiness = FresnelMask(WN,EV) * FresnelGloss + 1;

    half4 BaseLighting = max(Ambience, lambert(DotLN));

    half4 Translucency = TransPass(WN,LV,TransAttOcc,TexUV)
    * TransAttOcc
    * tex2D(TransSampler,IN.TexCoord.xy)
    * TransMultiplier;

    half4 Spec = SpecularFrontOn(WN,EV,LV,SpecPower * FresnelStrength ,SpecGloss * FresnelGlossiness * tex2D(SpecSampler,IN.TexCoord.xy).a)
    * BaseLighting
    * tex2D(SpecSampler,IN.TexCoord.xy);

    half4 LightingOutput = ((BaseLighting + Translucency) * tex2D(DiffSampler,IN.TexCoord.xy) + saturate(Spec)) * LightColour;

    return LightingOutput;
    }


    //================================Pixel shader - Simplified================================
    //not yet simplified... need to check on lower specs


    //================================TECHNIQUES================================
    technique SkinShader_Complete_1Light
    {
    pass componentlight1
    {
    VertexShader = compile vs_1_1 VertexShader(LightPosition1);
    ZEnable = true;
    ZWriteEnable = true;
    AlphaBlendEnable = true;
    SrcBlend = SrcAlpha;
    DestBlend = InvSrcAlpha;
    CullMode = CW; //None, CW, or CCW
    PixelShader = compile ps_2_0 PixelShader_Complete(LightColour1);
    }
    }

    technique SkinShader_Complete_2Lights
    {
    pass componentlight1
    {
    VertexShader = compile vs_1_1 VertexShader(LightPosition1);
    ZEnable = true;
    ZWriteEnable = true;
    AlphaBlendEnable = true;
    SrcBlend = SrcAlpha;
    DestBlend = InvSrcAlpha;
    CullMode = CW; //None, CW, or CCW
    PixelShader = compile ps_2_0 PixelShader_Complete(LightColour1);
    }

    pass componentlight2
    {
    VertexShader = compile vs_1_1 VertexShader(LightPosition2);
    ZEnable = true;
    ZWriteEnable = false;
    ZFunc = LessEqual;
    AlphaBlendEnable = true;
    SrcBlend = SrcAlpha;
    DestBlend = One;
    CullMode = None; //None, CW, or CCW
    PixelShader = compile ps_2_0 PixelShader_Complete(LightColour2);
    }
    }

    technique SkinShader_Complete_3Lights
    {
    pass componentlight1
    {
    VertexShader = compile vs_1_1 VertexShader(LightPosition1);
    ZEnable = true;
    ZWriteEnable = true;
    AlphaBlendEnable = true;
    SrcBlend = SrcAlpha;
    DestBlend = InvSrcAlpha;
    CullMode = CW; //None, CW, or CCW
    PixelShader = compile ps_2_0 PixelShader_Complete(LightColour1);
    }

    pass componentlight2
    {
    VertexShader = compile vs_1_1 VertexShader(LightPosition2);
    ZEnable = true;
    ZWriteEnable = false;
    ZFunc = LessEqual;
    AlphaBlendEnable = true;
    SrcBlend = SrcAlpha;
    DestBlend = One;
    CullMode = None; //None, CW, or CCW
    PixelShader = compile ps_2_0 PixelShader_Complete(LightColour2);
    }

    pass componentlight3
    {
    VertexShader = compile vs_1_1 VertexShader(LightPosition3);
    ZEnable = true;
    ZWriteEnable = false;
    ZFunc = LessEqual;
    AlphaBlendEnable = true;
    SrcBlend = SrcAlpha;
    DestBlend = One;
    CullMode = None; //None, CW, or CCW
    PixelShader = compile ps_2_0 PixelShader_Complete(LightColour3);
    }
    }
  • Rob Galanakis
    you know, fritz, code tags are there for a reason. Anyway, I added the following to the light constants up top:

    <font class="small">Code:</font><hr /><pre>
    half4 LightPosition4 : POSITION
    <
    string Object = "PointLight";
    string UIName = "Light 4";
    string Space = "World";
    int refID = 3;
    > = {1403.0f, 1441.0f, 1690.0f, 0.0f};

    half4 LightColour4 : LIGHTCOLOR
    <
    int LightRef = 3;
    > = { 1.0f, 1.0f, 1.0f, 0.0f };

    half4 LightPosition5 : POSITION
    <
    string Object = "PointLight";
    string UIName = "Light 5";
    string Space = "World";
    int refID = 4;
    > = {1403.0f, 1441.0f, 1690.0f, 0.0f};


    half4 LightColour5 : LIGHTCOLOR
    <
    int LightRef = 4;
    > = { 1.0f, 1.0f, 1.0f, 0.0f };
    </pre><hr />

    and to the bottom, we add a new technique:

    <font class="small">Code:</font><hr /><pre>
    technique SkinShader_Complete_5Lights
    {
    pass componentlight1
    {
    VertexShader = compile vs_1_1 VertexShader(LightPosition1);
    ZEnable = true;
    ZWriteEnable = true;
    AlphaBlendEnable = true;
    SrcBlend = SrcAlpha;
    DestBlend = InvSrcAlpha;
    CullMode = CW; //None, CW, or CCW
    PixelShader = compile ps_2_0 PixelShader_Complete(LightColour1);
    }

    pass componentlight2
    {
    VertexShader = compile vs_1_1 VertexShader(LightPosition2);
    ZEnable = true;
    ZWriteEnable = false;
    ZFunc = LessEqual;
    AlphaBlendEnable = true;
    SrcBlend = SrcAlpha;
    DestBlend = One;
    CullMode = None; //None, CW, or CCW
    PixelShader = compile ps_2_0 PixelShader_Complete(LightColour2);
    }

    pass componentlight3
    {
    VertexShader = compile vs_1_1 VertexShader(LightPosition3);
    ZEnable = true;
    ZWriteEnable = false;
    ZFunc = LessEqual;
    AlphaBlendEnable = true;
    SrcBlend = SrcAlpha;
    DestBlend = One;
    CullMode = None; //None, CW, or CCW
    PixelShader = compile ps_2_0 PixelShader_Complete(LightColour3);
    }

    pass componentlight4
    {
    VertexShader = compile vs_1_1 VertexShader(LightPosition4);
    ZEnable = true;
    ZWriteEnable = false;
    ZFunc = LessEqual;
    AlphaBlendEnable = true;
    SrcBlend = SrcAlpha;
    DestBlend = One;
    CullMode = None; //None, CW, or CCW
    PixelShader = compile ps_2_0 PixelShader_Complete(LightColour4);
    }

    pass componentlight5
    {
    VertexShader = compile vs_1_1 VertexShader(LightPosition5);
    ZEnable = true;
    ZWriteEnable = false;
    ZFunc = LessEqual;
    AlphaBlendEnable = true;
    SrcBlend = SrcAlpha;
    DestBlend = One;
    CullMode = None; //None, CW, or CCW
    PixelShader = compile ps_2_0 PixelShader_Complete(LightColour5);
    }
    }
    </pre><hr />

    Tell me if there are any problems.
  • fritz
    Offline / Send Message
    fritz polycounter lvl 18
    oh crap. i'm sorry man. never tried to post any code stuff before. thanks man...so much. i really appreciate it.
Sign In or Register to comment.