temperamental ID3D10EffectVectorVariable

SirYakalot
  • temperamental ID3D10EffectVectorVariable SirYakalot

    I am setting an HLSL effect variable in the following way in a number of places.

    extern ID3D10EffectVectorVariable* pColour;
    
    pColour = pEffect->GetVariableByName("Colour")->AsVector();
    
    pColour->SetFloatVector(temporaryLines[i].colour);
    

    In one of the places it is set in a loop, each line in the vector temporaryLines has a D3DXCOLOR variable associated with it. The most annoying thing about this problem is that it actually works on rare occasions, but most of the time it doesn't. Are there any known issues with this kind of code?

    Here it works:

    void GameObject::Draw(D3DMATRIX matView, D3DMATRIX matProjection)
    {
    device->IASetInputLayout(pVertexLayout);
    
    mesh.SetTopology();//TODO should not be done multiple times
    
    // select which vertex buffer and index buffer to display
    UINT stride = sizeof(VERTEX);
    UINT offset = 0;
    device->IASetVertexBuffers(0, 1, mesh.PBuffer(), &stride, &offset);
    device->IASetIndexBuffer(mesh.IBuffer(), DXGI_FORMAT_R32_UINT, 0);
    
    pColour->SetFloatVector(colour);
    
    // create a scale matrix
    D3DXMatrixScaling(&matScale, scale.x, scale.y, scale.z);
    
    // create a rotation matrix
    D3DXMatrixRotationYawPitchRoll(&matRotate, rotation.y, rotation.x, rotation.z);
    
    // create a position matrix
    D3DXMatrixTranslation(&matTranslation, position.x, position.y, position.z);
    
    // combine the matrices and render
    matFinal = 
        matScale        * 
        matRotate       * 
        matTranslation  * 
        matView * matProjection;
    pTransform->SetMatrix(&matFinal._11); 
    pRotation->SetMatrix(&matRotate._11);    // set the rotation matrix in the effect
    pPass->Apply(0);
    device->DrawIndexed(mesh.Indices(), 0, 0);   //input specific
    }
    

    Here is occasionally works:

    void BatchLineRenderer::RenderLines(D3DXMATRIX matView, D3DXMATRIX matProjection)
    {
    device->IASetInputLayout(pVertexLayout);
    
    device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP);
    
    // select which vertex buffer and index buffer to display
    UINT stride = sizeof(LINE);
    UINT offset = 0;
    device->IASetVertexBuffers(0, 1, &pBuffer, &stride, &offset);
    device->IASetIndexBuffer(iBuffer, DXGI_FORMAT_R32_UINT, 0);
    
    allLines = temporaryLines.size();
    
    for(int i = 0; i < allLines; i++)
    {
        pColour->SetFloatVector(temporaryLines[i].colour); // in the line loop too?
    
        // combine the matrices and render
        D3DXMATRIX matFinal = 
            temporaryLines[i].scale * 
            temporaryLines[i].rotation * 
            temporaryLines[i].position * 
            matView * matProjection;
    
        pTransform->SetMatrix(&matFinal._11); 
        pRotation->SetMatrix(&temporaryLines[i].rotation._11);    // set the rotation matrix in the effect
    
        pPass->Apply(0);
    
        device->DrawIndexed(2, 0, 0);
    }
    
    temporaryLines.clear();
    }
    

    the effect file:

    float4x4 Transform;    // a matrix to store the transform
    float4x4 Rotation;     // a matrix to store the rotation transform
    float4   LightVec   = {0.612f, 0.3535f, 0.612f, 0.0f};    // the light's vector
    float4   LightCol   = {1.0f,   1.0f,    1.0f,   1.0f};    // the light's color
    float4   AmbientCol = {0.3f,   0.3f,    0.3f,   1.0f};    // the ambient light's color
    float4   Colour;
    
    // a struct for the vertex shader return value
    struct VSOut
    {
        float4 Col : COLOR;    // vertex normal
        float4 Pos : SV_POSITION;    // vertex screen coordinates
    };
    
    // the vertex shader
    VSOut VS(float4 Norm : NORMAL, float4 Pos : POSITION)
    {
        VSOut Output;
    
        Output.Pos = mul(Pos, Transform);    // transform the vertex from 3D to 2D
    
        Output.Col = AmbientCol;    // set the vertex color to the input's color
    
        float4 Normal = mul(Norm, Rotation);
    
        Output.Col += saturate(dot(Normal, LightVec)) * LightCol * Colour; // add the diffuse and passed in light
    
        return Output;    // send the modified vertex data to the Rasterizer Stage
    }
    
    // the pixel shader
    float4 PS(float4 Col : COLOR) : SV_TARGET
    {
        return Col;    // set the pixel color to the color passed in by the Rasterizer Stage
    }
    
    // the primary technique
    technique10 Technique_0
    {
        // the primary pass
        pass Pass_0
        {
            SetVertexShader(CompileShader(vs_4_0, VS()));
            SetGeometryShader(NULL);
            SetPixelShader(CompileShader(ps_4_0, PS()));
        }
    }
    

  • Without being able to see it running (or the rest of the code) it's hard to say, but are you sure it's actually what you think failing here? That value is only used in the lighting equation where it's contribution is based on the angle between the normal of the vertex and the lighting vector. It could be the normal value on the line vertex is such that it breaks. Have you tried just setting the output colour of the VS (Output.Col) to just be equal to "Colour" to rule out any other possibilities? That way the value will just be set directly and will validate it's this that's broken. With that set, also try setting a specific value in the code rather than pull the value out of the line structure to ensure that's valid.

    Other than that, there's any number of reasons it could be broken, e.g. the vertex layout might not exactly match the actual structure correctly, etc.

    I'm not sure what the state of PC shader debugging is like as I haven't had much call to use them (e.g. PIX, NVidia or ATI tools), but they might also be able to let you see better what's going on.

  • Set your FloatVector before you set the Input Layout.

    I had the same problem once:

    https://stackoverflow.com/questions/2936472/setmatrix-does-not-copy-all-values-to-hlsl

Tags
c++ directx directx10
Related questions and answers
  • type we are using device-&gt;IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); // select which vertex buffer and index buffer to display UINT stride = sizeof(VERTEX); UINT offset = 0; device-&gt;IASetVertexBuffers(0, 1, &amp;pBuffer, &amp;stride, &amp;offset); device-&gt;IASetIndexBuffer(iBuffer, DXGI_FORMAT_R32_UINT, 0); D3DXMATRIX matRotate, matView...(pBackBuffer, NULL, &amp;rtv); pBackBuffer-&gt;Release(); // set the back buffer as the render target device-&gt;OMSetRenderTargets(1, &amp;rtv, dsv); D3D10_VIEWPORT viewport; // create a struct to hold

  • matView, D3DXMATRIX matProjection) { device-&gt;IASetInputLayout(pVertexLayout); device-&gt;IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP); // select which vertex buffer and index buffer to display UINT stride = sizeof(LINE); UINT offset = 0; device-&gt;IASetVertexBuffers(0, 1, &amp;pBuffer, &amp;stride, &amp;offset); device-&gt;IASetIndexBuffer(iBuffer, DXGI...++) { pColour-&gt;SetFloatVector(temporaryLines[i].colour); // in the line loop too? // combine the matrices and render D3DXMATRIX matFinal = temporaryLines[i].scale

  • : COLOR; // vertex color float4 Pos : SV_POSITION; // vertex screen coordinates }; // the vertex shader VSOut VS(float4 Col : COLOR, float4 Pos : POSITION) { VSOut Output; Output.Pos = Pos; // set the vertex position to the input's position Output.Col = Col; // set the vertex color to the input's color return Output; // send the modified vertex data to the Rasterizer Stage } // the pixel shader float4 PS(float4 Col : COLOR) : SV_TARGET { return Col; // set the pixel color to the color passed in by the Rasterizer Stage } // the primary technique technique10 Technique_0

  • (D3D10_PRIMITIVE_TOPOLOGY_LINELIST); UINT stride = sizeof(VERTEX); UINT offset = 0; device-&gt;IASetVertexBuffers(0, 1, &amp;pBuffer, &amp;stride, &amp;offset); screenPass-&gt;Apply(0... have marked with //THIS LINE, the code works fine.) when I run the code below the line breaks //HERE. Access violation reading location 0x00000000. seems like the create buffer line is not working...; bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; bd.MiscFlags = 0; device-&gt;CreateBuffer(&amp;bd, NULL, &amp;pBuffer); void* pVoid; pBuffer-&gt;Map(D3D10_MAP_WRITE_DISCARD, 0, &amp;pVoid); //HERE memcpy(pVoid

  • ;IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINELIST); // select which vertex buffer to display UINT stride = sizeof(VERTEX); UINT offset = 0; device-&gt;IASetVertexBuffers(0, 1, &amp;pBuffer, &amp;stride, &amp;offset); // apply the appropriate pass screenPass-&gt;Apply(0); // draw the vertex buffer to the back buffer device-&gt;Draw(temporary2DVerts.size... it all separately? Basically how would I extend this code to include more vectors of vertices? if (temporary2DVerts.size() &gt; 0) { // create the vertex buffer and store the pointer into pBuffer

  • in the shader code) for( int n = 0; n < vShaderArgs.size(); n ++) glBindAttribLocation( m_nProgramId, n, vShaderArgs[n].sFieldName.c_str() ); // Create and bind to a vertex array object, which...I'm writing a generic ShaderProgram class that compiles a set of Shader objects, passes args to the shader (like vertex position, vertex normal, tex coords etc), then links the shader components...: float m_Position[3]; // x, y, z // offset 0, size = 3*sizeof(float) float m_TexCoords[2]; // u, v // offset 3*sizeof(float), size = 2*sizeof(float) float m_Normal[3

  • ) glColor3fv (&amp;outlineColor[0]); // Set The Outline Color ( NEW ) // HERE I AM PARSING THE VERTICES AGAIN (NOT IN THE ORIGINAL FUNCTION) FOR THE OUTLINE AS PER...]; Vec3f pos = v1-&gt;pos * (1 - frac) + v2-&gt;pos * frac; Vec3f normal = v1-&gt;normal * (1 - frac) + v2-&gt;normal * frac; if (normal[0] == 0 &amp;&amp; normal[1...); // Set The Color Of The Model ( NEW ) // ORIGINAL DRAWING CODE //Draw the model as an interpolation between the two frames glBegin(GL_TRIANGLES); for(int i = 0; i

  • every frame to handle input and render etc I call an UpdatePhysics method to update the physics simulation. void GameState::UpdatePhysics(unsigned int TDeltaTime) { World-&gt;stepSimulation(TDeltaTime...)Point[0], (float)Point[1], (float)Point[2])); // set rotation btVector3 EulerRotation; QuaternionToEuler(TObject-&gt;getOrientation(), EulerRotation); node-&gt;setOrientation(1,(Ogre... code shows the changes I made to get accurate physics. void GameState::createScene() { m_pSceneMgr-&gt;createLight("Light")-&gt;setPosition(75,75,75); // Physics // As a test we want a floor plane

  • shader in every node. Other option I was thinking was making some helper functions to deal with the simpler cases, which would set some default parameters and would ask only the most basic ones... a shader thing which renders useless most of the animation property in the c++ side ) Also files are required to store the minimum data required to rebuild the mesh, so in smaller meshes or meshes without... GEOMETRYFRAME_DATA** ppGeometryFrames; // Store here the pointers to the buffer data? } then probably: struct GEOMETRYFRAME_DATA { float fTime; // or uint or whatever UINT nBufferCount

Data information