lowpoly-walking-simulator/directx11_hellovr/DirectXTK/Src/Shaders/Common.fxh

61 lines
1.3 KiB
HLSL
Raw Permalink Normal View History

2024-11-14 11:54:38 +00:00
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248929
// 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;