游戏开发论坛

 找回密码
 立即注册
搜索
查看: 8885|回复: 21

??technique?pass????????????????

[复制链接]

2

主题

9

帖子

13

积分

新手上路

Rank: 1

积分
13
发表于 2010-11-9 10:02:00 | 显示全部楼层 |阅读模式
?????????????shader?????????????MAX??????shader???????technique?Pass?Script???????????????????????

----------------------------------------------------------------------------------------------------------

string ParamID = "0x000001";        // this string tells 3ds Max to use the DXSAS compiler



float3 EmissiveColor
<
        string UIName = "Color";
        string UIWidget = "Color";
> = {1.0f, 0.0196078f, 0.0196078f };

float3 GlowColor : Emissive
<
        string UIName = "Color";
        string UIWidget = "Color";
> = {1.0f, 0.25098f, 0.25098f };



//----------------------------------

float4x4 wvp : WorldViewProjection;  
//float4x4 worldI : WorldInverse;  


// Render-to-Texture (RTT) glow example. Copyright NVIDIA (provided 'as is'). Adapted from HammerTime.fx in 3dsmax       
float4 ClearColor : DIFFUSE = {0,0,0,1.0};
float ClearDepth
<
        string UIWidget = "none";
> = 1.0;

float Script : STANDARDSGLOBAL
<
        string UIWidget = "none";
        string ScriptClass = "object";
        string ScriptOrder = "standard";
        string ScriptOutput = "color";

        // Call a script in the main technique.
        string Script = "Technique=Technique?Complete;";

> = 0.8;

#define RTT_SIZE 128

float TexelIncrement <
    string UIName = "Texel Stride for Blur";
    string UIWidget = "None";
> = 1.0f / RTT_SIZE;

texture GlowMap1 : RENDERCOLORTARGET
<  
        float2 Dimensions = { RTT_SIZE, RTT_SIZE };
    int MIPLEVELS = 1;
    string format = "X8R8G8B8";
    string UIWidget = "None";
>;

texture GlowMap2 : RENDERCOLORTARGET
<  
        float2 Dimensions = { RTT_SIZE, RTT_SIZE };
    int MIPLEVELS = 1;
    string format = "X8R8G8B8";
    string UIWidget = "None";
>;

sampler GlowSamp1 = sampler_state  
{
    texture = <GlowMap1>;
    AddressU  = CLAMP;
    AddressV  = CLAMP;
    AddressW  = CLAMP;
    MIPFILTER = NONE;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
};

sampler GlowSamp2 = sampler_state  
{
    texture = <GlowMap2>;
    AddressU  = CLAMP;
    AddressV  = CLAMP;
    AddressW  = CLAMP;
    MIPFILTER = NONE;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
};

texture DepthBuffer : RENDERDEPTHSTENCILTARGET
<
        float2 Dimensions = { RTT_SIZE, RTT_SIZE };
    string format = "D24S8";
    string UIWidget = "None";
>;
// input from application
struct a2v {
float4 position : POSITION;
float2 texCoord : TEXCOORD0;
};

// output to fragment program
struct v2f {
float4 position : POSITION;
float2 texCoord : TEXCOORD0;
};

struct VS_OUTPUT_BLUR
{
    float4 Position   : POSITION;
    float4 TexCoord0   : TEXCOORD0;
    float4 TexCoord1   : TEXCOORD1;
    float4 TexCoord2   : TEXCOORD2;
    float4 TexCoord3   : TEXCOORD3;
    float4 TexCoord4   : TEXCOORD4;
    float4 TexCoord5   : TEXCOORD5;
    float4 TexCoord6   : TEXCOORD6;
    float4 TexCoord7   : TEXCOORD7;
    float4 TexCoord8   : COLOR;   
};

struct VS_OUTPUT
{
           float4 Position   : POSITION;
    float4 Diffuse    : COLOR0;
    float4 TexCoord0   : TEXCOORD0;
};

v2f VS(a2v In)
{
    v2f Out = (v2f)0;
    Out.position = mul(In.position, wvp);                                //transform vert position to homogeneous clip space
    return Out;
}

v2f VS_Quad(a2v In, float3 DEFTexCoord : TEXCOORD0)
{
    v2f Out = (v2f)0;
    Out.position = In.position;
    Out.texCoord = DEFTexCoord;  
    return Out;
}

VS_OUTPUT_BLUR VS_Quad_Vertical_9tap(float3 Position : POSITION,  
                        float3 TexCoord : TEXCOORD0)
{
    VS_OUTPUT_BLUR OUT = (VS_OUTPUT_BLUR)0;
    OUT.Position = float4(Position, 1);
     
    float3 Coord = float3(TexCoord.x + TexelIncrement, TexCoord.y + TexelIncrement, 1);
    OUT.TexCoord0 = float4(Coord.x, Coord.y + TexelIncrement, TexCoord.z, 1);
    OUT.TexCoord1 = float4(Coord.x, Coord.y + TexelIncrement * 2, TexCoord.z, 1);
    OUT.TexCoord2 = float4(Coord.x, Coord.y + TexelIncrement * 3, TexCoord.z, 1);
    OUT.TexCoord3 = float4(Coord.x, Coord.y + TexelIncrement * 4, TexCoord.z, 1);
    OUT.TexCoord4 = float4(Coord.x, Coord.y, TexCoord.z, 1);
    OUT.TexCoord5 = float4(Coord.x, Coord.y - TexelIncrement, TexCoord.z, 1);
    OUT.TexCoord6 = float4(Coord.x, Coord.y - TexelIncrement * 2, TexCoord.z, 1);
    OUT.TexCoord7 = float4(Coord.x, Coord.y - TexelIncrement * 3, TexCoord.z, 1);
    OUT.TexCoord8 = float4(Coord.x, Coord.y - TexelIncrement * 4, TexCoord.z, 1);
    return OUT;
}

VS_OUTPUT_BLUR VS_Quad_Horizontal_9tap(float3 Position : POSITION,  
                        float3 TexCoord : TEXCOORD0)
{
    VS_OUTPUT_BLUR OUT = (VS_OUTPUT_BLUR)0;
    OUT.Position = float4(Position, 1);
     
    float3 Coord = float3(TexCoord.x + TexelIncrement, TexCoord.y + TexelIncrement, 1);
    OUT.TexCoord0 = float4(Coord.x + TexelIncrement, Coord.y, TexCoord.z, 1);
    OUT.TexCoord1 = float4(Coord.x + TexelIncrement * 2, Coord.y, TexCoord.z, 1);
    OUT.TexCoord2 = float4(Coord.x + TexelIncrement * 3, Coord.y, TexCoord.z, 1);
    OUT.TexCoord3 = float4(Coord.x + TexelIncrement * 4, Coord.y, TexCoord.z, 1);
    OUT.TexCoord4 = float4(Coord.x, Coord.y, TexCoord.z, 1);
    OUT.TexCoord5 = float4(Coord.x - TexelIncrement, Coord.y, TexCoord.z, 1);
    OUT.TexCoord6 = float4(Coord.x - TexelIncrement * 2, Coord.y, TexCoord.z, 1);
    OUT.TexCoord7 = float4(Coord.x - TexelIncrement * 3, Coord.y, TexCoord.z, 1);
    OUT.TexCoord8 = float4(Coord.x - TexelIncrement * 4, Coord.y, TexCoord.z, 1);
    return OUT;
}

// map the glow-mask texture to the screen - no lighting
// this shader will draw to a texture
float4 PS_BlurBuffer(v2f In) : COLOR
{   
        float4 Col = float4(1,1,1,1);

        float3 input2 = GlowColor.rgb;

        Col = float4(input2.rgb, 1);
        Col *= float4(1,1,1,1);
        return Col;
}   

// For two-pass blur, we have chosen to do  the horizontal blur FIRST. The
//        vertical pass includes a post-blur scale factor.

// Relative filter weights indexed by distance from 'home' texel
//    This set for 9-texel sampling
#define WT9_0 1.0
#define WT9_1 0.8
#define WT9_2 0.6
#define WT9_3 0.4
#define WT9_4 0.2
#define WT9_NORMALIZE (WT9_0+2.0*(WT9_1+WT9_2+WT9_3+WT9_4))

float4 PS_Blur_Horizontal_9tap(VS_OUTPUT_BLUR IN) : COLOR
{   
    float4 OutCol = (float4)0;
    OutCol += tex2D(GlowSamp1, IN.TexCoord0.xy) * (WT9_1/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp1, IN.TexCoord1.xy) * (WT9_2/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp1, IN.TexCoord2.xy) * (WT9_3/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp1, IN.TexCoord3.xy) * (WT9_4/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp1, IN.TexCoord4.xy) * (WT9_0/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp1, IN.TexCoord5.xy) * (WT9_1/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp1, IN.TexCoord6.xy) * (WT9_2/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp1, IN.TexCoord7.xy) * (WT9_3/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp1, IN.TexCoord8.xy) * (WT9_3/WT9_NORMALIZE);
    return OutCol;
}  

float4 PS_Blur_Vertical_9tap(VS_OUTPUT_BLUR IN, v2f In) : COLOR
{   
    float4 OutCol = (float4)0;
    OutCol += tex2D(GlowSamp2, IN.TexCoord0.xy) * (WT9_1/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp2, IN.TexCoord1.xy) * (WT9_2/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp2, IN.TexCoord2.xy) * (WT9_3/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp2, IN.TexCoord3.xy) * (WT9_4/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp2, IN.TexCoord4.xy) * (WT9_0/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp2, IN.TexCoord5.xy) * (WT9_1/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp2, IN.TexCoord6.xy) * (WT9_2/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp2, IN.TexCoord7.xy) * (WT9_3/WT9_NORMALIZE);
    OutCol += tex2D(GlowSamp2, IN.TexCoord8.xy) * (WT9_3/WT9_NORMALIZE);
    return OutCol;
}  

// just drawn model itself

float4 PS_MODEL(v2f In) : COLOR
{
        float4 Col = float4(0,0,0,1);

        float3 input1 = EmissiveColor.rgb;

        Col =  float4(input1, 1);
        return Col;
}   

// add glow on top of model

float4 PS_GlowPass(VS_OUTPUT IN) : COLOR
{
        float4 tex = tex2D(GlowSamp1, float2(IN.TexCoord0.x, IN.TexCoord0.y));
        return tex;
}   

technique Complete  
<
        string Script =
                        "ClearSetColor=ClearColor;"
                        "ClearSetDepth=ClearDepth;"
                        &quotass=BlurPass;"               
                "Pass=BlurGlowBuffer_Horz;"
                "Pass=BlurGlowBuffer_Vert;"
                "Pass=ModelPass1;"
                "Pass=GlowPass;";

>          
{

        pass BlurPass
        <
            string Script = "RenderColorTarget0=GlowMap1;"
            "RenderDepthStencilTarget=DepthBuffer;"
                "Clear=Color;"
                "Clear=Depth;"
                "Draw=Geometry;";
        >
        {
                CullMode = none;
                ZEnable = true;         
        VertexShader = compile vs_3_0 VS();
        PixelShader = compile ps_3_0 PS_BlurBuffer();
        }
       

    pass BlurGlowBuffer_Horz  
    <  
            string Script ="RenderColorTarget0=GlowMap2;"
            "RenderDepthStencilTarget=DepthBuffer;"
                "Clear=Color;"
                "Clear=Depth;"
                "Draw=Buffer;";
    >
        {
                CullMode = none;
                ZEnable = false;
                VertexShader = compile vs_3_0 VS_Quad_Horizontal_9tap();
                PixelShader  = compile ps_3_0 PS_Blur_Horizontal_9tap();
    }

    pass BlurGlowBuffer_Vert  
     <
            string Script = "RenderColorTarget0=GlowMap1;"
            "RenderDepthStencilTarget=DepthBuffer;"
                "Clear=Color;"
                "Clear=Depth;"
                "Draw=Buffer;";
    >
        {
                CullMode = none;
                ZEnable = false;
                VertexShader = compile vs_3_0 VS_Quad_Vertical_9tap();
                PixelShader  = compile ps_3_0 PS_Blur_Vertical_9tap();
    }


    pass ModelPass1
    <
           string Script= "RenderColorTarget0=;"
                                                "Draw=Geometry;";
    >
    {
        AlphaBlendEnable = false;
                AlphaTestEnable = FALSE;
                CullMode = cw;
                ZEnable = true;
                VertexShader = compile vs_3_0 VS();
                PixelShader = compile ps_3_0 PS_MODEL();
    }
       
    pass GlowPass
    <
               string Script= "RenderColorTarget0=;"
                "Draw=Buffer;";                 
        >
    {
                CullMode = none;
                ZEnable = false;
                ZWriteEnable = false;
                AlphaBlendEnable = true;
                SrcBlend = One;
                DestBlend = One;
                AlphaTestEnable = FALSE;
                VertexShader = compile vs_3_0 VS_Quad();         
                PixelShader = compile ps_3_0 PS_GlowPass();         
    }
       
}   
------------------------------------------------------------------------------------------------
??????????????????????????????DX?SDK?????????Script???????????
string Script= "RenderColorTarget0=;"
"Draw=Buffer;";
string Script= "RenderColorTarget0=;"
"Draw=Geometry;";
string Script = "RenderColorTarget0=GlowMap1;"
"RenderDepthStencilTarget=DepthBuffer;"
"Clear=Color;"
"Clear=Depth;"
"Draw=Buffer;";
string Script =
"ClearSetColor=ClearColor;"
"ClearSetDepth=ClearDepth;"
"Pass=BlurPass;"               
"Pass=BlurGlowBuffer_Horz;"
"Pass=BlurGlowBuffer_Vert;"
"Pass=ModelPass1;"
"Pass=GlowPass;";


???????????????????????????technique?pass???????
texture DepthBuffer : RENDERDEPTHSTENCILTARGET
<
    float2 Dimensions = { RTT_SIZE, RTT_SIZE };
    string format = "D24S8";
    string UIWidget = "None";
>;

texture GlowMap1 : RENDERCOLORTARGET
<  
    float2 Dimensions = { RTT_SIZE, RTT_SIZE };
    int MIPLEVELS = 1;
    string format = "X8R8G8B8";
    string UIWidget = "None";
>;

float Script : STANDARDSGLOBAL
<
        string UIWidget = "none";
        string ScriptClass = "object";
        string ScriptOrder = "standard";
        string ScriptOutput = "color";

        // Call a script in the main technique.
        string Script = "Technique=Technique?Complete;";

> = 0.8;

59

主题

984

帖子

1200

积分

金牌会员

Rank: 6Rank: 6

积分
1200
发表于 2010-11-9 16:20:00 | 显示全部楼层

Re:??technique?pass????????????????

annotation?????shader???????shader???????????

2

主题

9

帖子

13

积分

新手上路

Rank: 1

积分
13
 楼主| 发表于 2010-11-9 18:01:00 | 显示全部楼层

Re:??technique?pass????????????????

???????????? RENDERCOLORTARGET ??????????????pass?"RenderColorTarget0=GlowMap1;" ???pass?"RenderColorTarget0=;" ?

"Draw=Geometry;"; ???????????pass?"Draw=Buffer;"; ?

clear=color ? clear=Buffer??????

"ClearSetColor=ClearColor;" ?"ClearSetDepth=ClearDepth;"??????


float Script : STANDARDSGLOBAL ???????????????????????????0.8?

texture DepthBuffer : RENDERDEPTHSTENCILTARGET ?????????????????technique??????????????

?????????????????????????shader?????????????????????

0

主题

22

帖子

32

积分

注册会员

Rank: 2

积分
32
发表于 2010-11-9 19:27:00 | 显示全部楼层

Re:??technique?pass????????????????

RENDERCOLORTARGET???????
RenderColorTarget0=GlowMap1???????GlowMap1?
RenderColorTarget0=;???????????????????

59

主题

984

帖子

1200

积分

金牌会员

Rank: 6Rank: 6

积分
1200
发表于 2010-11-10 01:11:00 | 显示全部楼层

Re:??technique?pass????????????????

?????????????????....

1. annotation??????????semantic?shader?????????????????shader???
texture GlowMap1 : RENDERCOLORTARGET
<  
float2 Dimensions = { RTT_SIZE, RTT_SIZE };
    int MIPLEVELS = 1;
    string format = "X8R8G8B8";
    string UIWidget = "None";
>;
?
texture GlowMap1?
?????

2. ?directx?effect??????????GetSemantic?GetAnnotation???????semantic?Annotation?????????????

3. semantic?annotaion??????????shader???????????
????????pass?annotation?????clear=color ? clear=Buffer????????????????pass?????clear backbuffer?depthbuffer?

4. semantic?annotation??????????
????max??clear=color????clear backbuffer????????????????clear = backbuffer?HLSL?????annotation????????????*??*??annotation???
a. ??annotation??????????????annotation???????????3d max?maya??fx composer?????????????????????????????????????annotation?????????????????
b. ??????????shader??annotation??????????????annotation???????????shader??????????????



11

主题

80

帖子

146

积分

注册会员

Rank: 2

积分
146
发表于 2010-11-10 09:07:00 | 显示全部楼层

Re: ??technique?pass????????????????

?????shader?????

2

主题

9

帖子

13

积分

新手上路

Rank: 1

积分
13
 楼主| 发表于 2010-11-10 14:54:00 | 显示全部楼层

Re: Re:??technique?pass????????????????

clayman: Re:??technique?pass????????????????

?????????????????....

1. annotation??????????semantic?shader?????...


?????clayman???????????????[em6]?????????????TheCompleteEffectandHLSLGuide????????????????
??????????????????script?????shader???????3DMAX????????????????????????????????????MAX?Virtools?shader??????????????????????DX????????????????????????????MAX?SDK??????script????????????????DX?SDK??????????

2

主题

9

帖子

13

积分

新手上路

Rank: 1

积分
13
 楼主| 发表于 2010-11-10 14:58:00 | 显示全部楼层

Re:??technique?pass????????????????

???????????????????shader???????????????????????????

2

主题

9

帖子

13

积分

新手上路

Rank: 1

积分
13
 楼主| 发表于 2010-11-10 15:18:00 | 显示全部楼层

Re: Re: ??technique?pass????????????????

like_new1: Re: ??technique?pass????????????????

?????shader?????


???????????

??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????MAX????????????????????

??????????????????????BUG??????????????????????????????????????????????????????????????????????????????????????????????????????3D??????????????DX???shader???????????????????????????????????????????????????????????????????????????

0

主题

228

帖子

285

积分

中级会员

Rank: 3Rank: 3

积分
285
发表于 2010-11-10 20:36:00 | 显示全部楼层

Re:??technique?pass????????????????

LZ?????????????????????????
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-10-13 11:00

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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