dark coder
Quote: "If I change them to literals like in your code I can no longer change the values from my code as I believe on the left you have the constant the shader uses internally and on the right you have the constant the application can see, this makes sense for ASM shaders where you must have c0,1,2 etc for the constants."
No, that's wrong I'm afraid.
If you want to change the values using DBP just use
set effect constant float or
set effect constant vector as illustrated in the numerous shader demos on this site (and this thread).
Quote: "I found that if I pass IN.Position to the pixel shader "OUT.sPos = IN.Position;" it seems to work correctly, multiplying it by WorldViewProjection/World/WorldIT/WorldInverse etc all result in incorrect rendering."
That's interesting. I'm not sure off-hand why that should work (and am not convinced it does work) - I didn't check the details of what you were doing carefully yesterday. I concentrated on getting a functioning shader which you could amend as necessary. Seems like you are making good progress now.
Quote: "I get a sharp transition between light and dark, when it should blend."
I'll try to find time later today to look into this more carefully. However, for now, you might consider what the following lines actually do:
// Find distance from pixel to light
float Px_Dist_L = IN.sPos - LightPosition; // **GG
// Find distance from planet to light
float Pl_Dist_L = PlanetPosition - LightPosition;
// Find difference ratio
float Ratio = Px_Dist_L / Pl_Dist_L;
You have assigned a float4 to a float in the first two lines. I think what happens is that the first component, i.e. the x coordinate, ends up being assigned to the floats. Hence I believe your code is equivalent to the more transparent which makes it obvious that your "distance" could be negative
// Find distance from pixel to light
float Px_Dist_L = IN.sPos.x - LightPosition.x; // **GG
// Find distance from planet to light
float Pl_Dist_L = PlanetPosition.x - LightPosition.x;
// Find difference ratio
float Ratio = Px_Dist_L / Pl_Dist_L;
The line I corrected was merely to get your shader compiling, I didn't attempt to modify what it was apparently trying to do. If you are trying to get the distance between the planet's position and the light's position you shouldn't be doing that in the shader anyway, and certainly not in the pixel shader. You'll be calculating the same distance for every pixel unless the shader compiler can extract common code and pre-calculate it befiore the object is rendered. I usually play safe and calculate things like that ONCE per sync in DBP and pass the result to the shader using
set effect constant float. More importantly though, if you want
distance you need to calculate something like
// Find distance from pixel to light
float Px_Dist_L = length(IN.sPos.xyz - LightPosition.xyz); // **GG - squared :)
(except that I think you need World space coords as I mentioned yesterday - I suspect the difficulties you experienced are a result of you doing the wrong calculation).
If you're still stuck I'll try to sort this out properly later - I'm sure that what you are trying to do is easy to achieve and is a nice idea.