游戏开发论坛

 找回密码
 立即注册
搜索
查看: 4200|回复: 12

想了解一下用cubic environment map实现单位向量的查找.

[复制链接]

65

主题

518

帖子

521

积分

高级会员

Rank: 4

积分
521
发表于 2005-3-17 18:48:00 | 显示全部楼层 |阅读模式
在玩过Thief 3 Deadly shadows之后,翻找其文件目录,发现这样一个贴图:
normalize.dds
sf_2005317184837.bmp

65

主题

518

帖子

521

积分

高级会员

Rank: 4

积分
521
 楼主| 发表于 2005-3-17 18:53:00 | 显示全部楼层

Re:想了解一下用cubic environment map实现单位向量的查找.

我猜想它可能是为那些pixel shader版本在2.0以下的显卡用作normalized向量查找的.
可不知道使用细节,有这方面经历的给支个招吧. 谢谢.

6

主题

444

帖子

457

积分

中级会员

Rank: 3Rank: 3

积分
457
发表于 2005-3-17 20:33:00 | 显示全部楼层

Re:想了解一下用cubic environment map实现单位向量的查找.

cube map取样就是只和取样坐标(u,v,w)表示的方向相关的,比如(1,2,3)和(2,4,6)取同一个texel。
所以,假如texel(u,v,w) = normalize(u,v,w)*0.5+0.5,则texcube(u,v,w)_bx2 = normalize(u,v,w)

65

主题

518

帖子

521

积分

高级会员

Rank: 4

积分
521
 楼主| 发表于 2005-3-19 15:42:00 | 显示全部楼层

Re:想了解一下用cubic environment map实现单位向量的查找.

给个cubic enviroment map查找点光照光向量的shader的例子代码吧.

46

主题

281

帖子

313

积分

中级会员

Rank: 3Rank: 3

积分
313
QQ
发表于 2005-3-19 16:45:00 | 显示全部楼层

Re:想了解一下用cubic environment map实现单位向量的查找.

http://www.ati.com/developer/Treasurechest.html

65

主题

518

帖子

521

积分

高级会员

Rank: 4

积分
521
 楼主| 发表于 2005-3-19 22:54:00 | 显示全部楼层

Re:想了解一下用cubic environment map实现单位向量的查找.

楼上贴出的例子我下了,谢谢.
看了它的shader,用asm写的.看得不太明白.(我是从HLSL开始学的)
里面对转到tangent space的光向量在vs里给当作texcoord输出了.
那么在ps里它是以什么类型的sampler在哪张贴图上采样的呢?
我翻了他的目录,楞没找到与normalized有关的贴图,能给讲解一下吗?谢了!

46

主题

281

帖子

313

积分

中级会员

Rank: 3Rank: 3

积分
313
QQ
发表于 2005-3-19 23:08:00 | 显示全部楼层

Re:想了解一下用cubic environment map实现单位向量的查找.

例子中normalizer贴图都是程序生成的,看CNormalizerMap8::Function,和D3DXFillTexture。
texld r1, t0就是用0号坐标到1号贴图里采样。

65

主题

518

帖子

521

积分

高级会员

Rank: 4

积分
521
 楼主| 发表于 2005-3-19 23:52:00 | 显示全部楼层

Re:想了解一下用cubic environment map实现单位向量的查找.

在HLSL中相当于用samplerCUBE在texCUBE()中采样,还是用普通的sampler呢?
我对cubic mapping不太理解,刚才改了shader,还是错的.

65

主题

518

帖子

521

积分

高级会员

Rank: 4

积分
521
 楼主| 发表于 2005-3-19 23:56:00 | 显示全部楼层

Re:想了解一下用cubic environment map实现单位向量的查找.

用CNormalizerMap8::Function,和D3DXFillTexture生成的normalizer图和上面贴出的
那张是一样的吗?要是一样的话我觉着还是用现成的图方便一点吧.

65

主题

518

帖子

521

积分

高级会员

Rank: 4

积分
521
 楼主| 发表于 2005-3-20 22:11:00 | 显示全部楼层

Re:想了解一下用cubic environment map实现单位向量的查找.

有谁是用effect edit写shader的?
我贴一下这个shader,大家给看看问题出哪了:

struct VS_INPUT
{
    float4    Pos        : POSITION;
    float3    Normal        : NORMAL;
    float3    Tex0        : TEXCOORD0;
    float3    Tangent    : TANGENT;
};

struct VS_OUTPUT
{
    float4    Pos        : POSITION;
    float3    tLight        : COLOR;
    float3    tNormal    : TEXCOORD0;
    float3    tNormalize    : TEXCOORD1;
    //float3    Tex0        : TEXCOORD4;
    float3    tAttenuation    :TEXCOORD2;
    float3    tDist    :TEXCOORD3;
};

// Global Matrices
float4x4    matTotal     : WorldViewProjection;
float4x4    matWorld    : World;

float3        vLight = {0.0f, 0.0f, 0.0f};    // Position of the Omni light
float        range = 80.0f;    // Range of the Omni light

texture        texBasis < string name = "fieldstone.bmp"; >;
texture        texNormalize < string name = "lobbycube.dds" ;>;
texture        texNormal < string name = "fieldstonebumpdot3.tga"; >;
texture        texAtten< string name = "atten.dds"; >;
//texture        texDist< string name = "DistAtten.dds";>;

vector vCPS = {0.0f, 1.0f, -1.0f, 1.0f};
float4 vecEye    :CAMERAPOSITION;
string XFile = "chamber.x";
int    BCLR = 0xffffffff;

VS_OUTPUT    VShader(VS_INPUT i)
{
    VS_OUTPUT    o;
    float3    wNormal, wTangent, wBinormal, tLight;
    float3 aLight;
    float    a;
   
    float4 tPos = mul( i.Pos, matWorld );
    //vLight = mul( vLight, matWorld );
    tLight = tPos - vLight;
    a = clamp( range / length( tLight ), 0, 1.0 );
    aLight = tLight / range;
    tLight = normalize( tLight );
    aLight.xy =  0.5*aLight.xy+0.5 ;
    //aLight.xyz = aLight.xyz;
   
    o.tAttenuation = aLight;
      
    o.tDist = 0.5*(aLight.z)+0.5;
   
  
    o.Pos = mul( i.Pos, matTotal );
    wNormal = mul( i.Normal, matWorld );
    wTangent = mul( i.Tangent, matWorld );

    wBinormal = cross( wTangent, wNormal );

    float3x3    tangentMatrix = { wTangent, wBinormal, wNormal };

    tangentMatrix = transpose( tangentMatrix );
    tLight =  mul( -tLight, tangentMatrix );
    o.tLight = (tLight * 0.5f + 0.5f);

    // Copy UV coordinates
    //o.Tex0 = i.Tex0;
    o.tNormal = i.Tex0;
   
    o.tNormalize = 0.5*normalize(mul(i.Pos,matWorld)-vLight)+0.5;
    return    o;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
uniform sampler    sampler_diffuse = sampler_state
{
    Texture = <texBasis>;
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;
};

uniform sampler    sampler_bump = sampler_state
{
    Texture = <texNormal>;
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;
};

uniform sampler    sampler_Atten = sampler_state
{
    Texture = <texAtten>;
    BORDERCOLOR = 0x00000000;
    AddressU = Border;
    AddressV = Border;
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;   
};

uniform sampler    sampler_Dist = sampler_state
{
    Texture = <texAtten>;
    BORDERCOLOR = 0x00000000;
    ADDRESSU = Border;
    ADDRESSV = Border;
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;
};

uniform samplerCUBE    sampler_Normalize = sampler_state
{
    Texture = <texNormalize>;
   
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Point;
    AddressU = clamp;
    AddressV = clamp;
    AddressW = clamp;
};

struct PS_INPUT
{
    float4    tLight    : COLOR;
    float3    tNormal    : TEXCOORD0;
    float3    Tex0        : TEXCOORD1;
    float3    tAttenuation    : TEXCOORD2;
    float3    tDist    : TEXCOORD3;
    float3    tNormalize    : TEXCOORD1;
};

struct PS_OUTPUT
{
    float4    Col        : COLOR;
};

PS_OUTPUT PShader( PS_INPUT i )
{
    PS_OUTPUT    o;
    float4        t0, Atten, t4;
    float4     t2, t3;
    float3        t1, t5, tLight, aLight;
    float         cosang, sub;

    t0 = tex2D( sampler_diffuse, i.Tex0 );
    t1 = 2 * tex2D( sampler_bump, i.tNormal ) - 1;
    t2 = tex2D( sampler_Atten, i.tAttenuation ) ;
    t3 = tex2D( sampler_Dist, i.tDist );
    t4 = texCUBE( sampler_Normalize, i.tNormalize );
   
    Atten =  1 - t2 - t3;
    tLight = 2 * i.tLight - 1;
    float tmp = dot(tLight,tLight);
    float3 vtmp = tLight*(1-tmp)+tLight;
    tLight = vtmp;
    //tLight = 2 * i.tLight - 1;

    //cosang = saturate( dot( t1, tLight ) ) ;
    cosang = saturate( dot( t1.xyz, t4.xyz ) );
   
    //o.Col = (-Atten-0.1)*cosang+cosang*0.1;
    //o.Col = t0*cosang+saturate(cosang);
    o.Col = t4;
    return    o;
}

technique DiffuseBump
{
    pass P0
    {
        VertexShader = compile vs_1_1 VShader();
        PixelShader = compile ps_1_3 PShader();
        Lighting = false;
        ColorVertex = false;
        ZEnable = true;
        AlphaBlendEnable = false;
        //shademode = flat;
    }
}

我发现若用effect edit里面的Solid fill, no texture功能,渲染出来的是我想要的cubic environment效果,但一用自己的sampler就不对了.为啥?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-12-24 21:39

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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