We get it. We use ad blockers too. But GameDev.net displays them so we can continue to be a great platform for you.
Please whitelist GameDev.net and our advertisers.
Also consider a GDNet+ Pro subscription to remove all ads from GameDev.net.
Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 26 May 2012 - 04:47 AM
Edited by iedoc, 26 May 2012 - 04:48 AM.
Posted 26 May 2012 - 07:15 AM
you can use the "normalize()" function in hlsl to make a vector unit length, or you can create the vector in your app and send it to the shaders using a constant buffer.
in hlsl here are a couple unit vectors for you
float3 unitVector1 = float3(1,0,0); // unit vector
float3 unitVector2 = float3(10, 2, 7); // Not unit vector yet
unitVector = normalize(unitVector); // Now it's a unit length vector
float3 udir = float3 (1, 0, 1); udir = normalize(udir);
Posted 26 May 2012 - 07:25 AM
“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”
Posted 26 May 2012 - 08:07 AM
Can you show your entire shader? As far as I can tell these two lines are valid (out of context, anyway). There must be something else in the shader code that's preventing this to work.
uniform extern float4x4 gWVP; uniform extern float gTime; struct OutputVS { float4 posH : POSITION0; float4 color : COLOR0; }; float3 udir = float3 (1, 0, 1); udir = normalize(udir); static float a[2] = {0.8f, 0.2f}; static float k[2] = {1.0, 8.0f}; static float w[2] = {1.0f, 8.0f}; static float p[2] = {0.0f, 1.0f}; float SumOfRadialSineWaves(float x, float z) { float3 p = float3(x, 0, z); float my_x = dot(udir, p); float sum = 0.0f; for(int i = 0; i < 2; ++i) sum += a[i]*sin(k[i]*my_x - gTime*w[i] + p[i]); return sum; } float4 GetColorFromHeight(float y) { if( abs(y) <= 0.2f ) // black return float4(0.0f, 0.0f, 0.0f, 1.0f); else if(abs(y) <= 0.5f ) // blue return float4(0.0f, 0.0f, 1.0f, 1.0f); else if(abs(y) <= 0.8f ) // green return float4(0.0f, 1.0f, 0.0f, 1.0f); else if(abs(y) <= 1.0f ) // red return float4(1.0f, 0.0f, 0.0f, 1.0f); else // yellow return float4(1.0f, 1.0f, 0.0f, 1.0f); } OutputVS ColorVS(float3 posL : POSITION0) { OutputVS outVS = (OutputVS)0; posL.y = SumOfRadialSineWaves(posL.x, posL.z); outVS.color = GetColorFromHeight(posL.y); outVS.posH = mul(float4(posL, 1.0f), gWVP); return outVS; } float4 ColorPS(float4 c : COLOR0) : COLOR { return c; } technique HeightColorTech { pass P0 { vertexShader = compile vs_2_0 ColorVS(); pixelShader = compile ps_2_0 ColorPS(); FillMode = WireFrame; } }
Edited by Hseptic, 26 May 2012 - 08:09 AM.
Posted 26 May 2012 - 09:21 AM
float3 udir = float3 (1, 0, 1);
udir = normalize(udir);
static float a[2] = {0.8f, 0.2f};
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.