c – 气质ID3D10EffectVectorVariable

c – 气质ID3D10EffectVectorVariable,第1张

概述我在许多地方以下列方式设置HLSL效果变量. extern ID3D10EffectVectorVariable* pColour;pColour = pEffect->GetVariableByName("Colour")->AsVector();pColour->SetFloatVector(temporaryLines[i].colour); 在其中一个位置设置在循环中,向量temp 我在许多地方以下列方式设置HLSL效果变量.

extern ID3D10EffectVectorVariable* pColour;pColour = pEffect->GetvariableByname("Colour")->Asvector();pColour->SetfloatVector(temporarylines[i].colour);

在其中一个位置设置在循环中,向量temporarylines中的每一行都有一个与之关联的D3DXcolor变量.关于这个问题最烦人的事情是它实际上在极少数情况下有效,但大部分时间它没有.这种代码有任何已知问题吗?

在这里工作:

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 displayUINT 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 matrixD3DXMatrixScaling(&matScale,scale.x,scale.y,scale.z);// create a rotation matrixD3DXMatrixRotationYawPitchRoll(&matRotate,rotation.y,rotation.x,rotation.z);// create a position matrixD3DXMatrixTranslation(&matTranslation,position.x,position.y,position.z);// combine the matrices and rendermatFinal =     matScale        *     matRotate       *     matTranslation  *     matVIEw * matProjection;ptransform->SetMatrix(&matFinal._11); pRotation->SetMatrix(&matRotate._11);    // set the rotation matrix in the effectpPass->Apply(0);device->DrawIndexed(mesh.Indices(),0);   //input specific}

这里偶尔有效:

voID BatchlineRenderer::Renderlines(D3DXMATRIX matVIEw,D3DXMATRIX matProjection){device->IASetinputLayout(pVertexLayout);device->IASetPrimitivetopology(D3D10_PRIMITIVE_topolOGY_linesTRIP);// select which vertex buffer and index buffer to displayUINT strIDe = sizeof(liNE);UINT offset = 0;device->IASetVertexBuffers(0,&pBuffer,&offset);device->IASetIndexBuffer(iBuffer,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);}temporarylines.clear();}

效果文件:

float4x4 transform;    // a matrix to store the transformfloat4x4 Rotation;     // a matrix to store the rotation transformfloat4   lightVec   = {0.612f,0.3535f,0.612f,0.0f};    // the light's vectorfloat4   lightCol   = {1.0f,1.0f,1.0f};    // the light's colorfloat4   AmbIEntCol = {0.3f,0.3f,1.0f};    // the ambIEnt light's colorfloat4   Colour;// a struct for the vertex shader return valuestruct VSOut{    float4 Col : color;    // vertex normal    float4 Pos : SV_position;    // vertex screen coordinates};// the vertex shaderVSOut 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 shaderfloat4 PS(float4 Col : color) : SV_TARGET{    return Col;    // set the pixel color to the color passed in by the Rasterizer Stage}// the primary techniquetechnique10 Technique_0{    // the primary pass    pass Pass_0    {        SetVertexShader(CompileShader(vs_4_0,VS()));        SetGeometryShader(NulL);        SetPixelShader(CompileShader(ps_4_0,PS()));    }}
解决方法 所以color HLSL变量尚未在ConstantBuffer中定义,只是普通的着色器变量.
也许变量应该定义在Constant buffer,每帧updateblae?类似于应该如何定义世界和视图矩阵.至少GPU知道每次渲染时都要更新颜色变量. (因为您在绘制之前更新了值).

cbuffer cbChangesEveryFrame{    //The MVP matrices.    matrix World;    matrix VIEw;    float4   Colour;}

我要考虑的另一点是每次在绘制调用(或通过循环)之前获取指向技术desc的指针,
并没有重复使用它,似乎也有所作为.

//Initiate the pass through loop for the shader effect.technique->GetDesc(&desc);for (UINT p=0; p<desc.Passes; p++){    //Apply this pass through.    technique->getpassByIndex(p)->Apply(0);    //draw indexed,instanced.    device->device->DrawIndexedInstanced(indicesCount,(UINT) instanceCount,0);}
总结

以上是内存溢出为你收集整理的c – 气质ID3D10EffectVectorVariable全部内容,希望文章能够帮你解决c – 气质ID3D10EffectVectorVariable所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1229961.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存