Показать сообщение отдельно
Старый 03.02.2013, 15:16   #26
tirarex
Бывалый
 
Аватар для tirarex
 
Регистрация: 23.11.2011
Сообщений: 863
Написано 334 полезных сообщений
(для 866 пользователей)
Ответ: много шейдерного света

посмотрю

кстати вот попробывал переписать шейдер
посмотрите

//##########################################
// mSL
//
// Bump Light
// with 3 Light Source Types
//
// Open Source, for Free Using
// Author: MoKa (Maxim Miheyev)
// Mail: [email protected]
// Visit: RubuX.net
//##########################################


//################## Varriables ##################
const float4x4 MatWorldViewProj;
const float4x4 MatWorld;

texture diffuseTexture : TEXTURE_0;
texture normalTexture : TEXTURE_1;
texture normalTexture_2 : TEXTURE_2;
// Light
const float3 AmbientClr; // Ambient Color
const float3 LightClr; // Light Color
const half LightInt; // Light Intensity

// Positions
float3 PosLight; // Light Position
float RngLight; // Light Range
float DotLight; // Light Soft


float3 PosLight[100];
float RngLight[100];
float RDotLight[100];

const float3 LightClr[100]; // Light Color
const float LightInt[100]; // Light Intensity



//Spot Light
const float3 LightClrspot; // Light Color
const half LightIntspot; // Light Intensity
// Positions
float3 PosLightspot; // Light Position
float RngLightspot; // Light Range
float DotLightspot; // Light Soft
float3 Lightdir; // world space direction
float LightspotInnerCone; // spot light inner cone (theta) angle
float LightspotOuterCone; // spot light outer cone (phi) angle



const float3 LightClrDirection; // Light Color
const half LightIntDirection; // Light Intensity

// Positions
float3 PosLightDirection; // Light Position
float RngLightDirection; // Light Range
float DotLightDirection; // Light Soft
// Other
static float3 Color;
static float4 cD;
static float3 cN;

static float3 nLight;

static float3 nLightDirection;



//################## Textures ##################
//const texture tDiffuse; // Diffuse Texture
sampler TexDiffuse=sampler_state {
Texture = <diffuseTexture>;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};

//const texture tNormal; // NormalMap Texture
sampler TexNormal=sampler_state {
Texture = <normalTexture>;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};
//const texture tNormal2; // NormalMap Texture2
sampler TexNormal2=sampler_state {
Texture = <normalTexture_2>;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};

//################## Input VS ##################
struct sv_TBN_TC {
float4 Position : POSITION0;
float3 Normal : NORMAL;
float3 Tangent : TANGENT;
float3 Binormal : BINORMAL;
float2 TexCoords : TEXCOORD0;
};
//################## Output VS ##################
struct sp_PW_TBN_TC {
float4 Position : POSITION0;
float4 pWorld : TEXCOORD0;
float2 TexCoords : TEXCOORD1;
float3 Normal : TEXCOORD2;
float3 Tangent : TEXCOORD3;
float3 Binormal : TEXCOORD4;
};


//################## VS ##################
void vs_PW_TBN_TC( in sv_TBN_TC IN, out sp_PW_TBN_TC OUT ) {
OUT.Position = mul(IN.Position,MatWorldViewProj);
OUT.pWorld = mul(IN.Position,MatWorld);
OUT.Tangent = normalize(mul(IN.Tangent,MatWorld));
OUT.Binormal = normalize(mul(IN.Binormal,MatWorld));
OUT.Normal = normalize(mul(IN.Normal,MatWorld));
OUT.TexCoords = IN.TexCoords;
}

//################## PS ##################
float4 psDirectional( in sp_PW_TBN_TC IN ) : COLOR {
cD = tex2D(TexDiffuse,IN.TexCoords);
cN = normalize(tex2D(TexNormal,IN.TexCoords)*2.0f-1.0f);

PosLight = normalize(PosLight);
nLight = float3(dot(PosLight,IN.Tangent),
dot(PosLight,IN.Binormal),dot(PosLight,IN.Normal)) ;

nLight = pow(max(dot(cN,nLight),0.0f),0.8f);

Color = cD.rgb*AmbientClr+(cD*nLight*LightClr*LightInt);

return float4(Color,cD.a);
}
float4 psPoint( in sp_PW_TBN_TC IN ) : COLOR {
cD = tex2D(TexDiffuse,IN.TexCoords);
cN = normalize(tex2D(TexNormal,IN.TexCoords)*2.0f-1.0f);

PosLight = normalize(PosLight-IN.pWorld);
nLight = float3(dot(PosLight,IN.Tangent),
dot(PosLight,IN.Binormal),dot(PosLight,IN.Normal)) ;

nLight = pow(max(dot(cN,nLight),0.0f),0.8f);

Color = cD.rgb*AmbientClr+(cD*nLight*LightClr*LightInt);

return float4(Color,cD.a);
}
float4 psPointDistance( in sp_PW_TBN_TC IN ) : COLOR {
cD = tex2D(TexDiffuse,IN.TexCoords);
Color = cD.rgb*AmbientClr;










for(int i=0;i<100;i++)
{



RngLight[i] = pow(saturate(1.0f-(distance(IN.pWorld,PosLight[i])/RngLight[i])),DotLight[i]);


cN = normalize(tex2D(TexNormal,IN.TexCoords)*2.0f-1.0f);

PosLight[i] = normalize(PosLight[i]-IN.pWorld);
nLight[i] = float3(dot(PosLight[i],IN.Tangent),
dot(PosLight[i],IN.Binormal),dot(PosLight[i],IN.Normal));

nLight[i] = pow(max(dot(cN,nLight[i]),0.0f),0.8f);

Color += cD.rgb*nLight[i]*LightClr[i]*LightInt[i]*RngLight[i];





}
























//LIGHT_DIRECTION
PosLightDirection = normalize(PosLightDirection);
nLightDirection = float3(dot(PosLightDirection,IN.Tangent),
dot(PosLightDirection,IN.Binormal),dot(PosLightDir ection,IN.Normal));

nLightDirection = pow(max(dot(cN,nLightDirection),0.0f),0.8f);

Color += cD.rgb*cD*nLightDirection*LightClrDirection*LightI ntDirection;

return float4(Color,cD.a);
}

//################## Technique ##################
technique Directional {
pass p0 {
AlphaBlendEnable= false;
vertexshader = compile vs_3_0 vs_PW_TBN_TC();
pixelshader = compile ps_3_0 psDirectional();
}
}
technique Point {
pass p0 {
AlphaBlendEnable= false;
vertexshader = compile vs_3_0 vs_PW_TBN_TC();
pixelshader = compile ps_3_0 psPoint();
}
}
technique PointDistance {
pass p0 {
AlphaBlendEnable= false;
// AlphaTestEnable = 1;
//AlphaRef = 127;
//AlphaFunc = 5;
//AlphaBlendEnable = 0;
//CullMode = NONE;
vertexshader = compile vs_3_0 vs_PW_TBN_TC();
pixelshader = compile ps_3_0 psPointDistance();
}
}
(Offline)
 
Ответить с цитированием