mirror of
https://github.com/ncblakely/GiantsTools
synced 2024-11-24 15:15:37 +01:00
59 lines
1.3 KiB
HLSL
59 lines
1.3 KiB
HLSL
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
//
|
|
// http://go.microsoft.com/fwlink/?LinkId=248926
|
|
// http://go.microsoft.com/fwlink/?LinkId=248929
|
|
// http://go.microsoft.com/fwlink/?LinkID=615561
|
|
// http://create.msdn.com/en-US/education/catalog/sample/stock_effects
|
|
|
|
|
|
float ComputeFogFactor(float4 position)
|
|
{
|
|
return saturate(dot(position, FogVector));
|
|
}
|
|
|
|
|
|
void ApplyFog(inout float4 color, float fogFactor)
|
|
{
|
|
color.rgb = lerp(color.rgb, FogColor * color.a, fogFactor);
|
|
}
|
|
|
|
|
|
void AddSpecular(inout float4 color, float3 specular)
|
|
{
|
|
color.rgb += specular * color.a;
|
|
}
|
|
|
|
|
|
struct CommonVSOutput
|
|
{
|
|
float4 Pos_ps;
|
|
float4 Diffuse;
|
|
float3 Specular;
|
|
float FogFactor;
|
|
};
|
|
|
|
|
|
CommonVSOutput ComputeCommonVSOutput(float4 position)
|
|
{
|
|
CommonVSOutput vout;
|
|
|
|
vout.Pos_ps = mul(position, WorldViewProj);
|
|
vout.Diffuse = DiffuseColor;
|
|
vout.Specular = 0;
|
|
vout.FogFactor = ComputeFogFactor(position);
|
|
|
|
return vout;
|
|
}
|
|
|
|
|
|
#define SetCommonVSOutputParams \
|
|
vout.PositionPS = cout.Pos_ps; \
|
|
vout.Diffuse = cout.Diffuse; \
|
|
vout.Specular = float4(cout.Specular, cout.FogFactor);
|
|
|
|
|
|
#define SetCommonVSOutputParamsNoFog \
|
|
vout.PositionPS = cout.Pos_ps; \
|
|
vout.Diffuse = cout.Diffuse;
|