появился вопрос по шейдерам: есть два типа источников
1) направленный с конусом ( spot )
2) точечный
как их отрисовывать вместе? первым проходом отрисовать точечные, вторым направленные?
код шейдера отвечающего за освещение
float4x4 mWorldViewProj : MATRIX_WORLDVIEWPROJ;
float4x4 mWorld : MATRIX_WORLD;
#define MAX_LIGHTS 10
float3 lightPos[ MAX_LIGHTS ];
float3 litColor[ MAX_LIGHTS ];
float litDistFactor[ MAX_LIGHTS ];
int litEnabled[ MAX_LIGHTS ];
texture diffuseTexture : TEXTURE_0;
sampler diffuseSampler = sampler_state
{
Texture = <diffuseTexture>;
AddressU = WRAP;
AddressV = WRAP;
AddressW = WRAP;
MinFilter = ANISOTROPIC;
MagFilter = ANISOTROPIC;
MipFilter = ANISOTROPIC;
MaxAnisotropy = 4;
};
struct VSInput
{
float4 pos : POSITION;
float3 normal : NORMAL;
float2 texCoord0 : TEXCOORD0;
};
struct VSOutput
{
float4 pos : POSITION;
float3 normal : TEXCOORD0;
float2 texCoord0 : TEXCOORD1;
float4 pos2 : TEXCOORD2;
};
struct PSInput
{
float3 normal : TEXCOORD0;
float2 texCoord0 : TEXCOORD1;
float4 pos : TEXCOORD2;
};
VSOutput vertexShaderMain( VSInput input )
{
VSOutput output;
output.pos = mul( input.pos, mWorldViewProj );
output.pos2 = mul( input.pos, mWorld );
output.normal = normalize( mul( input.normal, mWorld ));
output.texCoord0 = input.texCoord0;
return output;
};
float4 pixelShaderPass1( PSInput input ) : COLOR0
{
float3 result = 0;
float4 texelColor = tex2D( diffuseSampler, input.texCoord0 );
for( int i = 0; i < MAX_LIGHTS / 2; i++ )
{
if( litEnabled[ i ] )
{
float orientationFactor = saturate( dot( input.normal, lightPos[ i ].xyz - input.pos )) * 0.77;
float distanceFactor = distance( lightPos[ i ].xyz, input.pos ) * litDistFactor[ i ];
float brightness = orientationFactor / ( distanceFactor );
result += brightness * litColor[ i ] ;
};
};
return texelColor * clamp( float4( result, 1 ), 0.1, 1 );
};
float4 pixelShaderPass2( PSInput input ) : COLOR0
{
float3 result = 0;
float4 texelColor = tex2D( diffuseSampler, input.texCoord0 );
for( int i = MAX_LIGHTS / 2; i < MAX_LIGHTS; i++ )
{
if( litEnabled[ i ] )
{
float orientationFactor = saturate( dot( input.normal, lightPos[ i ].xyz - input.pos )) * 0.77;
float distanceFactor = distance( lightPos[ i ].xyz, input.pos ) * litDistFactor[ i ];
float brightness = orientationFactor / ( distanceFactor );
result += brightness * litColor[ i ] ;
};
};
return texelColor * clamp( float4( result, 1 ), 0.1, 1 );
};
technique Main
{
pass p0
{
AlphaBlendEnable = false;
VertexShader = compile vs_2_0 vertexShaderMain();
PixelShader = compile ps_2_0 pixelShaderPass1();
}
pass p1
{
AlphaBlendEnable = TRUE;
DestBlend = ONE;
SrcBlend = ONE;
VertexShader = compile vs_2_0 vertexShaderMain();
PixelShader = compile ps_2_0 pixelShaderPass2();
}
}