游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3257|回复: 9

用shader进行渲染怎么做alpha,谢谢!

[复制链接]

7

主题

34

帖子

34

积分

注册会员

Rank: 2

积分
34
发表于 2007-12-26 10:57:00 | 显示全部楼层 |阅读模式
RT

7

主题

34

帖子

34

积分

注册会员

Rank: 2

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

Re:用shader进行渲染怎么做alpha,谢谢!

每人回答吗?

5

主题

755

帖子

757

积分

高级会员

Rank: 4

积分
757
发表于 2007-12-26 14:15:00 | 显示全部楼层

Re:用shader进行渲染怎么做alpha,谢谢!

什么alhpa.通道。还是color的 a分量。拿alpha干嘛。你都不说清楚。怎么知道怎么回答你

7

主题

34

帖子

34

积分

注册会员

Rank: 2

积分
34
 楼主| 发表于 2007-12-26 16:44:00 | 显示全部楼层

Re:用shader进行渲染怎么做alpha,谢谢!

比如说我先渲染了terrain(shader)不透明,上面再渲染一个透明的物体(用shader)?shader中color的a分量已经设置了,渲染状态的alpha blend也开了,但是没用!

5

主题

755

帖子

757

积分

高级会员

Rank: 4

积分
757
发表于 2007-12-26 17:34:00 | 显示全部楼层

Re:用shader进行渲染怎么做alpha,谢谢!

代码给来看看

7

主题

34

帖子

34

积分

注册会员

Rank: 2

积分
34
 楼主| 发表于 2007-12-27 09:53:00 | 显示全部楼层

Re:用shader进行渲染怎么做alpha,谢谢!


//------------------------
// vs

float4x4 matWorldViewProj;
float4 layer_speed = {0.68753, 0.52, 0.7534, 1};
float time_0_X;


struct VS_OUTPUT
{
   float4 Pos       : POSITION;
   float2 TexCoord0 : TEXCOORD0;
   float2 TexCoord1 : TEXCOORD1;
   float2 TexCoord2 : TEXCOORD2;
   float2 TexCoord3 : TEXCOORD3;
};

VS_OUTPUT vs_main (float3 vPosition: POSITION, float2 vTexCoord0 : TEXCOORD0)
{
   VS_OUTPUT Out = (VS_OUTPUT) 0;

   // Align quad with the screen
   Out.Pos = mul( float4(vPosition, 1), matWorldViewProj );
   //Out.Pos = float4 (vPosition.x, vPosition.y, 0.0f, 1.0f);

   // Output TexCoord0 directly
   Out.TexCoord0 = vTexCoord0;

   // Base texture coordinates plus scaled time
   Out.TexCoord1.x = vTexCoord0.x;
   Out.TexCoord1.y = vTexCoord0.y + layer_speed.x * time_0_X;
   // Base texture coordinates plus scaled time
   Out.TexCoord2.x = vTexCoord0.x;
   Out.TexCoord2.y = vTexCoord0.y + layer_speed.y * time_0_X;

   // Base texture coordinates plus scaled time
   Out.TexCoord3.x = vTexCoord0.x;
   Out.TexCoord3.y = vTexCoord0.y + layer_speed.z * time_0_X;

   return Out;
}

//-------------------------
// ps

float distortion_amount2 = 0.0723;
float distortion_amount1 = 0.091;
float distortion_amount0 = 0.123;
float4 height_attenuation = {0.44, 0.29, 0, 1};

texture tex_base;
texture tex_distortion;
texture tex_opacity;

sampler fire_base = sampler_state
{
        Texture = <tex_base>;
        MinFilter = Point;
        MagFilter = Point;
        MipFilter = None;
        AddressU  = Wrap;
        AddressV  = Wrap;
};

sampler fire_distortion = sampler_state
{
        Texture = <tex_distortion>;
        MinFilter = Point;
        MagFilter = Point;
        MipFilter = None;
        AddressU  = Wrap;
        AddressV  = Wrap;
};

sampler fire_opacity = sampler_state
{
        Texture = <tex_opacity>;
        MinFilter = Point;
        MagFilter = Point;
        MipFilter = None;
        AddressU  = Wrap;
        AddressV  = Wrap;
};

// Bias and double a value to take it from 0..1 range to -1..1 range
float4 bx2(float x)
{
   return 2.0f * x - 1.0f;
}

float4 ps_main (float2 tc0 : TEXCOORD0, float2 tc1 : TEXCOORD1,
             float2 tc2 : TEXCOORD2, float2 tc3 : TEXCOORD3) : COLOR
{
   // Sample noise map three times with different texture coordinates
   float4 noise0 = tex2D(fire_distortion, tc1);
   float4 noise1 = tex2D(fire_distortion, tc2);
   float4 noise2 = tex2D(fire_distortion, tc3);

   // Weighted sum of signed noise
   float2 noiseSum = bx2(noise0.r) * distortion_amount0 + bx2(noise1.r) * distortion_amount1 + bx2(noise2.r) * distortion_amount2;

   

   // Perturb base coordinates in direction of noiseSum as function of height (y)
   float2 perturbedBaseCoords = saturate(tc0 + noiseSum * (tc0.y * height_attenuation.x + height_attenuation.y));

   // Sample base and opacity maps with perturbed coordinates
   float4 base = tex2D(fire_base, perturbedBaseCoords);
   float4 opacity = tex2D(fire_opacity, tc0);

        //return float4(1, 1,1,1);
        base.a = 0;
   return base * opacity;
}



technique my_tech
{
        pass Fire
        {
                //PixelShader  = NULL;        
                //Texture[0] = NULL;

                // enable alpha blending
            /*AlphaBlendEnable = TRUE;
            AlphaTestEnable = TRUE;
        SrcBlend         = SRCCOLOR;
        DestBlend        = INVSRCCOLOR;*/
        
        // set up texture stage states to use the diffuse color
        //ColorOp[0]   = SELECTARG2;
        //ColorArg2[0] = DIFFUSE;
        //AlphaOp[0]   = SELECTARG2;
        //AlphaArg2[0] = DIFFUSE;

        //ColorOp[1]   = DISABLE;
        //AlphaOp[1]   = DISABLE;


                CullMode = None;
                VertexShader = compile vs_2_0 vs_main();
                PixelShader  = compile ps_2_0 ps_main();
        }
}

5

主题

755

帖子

757

积分

高级会员

Rank: 4

积分
757
发表于 2007-12-27 10:42:00 | 显示全部楼层

Re:用shader进行渲染怎么做alpha,谢谢!

base.a = 0;不是完全透明了。代码太长了。懒得看完。你改一下这个base.a = 别的试试。

18

主题

279

帖子

279

积分

中级会员

Rank: 3Rank: 3

积分
279
QQ
发表于 2007-12-27 10:56:00 | 显示全部楼层

Re:用shader进行渲染怎么做alpha,谢谢!

描述一下你渲染出来的状态吧。

8

主题

390

帖子

390

积分

中级会员

Rank: 3Rank: 3

积分
390
发表于 2007-12-27 13:37:00 | 显示全部楼层

Re:用shader进行渲染怎么做alpha,谢谢!

不管用不用shader,透明物体必须排序,并在不透明物体之后渲染。无其他投机方法。

7

主题

34

帖子

34

积分

注册会员

Rank: 2

积分
34
 楼主| 发表于 2007-12-27 17:36:00 | 显示全部楼层

Re:用shader进行渲染怎么做alpha,谢谢!

Texture[0] = NULL;
ZEnable = TRUE;
AlphaBlendEnable = true;
AlphaTestEnable = true;
SrcBlend         = SRCCOLOR;
DestBlend        = INVSRCCOLOR;
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-6-18 06:38

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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