// 2007/08/03 Hiroyuki Ogasawara // vim:ts=4 sw=4: // Cube // バッファ無しに Cube を自分で生成して描画するシェーダー // // http://flatlib.main.jp/dench/ // http://ch09144.kitaguni.tv/ float4x4 WorldToView; float4x4 Projection; struct GS_OUTPUT { float4 Pos : SV_POSITION; float3 Normal : NORMAL; }; float3 VS_Main( uint id : SV_VertexID, uint sid : SV_InstanceID ) : POSITION { uint _map[]= { 101733320, 104889305, 56280874, 125360034, }; id= _map[id&3]>>(((id&60)>>2)*3); float3 pos; pos.x= id & 1 ? 1 : -1; pos.y= id & 2 ? -1 : 1; pos.z= id & 4 ? 1 : -1; float2 ss; sincos( sid * 0.5236f, ss.x, ss.y ); pos.xy+= ss * 5; return mul( float4( pos, 1 ), WorldToView ).xyz; } [maxvertexcount(3)] void GS_Main( triangle float3 In[3] : POSITION, inout TriangleStream gsstream ) { float3 normal= normalize( cross( In[1]-In[0], In[2]-In[0] ) ); GS_OUTPUT op; op.Pos= mul( float4( In[0], 1 ), Projection ); op.Normal= normal; gsstream.Append( op ); op.Pos= mul( float4( In[1], 1 ), Projection ); gsstream.Append( op ); op.Pos= mul( float4( In[2], 1 ), Projection ); gsstream.Append( op ); gsstream.RestartStrip(); } float4 PS_Main( GS_OUTPUT In ) : SV_Target { float color= saturate( dot(normalize(In.Normal), float3(0, 0, -1) )+0.2 ); return float4( color.xxx, 1 ); } technique10 Main { pass P0 { SetVertexShader( CompileShader( vs_4_0, VS_Main() ) ); SetGeometryShader( CompileShader( gs_4_0, GS_Main() ) ); SetPixelShader( CompileShader( ps_4_0, PS_Main() ) ); } }