gpt4 book ai didi

c++ - 气质 ID3D10EffectVectorVariable

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:12:40 26 4
gpt4 key购买 nike

我在很多地方通过以下方式设置了 HLSL 效果变量。

extern ID3D10EffectVectorVariable* pColour;

pColour = pEffect->GetVariableByName("Colour")->AsVector();

pColour->SetFloatVector(temporaryLines[i].colour);

在一个循环中设置它的地方, vector 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 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
}

这里是偶尔的作品:

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();
}

效果文件:

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()));
}
}

最佳答案

所以 Color HLSL 变量并没有在 ConstantBuffer 中定义,只是一个普通的着色器变量。也许变量应该在常量缓冲区中定义,每帧更新一次?类似于世界和 View 矩阵的定义方式。至少 GPU 知道你想在每次渲染时更新颜色变量。 (当您在绘制之前更新值时)。

cbuffer cbChangesEveryFrame
{

//The MVP matrices.
matrix World;
matrix View;
float4 Colour;

}

我要考虑的另一点是每次在绘制调用(或通过循环)之前获取指向技术描述的指针,而不是重用它,似乎也有所作为。

//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, 0, 0);
}

关于c++ - 气质 ID3D10EffectVectorVariable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8636704/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com