我有以下.fx
文件:
Texture2D texture2d;
SamplerState linearSampler
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};
struct VS_IN
{
float4 pos : POSITION;
float3 uvq : TEXCOORD0;
};
struct PS_IN
{
float4 pos : SV_POSITION;
float3 uvq : TEXCOORD0;
};
PS_IN VS(VS_IN input)
{
PS_IN output = (PS_IN)0;
output.pos = float4(input.pos.xyz, 1.0);
output.uvq = input.uvq;
return output;
}
float4 PS(PS_IN input) : SV_Target
{
return texture2d.Sample(linearSampler, input.uvq.xy);
}
technique10 Render
{
pass P0
{
SetVertexShader(CompileShader(vs_4_0, VS()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(ps_4_0, PS()));
}
}
(注意:uvq
有float3
,原因是q
稍后会被使用,但现在却被忽略了。
当我使用这个效果来纹理贴图四边形(纹理图像在左边)时,我得到了正确的渲染:像素来自纹理,但它们很奇怪地采样并以条纹重复。
坐标没有什么特别的,完整的纹理:
public Vertex[] vertices = {
new Vertex() { Position = new D3.Vector4F(-0.7f, -0.5f, 0, 0), UVQ = new D3.Vector3F(0f, 1f, 0) },
new Vertex() { Position = new D3.Vector4F(-0.4f, 0.6f, 0, 0), UVQ = new D3.Vector3F(0f, 0f, 0) },
new Vertex() { Position = new D3.Vector4F( 0.5f, -0.5f, 0, 0), UVQ = new D3.Vector3F(1f, 1f, 0) },
new Vertex() { Position = new D3.Vector4F( 0.3f, 0.9f, 0, 0), UVQ = new D3.Vector3F(1f, 0f, 0) },
};
使用TextureLoader.cs
辅助例程读取纹理,因为它们出现在Code Pack API教程中。
var TextureVariable = DxEffect.GetVariableByName("texture2d").AsShaderResource;
var stream = Application.GetResourceStream(MakePackUri("Resources/image.png"));
TextureVariable.Resource = DXUtil.TextureLoader.LoadTexture(DxDevice, stream.Stream);
输入布局如下:
var layout = new D3D.InputElementDescription[] {
new D3D.InputElementDescription() { SemanticName = "POSITION", SemanticIndex = 0, Format = GX.Format.R32G32B32A32Float, AlignedByteOffset = 0, InputSlot = 0, InputSlotClass = D3D.InputClassification.PerVertexData, InstanceDataStepRate = 0 },
new D3D.InputElementDescription() { SemanticName = "TEXCOORD", SemanticIndex = 0, Format = GX.Format.R32G32B32Float, AlignedByteOffset = 16, InputSlot = 0, InputSlotClass = D3D.InputClassification.PerVertexData, InstanceDataStepRate = 0 }
};
var DxPassDesc = DxTechnique.GetPassByIndex(0).Description;
var DxLayout = DxDevice.CreateInputLayout(layout, DxPassDesc.InputAssemblerInputSignature, DxPassDesc.InputAssemblerInputSignatureSize);
DxDevice.IA.InputLayout = DxLayout;
var vertex = new VertexArray();
var DxVertexBufferDescription = new D3D.BufferDescription() { BindingOptions = D3D.BindingOptions.VertexBuffer, CpuAccessOptions = D3D.CpuAccessOptions.None, MiscellaneousResourceOptions = D3D.MiscellaneousResourceOptions.None, Usage = D3D.Usage.Default, ByteWidth = (uint)Marshal.SizeOf(vertex) };
IntPtr vertexData = Marshal.AllocCoTaskMem(Marshal.SizeOf(vertex));
Marshal.StructureToPtr(vertex, vertexData, false);
var DxVertexBufferInitData = new D3D.SubresourceData() { SystemMemory = vertexData, SystemMemoryPitch = 0, SystemMemorySlicePitch = 0 };
var DxVertices = DxDevice.CreateBuffer(DxVertexBufferDescription, DxVertexBufferInitData);
uint stride = (uint)Marshal.SizeOf(typeof(Vertex));
uint offset = 0;
DxDevice.IA.SetVertexBuffers(0, new D3D.D3DBuffer[] { DxVertices }, new uint[] { stride }, new uint[] { offset });
Marshal.FreeCoTaskMem(vertexData);
答案 0 :(得分:0)
解决。最大纹理大小似乎是512(虽然MS的描述似乎表明DX10 Texture2D的值更大)。嗯......