Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

q2guy

PerPixel Specular in PS 1.3

This topic is 5283 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

PerPixel specular lighting can be made in a pixel shader version 1.1 - 1.3 ? I have tried but I get errors compiling
struct FP_INPUT
{
   float4 Diffuse : COLOR0;
   float3 Normal  : TEXCOORD0;
   float3 Light   : TEXCOORD1;
   float3 View    : TEXCOORD2;
};

struct FP_OUTPUT
{
   float4 Color : COLOR0;
};

void ps_main (in FP_INPUT IN,out FP_OUTPUT OUT)
{
   float3 vReflect = normalize(2*dot(IN.Normal,IN.Light)*IN.Normal - IN.Light);
   //float3 vReflect = reflect(IN.Normal,IN.Light);

   
   OUT.Color = Ka * Ca + 
               Kd * Cd * dot(IN.Normal,IN.Light) +
               Ks * Cs * pow(max(0,dot(vReflect,IN.View)),32.0);
}

Share this post


Link to post
Share on other sites
Advertisement
i''ve only done a little in pixel shaders but i think this piece of code is a little weird:

struct FP_INPUT{
float4 Diffuse : COLOR0;
float3 Normal : TEXCOORD0;
float3 Light : TEXCOORD1;
float3 View : TEXCOORD2;
};

why not make it:

struct FP_INPUT{
float4 Diffuse : COLOR0;
float3 Normal : NORMAL0;
float3 Light : LIGHT0; //and something others to the others
float3 View : EYEPOS;
};

Share this post


Link to post
Share on other sites
In pixel shader input you can''t pass a NORMAL0 or BLENDWEIGHT ..., only COLOR and TEXCOORD I think.
I''ve tried and the compiler show errors, and I have see in ATI docs do the input struct in this way.

Share this post


Link to post
Share on other sites
What are the compilation errors it shows ?
Did you try to get it in assembly first ? ps1.3 will be very limited in instruction number (4+8) and if I can remember, pow will consume a lot of instructions to be emulated (not in the ps1.x instruction set).


ps_1_3

def c0, <Ka*Ca>
def c1, <Kd*Cd>
def c2, <Ks*Cs>
def c3, 0, 0, 0, 0

dp3 r1, t0, t1 // r1 = N.L
mul r0, r1.w, t0 // r0 = (N.L)*N
sub r0, r0_x2, t1 // r0 = 2*N.L*N - L

dp3 r0, r0, t2 // r0.w = R.V
cmp r0.w, r0.w, r0.x, c3.w // take only positive values (note that cmp uses 2 instruction slots in ps 1.3)

// Pow is following, beware of precision issues !!
mul r0.w, r0.w, r0.w // r0 = (R.V)^2
mul r0.w, r0.w, r0.w // r0 = (R.V)^4
mul r0.w, r0.w, r0.w // r0 = (R.V)^8
mul r0.w, r0.w, r0.w // r0 = (R.V)^16
mul r0.w, r0.w, r0.w // r0 = (R.V)^32

mad r1, c1, r1.w, c0 // r1 = Ka*Ca + Kd*Cd*N.L
mad v0, c2, r0.w, r1 // v0 = r1 + Ks*Cs*(R.V)^32


So in the end, we have 13 instruction slots taken whereas only 8 are available. I doubt we can do much shorter than this but it might be possible, I am no shader guru and I did not compile previous shader. You can cut on the pow though and it should fit.

Check that URL for some shaders that might inspire you.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx05222002.asp

[edited by - vprat on June 4, 2004 3:04:35 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!