Jump to content
  • Advertisement

stevereine

Member
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

104 Neutral

About stevereine

  • Rank
    Newbie
  1. stevereine

    hlsl if then else question

    I've got quite a bit to learn, thank you all gentlemen!   Steve
  2. stevereine

    hlsl if then else question

    OK Dingleberry, you have solved my problem. I didn't mention it until my second post, but I was using ps_2_0 to compile. I noticed you had compiled my code in ps_3_0 so switched to that and switched to the VPOS semantic. It now works exactly as I had hoped it would. Being the OCD individual that I am, I might just go back and try to understand the difference between ps_2 and ps_3 to find out what went wrong, maybe no good explanation. I also need to read up on semantics, don't understand the difference between VPOS and POSITION.   thank you very much!   Steve  
  3. stevereine

    hlsl if then else question

    Hi Hodgman,   The error is 'unhandled exception at 0x003C3B5F. Access violation reading location 0x00000000. Maybe not an error in shader compilation then, but looks like maybe it's not getting a correct pointer value when returning from the GetTechniqueByName function.    I think you're on the right path when suggesting that it's optimizing away the if statement. HLSL code is a very interesting animal.   Steve
  4. stevereine

    hlsl if then else question

    Thank you Hodgman for the edit, I will try to stick to that format in the future.   FYI - This is Directx9, and the error is not actually when the shader is compiled, but occurs in the GetTechniqueByName statement in the C++ code. Technique code in shader is as follows; Technique mytechnique { pass PO { //SetVertexShader( CompileShader( vs_2_0, Ripple())); vertexShader = compile vs_2_0 Ripple(); pixelShader = compile ps_2_0 ColorPS(); }   pass P1 { //SetVertexShader( CompileShader( vs_2_0, Ripple())); vertexShader = compile vs_2_0 Ripple(); pixelShader = compile ps_2_0 ColorPS(); }   }   Steve
  5. Can someone tell me why the following pixel shader code works and the second bit of code doesn't? This is excerpted from a .fx file that otherwise works fine. The only thing that is changing is the litcolor.r value in the if-then code. It seems that if I don't change the litcolor.r value, all works fine. Why would changing this value cause the shader to not compile correctly? I know it's not a real useful bit of code, but just trying to see what the limitations of pixel shaders are. Thanks! struct VS_OUTPUT { float4 Position : POSITION; // vertex position float4 Diffuse : COLOR0; // vertex diffuse color }; float4 ColorPS(float4 vPosition : POSITION, float4 c : COLOR0) : COLOR { VS_OUTPUT Output; float4 litcolor = float4(0.0f, 0.0f, 0.0f, 0.0f); if (vPosition.x>1000) { litcolor.r=0.0f; } //else //{ // litcolor.g=1.0f; //} return litcolor; }and the following gives me a shader compiler error? ColorPS(float4 vPosition : POSITION, float4 c : COLOR0) : COLOR { VS_OUTPUT Output; float4 litcolor = float4(0.0f, 0.0f, 0.0f, 0.0f); if (vPosition.x>1000) { litcolor.r=1.0f; } //else //{ // litcolor.g=1.0f; //} return litcolor; }
  6. Never mind, found it. Funny how these things work. As I was reviewing the code I had posted, I noticed that I was passing an identity matrix into the technique in this line;   mfx->SetMatrix(h_mWorldViewProj,&identity);   where I should have been passing in the mWorldViewProj matrix variable created a few lines earlier in the code with this line;   D3DXMATRIX mWorldViewProj = identity*(matView)*(matProj);   Everything work great now!   Engineer, heal thyself!   Steve
  7. I'm sure this question is trivial, but here goes.   Up till now, I've done everything I needed to do using Shaders without Effects. Now I've added a most basic Effect, with a single Technique, to my code and now I can't get anything to render to the screen.   I have the standard Begin,Beginpass,Endpass,End loop with DrawPrimitive within the loop. The thing that is most frustrating is that I also have a DrawPrimitive command outside of that loop. If I uncomment that line, so the code is just using the Shader, it renders fine. Based on that, I know that the vertex and associated set-up code is OK.   I have debug code set up so that I know that the Technique is being created, that I have acquired the global world view matrix variable within the technique code and that I am able to pass my WorldView matrix back to the Technique code. Also, with the debug code, I can verify that the code is looping through the technique, just not doing anything with it.   I've spent about a week on this, but I'm sure someone will come back with something trivial that I'm missing;   Any ideas on what can cause such behavior. Here's the code around the rendering loop and below that is the shader code, just taken from the Microsoft tutorial. Note that I'm just setting the WorldViewProj matrix to an identity matrix. This works when just using the Shader, is there something else that happens when using an Effect/Technique?   thanks!   Steve     UINT numPasses = 1;   mfx->Begin(&numPasses, 0);   for(UINT i = 0; i < numPasses; ++i) { mfx->BeginPass(i); mfx->SetMatrix(h_mWorldViewProj,&identity); mfx->CommitChanges();   g_pd3dDevice_1->SetVertexDeclaration(Decl); g_pd3dDevice_1->SetStreamSource( 0, g_pVB_1, 0,   sizeof(CUSTOMVERTEX) ); HR = g_pd3dDevice_1->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 8 );   mfx->EndPass(); }   mfx->End();   //end c++ code   //begin shader code:     //----------------------------------------------------------------------------- // File: HLSLwithoutEffects.vsh // // Desc: The effect file for the BasicHLSL sample. It contains a vertex // shader which animates the vertices. // // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- // note: variables that are declared, but not used in the code, will be removed when the code is compiled. //----------------------------------------------------------------------------- // Global variables //----------------------------------------------------------------------------- uniform extern float4x4 mWorldViewProj; // World * View * Projection transformation   //----------------------------------------------------------------------------- // Vertex shader output structure //----------------------------------------------------------------------------- struct VS_OUTPUT { float4 Position : POSITION; // vertex position float4 Diffuse : COLOR0; // vertex diffuse color }; ? //----------------------------------------------------------------------------- // Name: Ripple // Type: Vertex shader // Desc: This shader ripples the vertices //----------------------------------------------------------------------------- VS_OUTPUT Ripple(   float3 vPosition : POSITION, float4 color : COLOR0 ) { VS_OUTPUT Output;     // This HLSL intrinsic computes returns both the sine and cosine of x sincos( x, fSin, fCos ); Output.Position = mul(float4( vPosition.x, vPosition.y, vPosition.z, 1.0f ), mWorldViewProj ); Output.Diffuse = float4(0.0f, 0.0f, 0.0f, 1.0f);//color;   return Output; }   float4 ColorPS(float4 c : COLOR0) : COLOR {   return c;   }   Technique mytechnique {   pass PO {     //SetVertexShader( CompileShader( vs_2_0, Ripple())); vertexShader = compile vs_2_0 Ripple(); pixelShader = compile ps_2_0 ColorPS(); FillMode = WIREFRAME; CullMode = NONE;   } } ?
  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!