游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2587|回复: 3

问个有关HLSL的问题.纹理为什么贴不上去?

[复制链接]

2

主题

14

帖子

14

积分

新手上路

Rank: 1

积分
14
发表于 2007-9-9 12:36:00 | 显示全部楼层 |阅读模式
用C#写的程序.
test.fx文件的部分.东西是看网络上的教程写的......不知道对不对......
--------------------------------------------------------------
float gray;
float4x4 WorldViewProj : WorldViewProjection;
struct VS_OUTPUT
{
    float4 Position   : POSITION;
    float2 TextureUV  : TEXCOORD0;
    float4 Diffuse    : COLOR0;
};
struct VS_INPUT
{
    float4 Position   : POSITION;
    float2 TextureUV  : TEXCOORD0;
    float4 Diffuse    : COLOR0;
};
VS_OUTPUT mainVS(VS_INPUT input)
{
        VS_OUTPUT output;
        output.Position = mul(input.Position, WorldViewProj);
        output.TextureUV = input.TextureUV;
        output.Diffuse = input.Diffuse;
        return output;
}
struct PS_OUTPUT
{
     float4 color : COLOR;
};
PS_OUTPUT mainPS(VS_OUTPUT input)
{
        PS_OUTPUT output;
        output.color = input.Diffuse;
        return output;
}

technique Effect {
        pass p0 {
                VertexShader = compile vs_3_0 mainVS();
                PixelShader = compile ps_3_0 mainPS();
        }
}
=========================================================
Effect.FromFile的部分
---------------------------------------------------------
            string path = "..\\..\\HLSL\\test.fx";
            effect = Effect.FromFile(_Device, path, null, null, ShaderFlags.NotCloneable, null);
            effect.Technique = "Effect";
            effect.SetValue("gray", 1.0f);
=========================================================
DrawPrimitives的部分
这里...没问题吧......
---------------------------------------------------------
                Effect.SetValue("WorldViewProj", worldMatrix * viewMatrix * projMatrix);
                Device.SetTexture(0, texture);
                Device.RenderState.AlphaBlendEnable = true;
                Device.RenderState.SourceBlend = Blend.SourceColor;
                Device.RenderState.DestinationBlend = Blend.DestinationColor | Blend.SourceAlpha;
                Device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;
                Device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
                Device.SetStreamSource(0, vertexBuffer, 0);
                Device.VertexFormat = CustomVertex.PositionColoredTextured.Format;
                int p = Effect.Begin(0);
                for (int i = 0; i < p; i++)
                {
                    Effect.BeginPass(i);
                    Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);
                    Effect.EndPass();
                }
                Effect.End();

[B]
可以显示出矩形了,但是是一片白色.
为什么纹理贴不上去?
[/B][/COLOR]

2

主题

14

帖子

14

积分

新手上路

Rank: 1

积分
14
 楼主| 发表于 2007-9-9 12:44:00 | 显示全部楼层

Re:问个有关HLSL的问题.纹理为什么贴不上去?

先谢谢大家了.菜鸟飘过...

1

主题

149

帖子

149

积分

注册会员

Rank: 2

积分
149
QQ
发表于 2007-9-9 12:49:00 | 显示全部楼层

Re:问个有关HLSL的问题.纹理为什么贴不上去?

你连采样器都没有~``
类似如下做做.
texture ColorMap;//在外面设置effect->SetTexture("ColorMap",myTexture);
sampler ColorSampler = sampler_state
{
        texture = (ColorMap);

        MipFilter = Linear;
        MinFilter = Linear;
        MagFilter = Linear;
       
        AddressU = Wrap;
        AddressV = Wrap;

};

float4 mainPS(VS_OUTPUT input)
{
float4 color=tex2D(ColorSampler,input.TextureUV);
return output;
}

2

主题

14

帖子

14

积分

新手上路

Rank: 1

积分
14
 楼主| 发表于 2007-9-9 14:10:00 | 显示全部楼层

Re:问个有关HLSL的问题.纹理为什么贴不上去?

谢谢.可以了,呵呵,我还要多学学啊.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-25 00:39

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表