Budujemy silnik: shadery kontratakujÄ… - kod shadera

<shader>
<params>

Material.TextureMode in (NONE, SIMPLE, SPLITTING)
Material.AlphaTestMode in (FALSE, TRUE)
Material.BumpMapping in (NONE)

Material.Any in (ANY)

Light.LightType in (DIRECTIONAL, POINT, SPOT)

</params>
<ps_variables>

uniform sampler2D Material.ColorSampler;
uniform sampler2D Material.DetailsSampler;
uniform sampler2D Material.DetailRSampler;
uniform float4 Material.MaterialColor;
uniform float4 Material.DetailsScales;
uniform float3 Light.PositionWorld;
uniform float Light.Strength;
uniform float3 Light.Direction;
uniform float4x4 Light.MatrixShadow;
varying float4 PositionWorld;
varying float2 TextureCoord;
varying float3 Normal;
//...

</ps_variables>
<ps_functions>

Color Texture[Material.TextureMode = NONE]
{
	$ NULL
}

[Require(Material.ColorSampler, TextureCoord)]
Color Texture[Material.TextureMode = SIMPLE]
{
	!color %color
	%color = tex2D(Material.ColorSampler, TextureCoord.xy);
	$ %color
}

Null AlphaTest[Material.AlphaTestMode = FALSE]
{
}

[Require(Material.ColorSampler, TextureCoord, Material.AlphaTestValue)]
Null AlphaTest[Material.AlphaTestMode = TRUE]
{
	!let %texture Texture
	if (%texture.a < AlphaTestValue)
	{
		discard;
	}
}
</ps_functions>
<ps_techniques>

Technique[DRAW]
{
	!let %ambient Ambient
	
	!color %color
	
	!add %color %ambient
  
	!foreach light
	{
		!color %subcolor
		
		!let %shadow Shadow
		
		!let %attenuation Attenuation
		!let %diffuse Diffuse
		!let %specular Specular
		
		!add %subcolor %diffuse %specular
		
		!multiply %subcolor %attenuation	
		
		!multiply %subcolor %shadow
		
		!add &color %subcolor
	}
	
	!out 0 %color
}

</ps_techniques>

<vs_provides>
[Requires(Stream.Normal)]
[Provides(Normal)]
{
	float3 %norm = Stream.Normal;
	$ %norm
}

[Requires(Scene.MatrixMVP)]
[Provides(CORE)]
{
	!req %core PositionWorld
	%core = mul(Scene.MatrixMVP, %core);
	$ %core
}

</vs_provides>

<stream>

float3 Position POSITION
float3 Normal NORMAL
float2 Texcoord TEXCOORD0
float3 Tangent COLOR

</stream>

</shader>

Comments:

Leave comment: