mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Start of PBR
This commit is contained in:
@@ -1,9 +1,21 @@
|
||||
Texture2D AlbedoTexture : register(t0);
|
||||
SamplerState AlbedoSampler : register(s0);
|
||||
|
||||
Texture2D<float3> NormalTexture : register(t1);
|
||||
SamplerState NormalSampler : register(s1);
|
||||
|
||||
Texture2D<float> MetallicTexture : register(t2);
|
||||
SamplerState MetallicSampler : register(s2);
|
||||
|
||||
Texture2D<float> RoughnessTexture : register(t3);
|
||||
SamplerState RoughnessSampler : register(s3);
|
||||
|
||||
// Texture2D<float> AmbientTexture : register(t4);
|
||||
// SamplerState AmbientSampler : register(s4);
|
||||
|
||||
cbuffer SceneConstants
|
||||
{
|
||||
float4x4 ViewProjection = float4x4(1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
float4x4 ViewProjection;
|
||||
}
|
||||
|
||||
cbuffer ObjectConstants
|
||||
@@ -13,7 +25,7 @@ cbuffer ObjectConstants
|
||||
|
||||
cbuffer Constants
|
||||
{
|
||||
float4 BaseColor = float4(1, 0, 1, 1);
|
||||
//float4 BaseColor = float4(1, 0, 1, 1);
|
||||
//float3 LightDir = float3(0, 1, 0);
|
||||
}
|
||||
|
||||
@@ -21,13 +33,19 @@ struct VS_IN
|
||||
{
|
||||
float3 Position : POSITION;
|
||||
float3 Normal : NORMAL;
|
||||
// Todo: Tangent.w... handedness
|
||||
float3 Tangent : TANGENT;
|
||||
float2 TexCoord : TEXCOORD;
|
||||
};
|
||||
|
||||
struct PS_IN
|
||||
{
|
||||
float4 Position : SV_POSITION;
|
||||
float3 WorldPosition : TEXCOORD0;
|
||||
float3 Normal : NORMAL;
|
||||
float4 Position : SV_POSITION;
|
||||
float3 WorldPosition : WORLDPOSITION;
|
||||
float3 Normal : NORMAL;
|
||||
float3 Tangent : TANGENT;
|
||||
float2 TexCoord : TEXCOORD;
|
||||
//nointerpolation float Handedness : HANDEDNESS;
|
||||
};
|
||||
|
||||
PS_IN VS(VS_IN input)
|
||||
@@ -36,36 +54,67 @@ PS_IN VS(VS_IN input)
|
||||
|
||||
float4 worldPosition = mul(Transform, float4(input.Position, 1));
|
||||
|
||||
output.Position = mul(ViewProjection, worldPosition);
|
||||
output.Position = mul(ViewProjection, worldPosition);
|
||||
output.WorldPosition = worldPosition.xyz / worldPosition.w;
|
||||
output.Normal = mul((float3x3)Transform, input.Normal);
|
||||
|
||||
output.Normal = mul(input.Normal, (float3x3)Transform);
|
||||
output.Tangent = mul((float3x3)Transform, input.Tangent);
|
||||
// TODO: output.Handedness = input.Tangent.w
|
||||
|
||||
output.TexCoord = input.TexCoord;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
struct PS_OUT
|
||||
{
|
||||
float4 Color : SV_TARGET0;
|
||||
float4 Normal : SV_TARGET1;
|
||||
float4 Position : SV_TARGET2;
|
||||
float4 Albedo : SV_TARGET0;
|
||||
// RG: TextureNormal.XY BA: GeoNrm.XY
|
||||
float4 Normal : SV_TARGET1;
|
||||
// R: GeoNrm.Z GBA: GeoTan.XYZ
|
||||
float4 Tangent : SV_TARGET2;
|
||||
float4 Position : SV_TARGET3;
|
||||
// R: Metallicity G: Roughness B: Ambient
|
||||
float4 Material : SV_TARGET4;
|
||||
};
|
||||
|
||||
PS_OUT PS(PS_IN input)
|
||||
{
|
||||
input.Normal = normalize(input.Normal);
|
||||
// Build tangent space
|
||||
float3 normal = normalize(input.Normal);
|
||||
float3 tangent = normalize(input.Tangent - dot(input.Tangent, normal) * input.Normal);
|
||||
// TODO: float3 bitangent = input.Handedness * cross(normal, tangent);
|
||||
float3 bitangent = -cross(normal, tangent);
|
||||
|
||||
float f = distance(input.Normal, input.Normal);
|
||||
float3x3 tangentTransform = float3x3(tangent, bitangent, normal);
|
||||
//tangentTransform = transpose(tangentTransform);
|
||||
|
||||
//float shading = dot(LightDir, input.Normal);
|
||||
//float shading = dot(LightDir, LightDir) + 1;
|
||||
//shading = clamp(shading, 0.0f, 1.0f);
|
||||
float4 texAlbedo = AlbedoTexture.Sample(AlbedoSampler, input.TexCoord);
|
||||
float3 texNormal = NormalTexture.Sample(NormalSampler, input.TexCoord);
|
||||
texNormal.xy = texNormal.xy * 2.0 - 1.0;
|
||||
float texMetallic = MetallicTexture.Sample(MetallicSampler, input.TexCoord);
|
||||
float texRoughness = RoughnessTexture.Sample(RoughnessSampler, input.TexCoord);
|
||||
|
||||
//return float4(BaseColor.rgb * shading, 1.0f);
|
||||
//float3 objectNormal = mul(tangentTransform, texNormal);
|
||||
//float3 worldNormal = mul(objectNormal, (float3x3)Transform);
|
||||
|
||||
PS_OUT output = (PS_OUT)0;
|
||||
output.Color = BaseColor;
|
||||
output.Normal = float4(input.Normal, 1);
|
||||
output.Position = float4(input.WorldPosition, 1);
|
||||
|
||||
/////////////TODO: REMOVEME
|
||||
|
||||
//worldNormal = max(worldNormal - 10000000, normal);
|
||||
//texAlbedo = max(texAlbedo - 10000000, 1.0);
|
||||
//texMetallic = max(texMetallic - 10000000, 0.0);
|
||||
//texRoughness = max(texRoughness - 10000000, 0.1);
|
||||
|
||||
/////////////TODO: END_REMOVEME
|
||||
|
||||
PS_OUT output;
|
||||
output.Albedo = texAlbedo;
|
||||
//output.Normal = float4(objectNormal, 1.0);
|
||||
output.Normal = float4(texNormal.xy, normal.xy);
|
||||
output.Tangent = float4(normal.z, tangent.xyz);
|
||||
output.Position = float4(input.WorldPosition, 1.0);
|
||||
output.Material = float4(texMetallic, texRoughness, 1.0, 0);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user