cnq3/code/renderer/shaders/crp/prepass.hlsl
2024-01-19 23:57:40 +01:00

98 lines
2.3 KiB
HLSL

/*
===========================================================================
Copyright (C) 2024 Gian 'myT' Schellenbaum
This file is part of Challenge Quake 3 (CNQ3).
Challenge Quake 3 is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Challenge Quake 3 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Challenge Quake 3. If not, see <https://www.gnu.org/licenses/>.
===========================================================================
*/
// generic shader for the prepass of opaque surfaces
#include "common.hlsli"
#include "world.h.hlsli"
#include "world.hlsli"
cbuffer RootConstants
{
// geometry
matrix modelViewMatrix;
matrix projectionMatrix;
matrix normalMatrix;
float4 clipPlane;
// general
uint textureIndex;
uint samplerIndex;
uint alphaTest;
};
struct VIn
{
float3 position : POSITION;
float3 normal : NORMAL;
float2 texCoords : TEXCOORD0;
float4 color : COLOR0;
};
struct VOut
{
float4 position : SV_Position;
float3 normal : NORMAL;
float2 texCoords : TEXCOORD0;
float4 color : COLOR0;
float clipDist : SV_ClipDistance0;
};
VOut vs(VIn input)
{
float4 positionVS = mul(modelViewMatrix, float4(input.position.xyz, 1));
VOut output;
output.position = mul(projectionMatrix, positionVS);
output.normal = mul(normalMatrix, float4(input.normal, 0)).xyz;
output.texCoords = input.texCoords;
output.color = input.color;
output.clipDist = dot(positionVS, clipPlane);
return output;
}
struct POut
{
float2 normal : SV_Target0;
float2 motionVector : SV_Target1;
};
POut ps(VOut input)
{
if(alphaTest != ATEST_NONE)
{
Texture2D texture0 = ResourceDescriptorHeap[textureIndex];
SamplerState sampler0 = ResourceDescriptorHeap[samplerIndex];
float4 dst = texture0.Sample(sampler0, input.texCoords) * input.color;
if(FailsAlphaTest(dst.a, alphaTest))
{
discard;
}
}
POut output;
output.normal = OctEncode(normalize(input.normal));
output.motionVector = float2(0, 0); // @TODO:
return output;
}