- 2007/06/07 19:37
- 未分類
多分一番シンプルなlambertシェーダ。
本に載ってたサンプルだといらんことをたくさんやってて、
結局いろいろそぎ落としていったらこうなった。
どうやって調べていいものかわかんないものが多くて困った。
セマンティックって何よ、、
以下、コード。
———————————————————–
// un-tweakables //
float4x4 wvp : WorldViewProjection;
// tweakables //
float4 diffuse : DIFFUSE = { 0.5f, 0.5f, 0.5f, 1.0f };
float4 ambient : AMBIENT = { 0.1f, 0.1f, 0.1f, 1.0f };
float4 lightPos : Position
<
string Object = "PointLight";
string Space = "World";
> = { 100.0f, 100.0f, 100.0f, 0.0f };
struct VIN
{
float4 position : POSITION;
float4 normal : NORMAL;
};
struct VOUT
{
float4 diffuse : COLOR0;
float4 position : POSITION;
};
VOUT easyVtx( VIN vin )
{
float4 lightvec = normalize( lightPos – vin.position );
float4 illumination = max( dot( vin.normal, lightvec ), 0 );
VOUT vout;
vout.diffuse = ambient + diffuse * illumination;
vout.position = mul( wvp, vin.position );
return vout;
}
float4 fragment( VOUT vin ) : COLOR
{
return vin.diffuse;
}
technique SimpleLambert
{
pass
{
VertexProgram = compile arbvp1 easyVtx();
FragmentProgram = compile arbfp1 fragment();
DepthTestEnable = true;
DepthMask = true;
DepthFunc = LEqual;
}
}
———————————————————–
慣れてきたら結構楽しく使える道具、って感じかもね。
まだ自由には使えないけど。
つーか行列変換とかよくわかんなくて困った。
まぁでも全部覚える必要はないか。
とりあえずは使い方わかってて、道具として使えればOK。
- Newer: [ Cg ] texture
- Older: [ movie ] おはなしの花
Comments:0
Trackbacks:0
- Trackback URL for this entry
- http://blog.taikomatsu.com/2007/06/07/cg-lambert/trackback/
- Listed below are links to weblogs that reference
- [ Cg ] lambert from memlog