Сообщение от ABTOMAT
А то я не писал.
Просто блин народ думает, что всегда найдётся волшебный шейдер, который за них игру сделает.
.
|
Ы
валшебный шойдер

const float4x4 MatWorldViewProj;
const float4x4 MatWorld;
float2 TexScale=float2(1.0f,1.0f);
float3 Ring[10];
const float2 OffsetF; // Offset First
const float2 OffsetS; // Offset Second
const float FallOffSoft; // FallOff Soft
const half FallOffInt; // FallOff Intensity
const float3 WaterColor; // Water Color
const half WaterInt; // Water Intensity
const float ViewSoft; // View Soft
const float Refract; // Refraction Intensity
const float Reflect; // Reflection Intensity
const float attenuat1; // Attenuation 1
const float attenuat2; // Attenuation 2
// Positions
float3 PosCamera; // Camera Position
// Other
static float2 ProjCoords;
static float3 Color;
static float4 cD;
static float3 cN;
static float3 cNRing;
static float3 cS;
static float3 cR;
static float cFV;
static float cFO;
static float koof;
static float3 nCamera;
//################## Textures ##################
const texture tDiffuse;
sampler TexDiffuse=sampler_state {
Texture = <tDiffuse>;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};
const texture tNormalW;
sampler TexNormalW=sampler_state {
Texture = <tNormalW>;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};
const texture tNormalN;
sampler TexNormalN=sampler_state {
Texture = <tNormalN>;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};
const texture tRing;
sampler TexRing=sampler_state {
Texture = <tRing>;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
ADDRESSW = CLAMP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};
const texture tRingS;
sampler TexRingS=sampler_state {
Texture = <tRingS>;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
ADDRESSW = CLAMP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};
const texture tRing_;
sampler TexRing_=sampler_state {
Texture = <tRing_>;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
ADDRESSW = CLAMP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};
const texture tScreen;
sampler TexScreen=sampler_state {
Texture = <tScreen>;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
ADDRESSW = CLAMP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};
const texture tReflection;
sampler TexReflection=sampler_state {
Texture = <tReflection>;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
ADDRESSW = CLAMP;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};
//############### Input VS ###############
struct svNTB_TC {
float4 Position : POSITION0;
float3 Normal : NORMAL;
float3 Tangent : TANGENT;
float3 Binormal : BINORMAL;
float2 TexCoords : TEXCOORD0;
};
//############### Output VS ##############
struct spPW_NTB_TC_TP {
float4 Position : POSITION0;
float4 pWorld : TEXCOORD0;
float3 Normal : TEXCOORD1;
float3 Tangent : TEXCOORD2;
float3 Binormal : TEXCOORD3;
float2 TexCoords : TEXCOORD4;
float3 TexProj : TEXCOORD5;
};
//################## VS ##################
void vsPV_NTB_TC_TP( in svNTB_TC IN, out spPW_NTB_TC_TP OUT ) {
OUT.Position = mul(IN.Position,MatWorldViewProj);
OUT.pWorld = mul(IN.Position,MatWorld);
OUT.Normal = normalize(mul(IN.Normal,MatWorld));
OUT.Tangent = normalize(mul(IN.Tangent,MatWorld));
OUT.Binormal = normalize(mul(IN.Binormal,MatWorld));
OUT.TexCoords = IN.TexCoords;
OUT.TexProj.x = 0.5f*(OUT.Position.w+OUT.Position.x);
OUT.TexProj.y = 0.5f*(OUT.Position.w-OUT.Position.y);
OUT.TexProj.z = OUT.Position.w;
}
//################## PS ##################
float4 psWater( in spPW_NTB_TC_TP IN ) : COLOR {
cN = tex2D(TexNormalW,IN.TexCoords/TexScale+OffsetF)*0.5f;
cN +=tex2D(TexNormalN,IN.TexCoords/TexScale+OffsetS)*0.5f;
for (int i = 0; i < 5; i++)
{
cNRing +=tex2D(TexRing,(IN.TexCoords+Ring[i].xy)/Ring[i].z)*0.05f*(1-Ring[i].z*attenuat1);
cNRing +=tex2D(TexRing_,(IN.TexCoords+Ring[i].xy)/Ring[i].z)*0.05f*(1+Ring[i].z*attenuat1);
//*(1-Ring[i].z)*(1+Ring[i].z)
}
for (int i = 5; i < 10; i++)
{
cNRing +=tex2D(TexRingS,(IN.TexCoords+Ring[i].xy)/Ring[i].z)*0.05f*(1-Ring[i].z*attenuat2);
cNRing +=tex2D(TexRing_,(IN.TexCoords+Ring[i].xy)/Ring[i].z)*0.05f*(1+Ring[i].z*attenuat2);
}
cN = cNRing*0.9+cN*0.1f;
cN = normalize(cN*2.0f-1.0f);
PosCamera = normalize(PosCamera-IN.pWorld);
ProjCoords = IN.TexProj.xy/IN.TexProj.z;
cS = tex2D(TexScreen,ProjCoords+cN.xy*Refract);
ProjCoords.y = 1.0f-ProjCoords.y;
cR = tex2D(TexReflection,ProjCoords+cN.xy*Reflect);
nCamera = normalize(float3(dot(PosCamera,IN.Tangent),
dot(PosCamera,IN.Binormal),dot(PosCamera,IN.Normal)));
cFV = pow(max(dot(cN,nCamera),0.0f),ViewSoft)*WaterInt;
cFO = pow(max(dot(cN,nCamera),0.0f),FallOffSoft)*FallOffInt;
Color = cR*(1.0f-cFV)+cS*cFV;
Color +=Color*(1.0f-cFO)*FallOffInt*WaterColor;
//Color +=Color*(1.0f-saturate(pow(cFO,0.2f)))*FallOffInt*WaterColor;
return float4(Color*0.8,1.0f);
}
//############## Technique ###############
technique Water {
pass p0 {
AlphaBlendEnable= false;
vertexshader = compile vs_3_0 vsPV_NTB_TC_TP();
pixelshader = compile ps_3_0 psWater();
}
}