Compare commits
3 Commits
00d5e1476c
...
d51fc375d2
| Author | SHA1 | Date |
|---|---|---|
|
|
d51fc375d2 | |
|
|
9314b3504e | |
|
|
afec17cb0f |
|
|
@ -0,0 +1,63 @@
|
||||||
|
import Bindless;
|
||||||
|
|
||||||
|
public struct Material {
|
||||||
|
float4 baseColor;
|
||||||
|
float4 emissiveColor;
|
||||||
|
Sampler2D.RID albedoTextureID;
|
||||||
|
Sampler2D.RID normalTextureID;
|
||||||
|
Sampler2D.RID metalRoughTextureID;
|
||||||
|
Sampler2D.RID emissiveTextureID;
|
||||||
|
float metallic;
|
||||||
|
float roughness;
|
||||||
|
|
||||||
|
public float4 getAlbedo(float2 uv, float4 inColor) {
|
||||||
|
if (let albedoTex = albedoTextureID) {
|
||||||
|
return baseColor * albedoTex.Sample(uv).rgba;
|
||||||
|
}
|
||||||
|
return baseColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float3 getEmissive(float2 uv) {
|
||||||
|
if (let emissionTex = emissiveTextureID) {
|
||||||
|
return emissionTex.Sample(uv).rgb * emissiveColor.rgb * emissiveColor.a;
|
||||||
|
}
|
||||||
|
return emissiveColor.rgb * emissiveColor.a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float3 getNormal(float3 position, float3 normal, float4 tangent, float2 uv) {
|
||||||
|
float3 N = normalize(normal.xyz);
|
||||||
|
|
||||||
|
if (let normalTex = normalTextureID) {
|
||||||
|
let vNt = normalize(2.0f * normalTex.Sample(uv).rgb - 1.0f);
|
||||||
|
|
||||||
|
float3 T;
|
||||||
|
float3 B;
|
||||||
|
|
||||||
|
if (tangent.w == 0.0f) {
|
||||||
|
float3 q1 = ddx(position);
|
||||||
|
float3 q2 = ddy(position);
|
||||||
|
float2 st1 = ddx(uv);
|
||||||
|
float2 st2 = ddy(uv);
|
||||||
|
|
||||||
|
float det = (st1.x * st2.y - st2.x * st1.y);
|
||||||
|
|
||||||
|
T = -(q1 * st2.y - q2 * st1.y) / det;
|
||||||
|
T = T - N * dot(N, T);
|
||||||
|
B = normalize(cross(N, T));
|
||||||
|
} else {
|
||||||
|
T = normalize(tangent.xyz);
|
||||||
|
B = tangent.w * cross(N, T);
|
||||||
|
}
|
||||||
|
N = normalize(T * vNt.x + B * vNt.y + N * vNt.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
return N;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float2 getMetalRough(float2 uv) {
|
||||||
|
if (let metalRoughTex = metalRoughTextureID) {
|
||||||
|
return metalRoughTex.Sample(uv).bg * float2(metallic, roughness);
|
||||||
|
}
|
||||||
|
return float2(metallic, roughness);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
import Bindless;
|
import Bindless;
|
||||||
|
import Material;
|
||||||
|
import PBR;
|
||||||
|
|
||||||
struct VertexOut {
|
struct VertexOut {
|
||||||
|
float4 worldPosition : POSITION;
|
||||||
|
float3 normal : NORMAL;
|
||||||
|
float4 tangent : TANGENT;
|
||||||
|
float2 texCoord0 : TEXCOORD0;
|
||||||
|
float2 texCoord1 : TEXCOORD1;
|
||||||
|
float4 vertexColor0 : COLOR0;
|
||||||
float4 outPosition : SV_Position;
|
float4 outPosition : SV_Position;
|
||||||
float4 worldPosition : WorldPosition;
|
|
||||||
float4 normal : WorldNormal;
|
|
||||||
float2 texCoord0 : TexCoord0;
|
|
||||||
float2 texCoord1 : TexCoord1;
|
|
||||||
float4 vertexColor0 : VertexColor;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CameraData {
|
struct CameraData {
|
||||||
|
|
@ -15,13 +18,6 @@ struct CameraData {
|
||||||
float4 position;
|
float4 position;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PointLight {
|
|
||||||
float3 position;
|
|
||||||
float range;
|
|
||||||
float3 color;
|
|
||||||
float attenuation;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DirectionalLight {
|
struct DirectionalLight {
|
||||||
float3 direction;
|
float3 direction;
|
||||||
float _padding0;
|
float _padding0;
|
||||||
|
|
@ -55,11 +51,8 @@ uniform ParameterBlock<PerFrameData> pfd;
|
||||||
|
|
||||||
struct PerInstanceData {
|
struct PerInstanceData {
|
||||||
float4x4 transform;
|
float4x4 transform;
|
||||||
Sampler2D.RID textureID;
|
float4x4 invTransform;
|
||||||
uint _padding;
|
Material material;
|
||||||
float metallic;
|
|
||||||
float roughness;
|
|
||||||
float4 baseColor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[vk::push_constant]]
|
[[vk::push_constant]]
|
||||||
|
|
@ -70,6 +63,7 @@ VertexOut VertexMain(
|
||||||
uint vertexId: SV_VertexID,
|
uint vertexId: SV_VertexID,
|
||||||
float3 position,
|
float3 position,
|
||||||
float3 normal,
|
float3 normal,
|
||||||
|
float4 tangent,
|
||||||
float2 texCoord0,
|
float2 texCoord0,
|
||||||
float2 texCoord1,
|
float2 texCoord1,
|
||||||
float4 vertexColor0,
|
float4 vertexColor0,
|
||||||
|
|
@ -79,49 +73,164 @@ VertexOut VertexMain(
|
||||||
VertexOut output;
|
VertexOut output;
|
||||||
output.outPosition = mul(pfd.camera.proj, mul(pfd.camera.view, worldPosition));
|
output.outPosition = mul(pfd.camera.proj, mul(pfd.camera.view, worldPosition));
|
||||||
output.worldPosition = worldPosition;
|
output.worldPosition = worldPosition;
|
||||||
output.normal = mul(pcb.transform, float4(normalize(normal.rgb), 0.0f));
|
output.normal = normalize(mul(float4(normal.xyz, 0.0f), pcb.invTransform).xyz);
|
||||||
|
if (tangent.w == 0.0f) {
|
||||||
|
output.tangent = 0.0f.xxxx;
|
||||||
|
} else {
|
||||||
|
output.tangent = float4(normalize(mul(float4(tangent.xyz, 0.0f), pcb.invTransform).xyz), tangent.w);
|
||||||
|
}
|
||||||
output.texCoord0 = texCoord0;
|
output.texCoord0 = texCoord0;
|
||||||
output.texCoord1 = texCoord1;
|
output.texCoord1 = texCoord1;
|
||||||
output.vertexColor0 = vertexColor0;
|
output.vertexColor0 = vertexColor0;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
[shader("fragment")]
|
|
||||||
float4 FragmentMain(
|
|
||||||
float4 worldPosition : WorldPosition,
|
|
||||||
float4 normal : WorldNormal,
|
|
||||||
float2 uv0 : TexCoord0,
|
|
||||||
float2 uv1 : TexCoord1,
|
|
||||||
float4 color : VertexColor,
|
|
||||||
) : SV_Target0 {
|
|
||||||
|
|
||||||
float3 diffuse = 0.0f.xxx;
|
float TrowbridgeReitzGGX(float3 Normal, float3 Halfway, float Roughness)
|
||||||
float3 specular = 0.0f.xxx;
|
{
|
||||||
|
float Coeff = Roughness * Roughness;
|
||||||
|
float Alpha2 = Coeff * Coeff;
|
||||||
|
float NdotH = max(dot(Normal, Halfway), 0.0f);
|
||||||
|
float NdotH2 = NdotH * NdotH;
|
||||||
|
|
||||||
for (uint i = 0; i < pfd.lightData.pointLightCount; ++i) {
|
float Numerator = Alpha2;
|
||||||
PointLight pointlight = pfd.lightData.pointLights[i];
|
float Denominator = NdotH2 * (Alpha2 - 1.0f) + 1.0f;
|
||||||
|
Denominator = PI * Denominator * Denominator;
|
||||||
|
|
||||||
let lightPosition = pointlight.position;
|
return Numerator / Denominator;
|
||||||
let lightDisplace = worldPosition.xyz - lightPosition;
|
}
|
||||||
let lightDistance = length(lightDisplace);
|
|
||||||
let lightDirection = normalize(lightDisplace);
|
float GeometrySchlickGGX(float NdotV, float Roughness)
|
||||||
let viewDirection = normalize(worldPosition.xyz - pfd.camera.position.xyz);
|
{
|
||||||
let halfWayVector = normalize(-lightDirection + viewDirection);
|
float R = Roughness + 1.0f;
|
||||||
|
float K = (R * R) / 8.0f;
|
||||||
let attenuation = (1.0f / lightDistance);
|
|
||||||
|
float Numerator = NdotV;
|
||||||
let diffuseFactor = pcb.roughness * dot(-lightDirection, normalize(normal.xyz));
|
float Denominator = NdotV * (1.0f - K) + K;
|
||||||
diffuse += pointlight.color * diffuseFactor;
|
|
||||||
|
return Numerator / Denominator;
|
||||||
let specularFactor = (1.0f - pcb.roughness) * pow(max(dot(halfWayVector, viewDirection), 0.0f), 32.0f) * attenuation;
|
}
|
||||||
|
|
||||||
specular += pointlight.color * specularFactor;
|
float GeometrySmith(float NdotV, float NdotL, float Roughness)
|
||||||
}
|
{
|
||||||
|
float GGX1 = GeometrySchlickGGX(NdotV, Roughness);
|
||||||
if (let texture = pcb.textureID) {
|
float GGX2 = GeometrySchlickGGX(NdotL, Roughness);
|
||||||
return float4(texture.Sample(uv0).rgb, 1.0f) * pcb.baseColor * color * float4((diffuse + specular), 0.0f);
|
|
||||||
} else {
|
return GGX1 * GGX2;
|
||||||
return pcb.baseColor * color * float4((diffuse + specular), 0.0f);
|
}
|
||||||
}
|
|
||||||
|
// https://en.wikipedia.org/wiki/Schlick%27s_approximation
|
||||||
|
float3 FresnelSchlick(float cosine, float3 F_0)
|
||||||
|
{
|
||||||
|
return F_0 + (1.0f - F_0) * pow(clamp(1.0f - cosine, 0.0f, 1.0f), 5.0f); // Clamp to avoid artifacts.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sebastian Lagarde
|
||||||
|
float3 FresnelSchlickRoughness(float cosine, float3 F_0, float Roughness)
|
||||||
|
{
|
||||||
|
return F_0 + (max((1.0f - Roughness).xxx, F_0) - F_0) * pow(clamp(1.0f - cosine, 0.0f, 1.0f), 5.0f); // Clamp to avoid artifacts.
|
||||||
|
}
|
||||||
|
|
||||||
|
float3 GetPBRContrib(float3 Albedo, float3 LightColor, float3 ViewDir, float3 Normal, float Metallic, float Roughness, float3 F_0, float3 LightDir, float LightDistance)
|
||||||
|
{
|
||||||
|
float Attenuation = 1.0f / (LightDistance * LightDistance); // TODO: Controlled Attenuation
|
||||||
|
float3 Halfway = normalize(ViewDir + LightDir);
|
||||||
|
|
||||||
|
float CosineFactor = max(dot(Halfway, ViewDir), 0.0f);
|
||||||
|
float NdotV = max(dot(Normal, ViewDir), 0.0f);
|
||||||
|
float NdotL = max(dot(Normal, LightDir), 0.0f);
|
||||||
|
|
||||||
|
float3 Radiance = LightColor * Attenuation;
|
||||||
|
|
||||||
|
float NormalDistribution = TrowbridgeReitzGGX(Normal, Halfway, Roughness);
|
||||||
|
float Geometry = GeometrySmith(NdotV, NdotL, Roughness);
|
||||||
|
float3 Fresnel = FresnelSchlickRoughness(CosineFactor, F_0, Roughness);
|
||||||
|
|
||||||
|
float3 Numerator = (NormalDistribution * Geometry) * Fresnel;
|
||||||
|
float Denominator = 4.0f * NdotV * NdotL;
|
||||||
|
float3 Specular = Numerator / (Denominator + 0.00001f);
|
||||||
|
|
||||||
|
float3 K_Specular = Fresnel;
|
||||||
|
float3 K_Diffuse = 1.0f.xxx - K_Specular;
|
||||||
|
|
||||||
|
K_Diffuse *= 1.0f - Metallic;
|
||||||
|
|
||||||
|
return NdotL * Radiance * (K_Diffuse * Albedo / PI + Specular);
|
||||||
|
}
|
||||||
|
|
||||||
|
float3 GetPointLightInfluence(float3 Albedo, float2 MetalRough, float3 Position, float3 Normal)
|
||||||
|
{
|
||||||
|
if (pfd.lightData.pointLightCount == 0)
|
||||||
|
return 0.0f.xxx;
|
||||||
|
|
||||||
|
float3 ViewDir = normalize(pfd.camera.position.xyz - Position);
|
||||||
|
|
||||||
|
float Metallic = MetalRough.r;
|
||||||
|
float Roughness = MetalRough.g;
|
||||||
|
|
||||||
|
// Dielectric F_0 based on LearnOpenGL.
|
||||||
|
// TODO: Cite
|
||||||
|
float3 F_0 = 0.04f.xxx;
|
||||||
|
F_0 = lerp(F_0, Albedo, Metallic);
|
||||||
|
|
||||||
|
float3 Contrib = 0.0f;
|
||||||
|
for (uint i = 0; i < pfd.lightData.pointLightCount; ++i)
|
||||||
|
{
|
||||||
|
PointLight Light = pfd.lightData.pointLights[i];
|
||||||
|
|
||||||
|
if (Light.range < 0.0f)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
float3 LightDir = float3(Light.position) - Position;
|
||||||
|
float LightDistance = length(LightDir);
|
||||||
|
|
||||||
|
if (LightDistance > Light.range)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
LightDir /= LightDistance; // Normalization
|
||||||
|
|
||||||
|
// Color Unpack
|
||||||
|
//float R = (Light.Color & 0xFF000000) >> 24;
|
||||||
|
//float G = (Light.Color & 0x00FF0000) >> 16;
|
||||||
|
//float B = (Light.Color & 0x0000FF00) >> 8;
|
||||||
|
|
||||||
|
//float3 LightColor = Light.Intensity * float3(R, G, B) * 0.00392156862f; // 0.00392156862 = 1/255
|
||||||
|
|
||||||
|
Contrib += GetPBRContrib(Albedo, Light.color, ViewDir, Normal, Metallic, Roughness, F_0, LightDir, LightDistance);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Contrib;
|
||||||
|
}
|
||||||
|
|
||||||
|
[shader("fragment")]
|
||||||
|
float4 FragmentMain(
|
||||||
|
float4 position : POSITION,
|
||||||
|
float3 normal : NORMAL,
|
||||||
|
float4 tangent : TANGENT,
|
||||||
|
float2 texCoord0 : TEXCOORD0,
|
||||||
|
float2 texCoord1 : TEXCOORD1,
|
||||||
|
float4 vertexColor0 : COLOR0,
|
||||||
|
) : SV_Target0 {
|
||||||
|
|
||||||
|
float3 N = pcb.material.getNormal(position.xyz, normal.xyz, tangent, texCoord0);
|
||||||
|
float2 metalRough = pcb.material.getMetalRough(texCoord0);
|
||||||
|
|
||||||
|
let albedo = pcb.material.getAlbedo(texCoord0, vertexColor0);
|
||||||
|
let viewDir = normalize(position.xyz - pfd.camera.position.xyz);
|
||||||
|
|
||||||
|
//float3 f_0 = 0.04f.xxx;
|
||||||
|
//f_0 = lerp(f_0, albedo.rgb, metalRough.x);
|
||||||
|
|
||||||
|
|
||||||
|
//float3 contrib = 0.0f.xxx;
|
||||||
|
//for (uint i = 0; i < pfd.lightData.pointLightCount; ++i) {
|
||||||
|
// PointLight pointlight = pfd.lightData.pointLights[i];
|
||||||
|
|
||||||
|
// contrib += pointlight.getInfluence(albedo.rgb, metalRough, viewDir, position.xyz, N, f_0);
|
||||||
|
//}
|
||||||
|
|
||||||
|
let contrib = GetPointLightInfluence(albedo.rgb, metalRough, position.xyz, N);
|
||||||
|
|
||||||
|
return float4(pcb.material.getEmissive(texCoord0) + contrib, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,107 @@
|
||||||
|
public static const float PI = 3.14159265f;
|
||||||
|
|
||||||
|
float TrowbridgeReitzGGX(float3 normal, float3 halfway, float roughness)
|
||||||
|
{
|
||||||
|
float alpha = roughness * roughness;
|
||||||
|
float alpha2 = alpha * alpha;
|
||||||
|
float nDotH = max(dot(normal, halfway), 0.0f);
|
||||||
|
float nDotH2 = nDotH * nDotH;
|
||||||
|
|
||||||
|
float numerator = alpha2;
|
||||||
|
float denominator = nDotH2 * (alpha2 - 1.0f) + 1.0f;
|
||||||
|
denominator = PI * denominator * denominator;
|
||||||
|
|
||||||
|
return numerator / denominator;
|
||||||
|
}
|
||||||
|
|
||||||
|
float GeometrySchlickGGX(float nDotV, float roughness)
|
||||||
|
{
|
||||||
|
float r = roughness + 1.0f;
|
||||||
|
float k = (r * r) / 8.0f;
|
||||||
|
|
||||||
|
float numerator = nDotV;
|
||||||
|
float denominator = nDotV * (1.0f - k) + k;
|
||||||
|
|
||||||
|
return numerator / denominator;
|
||||||
|
}
|
||||||
|
|
||||||
|
float GeometrySmith(float nDotV, float nDotL, float roughness)
|
||||||
|
{
|
||||||
|
float ggx1 = GeometrySchlickGGX(nDotV, roughness);
|
||||||
|
float ggx2 = GeometrySchlickGGX(nDotL, roughness);
|
||||||
|
|
||||||
|
return ggx1 * ggx2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://en.wikipedia.org/wiki/Schlick%27s_approximation
|
||||||
|
float3 FresnelSchlick(float cosine, float3 f_0)
|
||||||
|
{
|
||||||
|
return f_0 + (1.0f - f_0) * pow(clamp(1.0f - cosine, 0.0f, 1.0f), 5.0f); // Clamp to avoid artifacts.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sebastian Lagarde
|
||||||
|
float3 FresnelSchlickRoughness(float cosine, float3 f_0, float roughness)
|
||||||
|
{
|
||||||
|
return f_0 + (max((1.0f - roughness).xxx, f_0) - f_0) * pow(clamp(1.0f - cosine, 0.0f, 1.0f), 5.0f); // Clamp to avoid artifacts.
|
||||||
|
}
|
||||||
|
|
||||||
|
float3 GetPBRContrib(
|
||||||
|
float3 albedo,
|
||||||
|
float3 radiance,
|
||||||
|
float3 viewDir,
|
||||||
|
float3 normal,
|
||||||
|
float3 lightDir,
|
||||||
|
float2 metalRough,
|
||||||
|
float3 f_0)
|
||||||
|
{
|
||||||
|
float3 halfway = normalize(viewDir + lightDir);
|
||||||
|
|
||||||
|
float cosineFactor = max(dot(halfway, viewDir), 0.0f);
|
||||||
|
float nDotV = max(dot(normal, viewDir), 0.0f);
|
||||||
|
float nDotL = max(dot(normal, lightDir), 0.0f);
|
||||||
|
|
||||||
|
float normalDistribution = TrowbridgeReitzGGX(normal, halfway, metalRough.y);
|
||||||
|
float geometry = GeometrySmith(nDotV, nDotL, metalRough.y);
|
||||||
|
float3 fresnel = FresnelSchlickRoughness(cosineFactor, f_0, metalRough.y);
|
||||||
|
|
||||||
|
float3 numerator = (normalDistribution * geometry) * fresnel;
|
||||||
|
float denominator = 4.0f * nDotV * nDotL;
|
||||||
|
float3 specular = numerator / (denominator + 0.00001f);
|
||||||
|
|
||||||
|
float3 kSpecular = fresnel;
|
||||||
|
float3 kDiffuse = 1.0f - kSpecular;
|
||||||
|
|
||||||
|
kDiffuse *= 1.0f - metalRough.x;
|
||||||
|
|
||||||
|
return nDotL * radiance * (kDiffuse * albedo / PI + specular);
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct PointLight {
|
||||||
|
public float3 position;
|
||||||
|
public float range;
|
||||||
|
public float3 color;
|
||||||
|
float attenuation;
|
||||||
|
|
||||||
|
public float3 getInfluence(float3 albedo, float2 metalRough, float3 viewDir, float3 worldPosition, float3 normal, float3 f_0) {
|
||||||
|
|
||||||
|
float3 lightDir = float3(position) - worldPosition;
|
||||||
|
float lightDistance = length(lightDir);
|
||||||
|
|
||||||
|
if (lightDistance > range)
|
||||||
|
return 0.0f.xxx;
|
||||||
|
|
||||||
|
lightDir /= lightDistance; // Normalization
|
||||||
|
|
||||||
|
// Color Unpack
|
||||||
|
//float R = (Light.Color & 0xFF000000) >> 24;
|
||||||
|
//float G = (Light.Color & 0x00FF0000) >> 16;
|
||||||
|
//float B = (Light.Color & 0x0000FF00) >> 8;
|
||||||
|
|
||||||
|
//float3 LightColor = Light.Intensity * float3(R, G, B) * 0.00392156862f; // 0.00392156862 = 1/255
|
||||||
|
|
||||||
|
let attenuation_ = attenuation / (lightDistance * lightDistance);
|
||||||
|
let radiance = color * attenuation_;
|
||||||
|
|
||||||
|
return GetPBRContrib(albedo, radiance, viewDir, normal, lightDir, metalRough, f_0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -1,2 +1,4 @@
|
||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Class_0020and_0020struct_0020methods/@EntryIndexedValue"><NamingElement Priority="10"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="member function" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"><ExtraRule Prefix="" Suffix="" Style="aa_bb" /></Policy></NamingElement></s:String></wpf:ResourceDictionary>
|
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Class_0020and_0020struct_0020methods/@EntryIndexedValue"><NamingElement Priority="10"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="member function" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"><ExtraRule Prefix="" Suffix="" Style="aa_bb" /></Policy></NamingElement></s:String>
|
||||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Local_0020variables/@EntryIndexedValue"><NamingElement Priority="7"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="local variable" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></NamingElement></s:String>
|
||||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CppNaming/Rules/=Parameters/@EntryIndexedValue"><NamingElement Priority="6"><Descriptor Static="Indeterminate" Constexpr="Indeterminate" Const="Indeterminate" Volatile="Indeterminate" Accessibility="NOT_APPLICABLE"><type Name="function parameter" /><type Name="lambda parameter" /></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></NamingElement></s:String></wpf:ResourceDictionary>
|
||||||
|
|
@ -121,6 +121,15 @@
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
</Link>
|
</Link>
|
||||||
|
<CustomBuild>
|
||||||
|
<Command>slangc %(FullPath) -profile sm_6_6 -target spirv -o %(Filename).spv</Command>
|
||||||
|
</CustomBuild>
|
||||||
|
<CustomBuild>
|
||||||
|
<Message>Compiling %(Filename)</Message>
|
||||||
|
</CustomBuild>
|
||||||
|
<CustomBuild>
|
||||||
|
<Outputs>%(Filename).spv</Outputs>
|
||||||
|
</CustomBuild>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
|
|
@ -146,6 +155,15 @@
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
</Link>
|
</Link>
|
||||||
|
<CustomBuild>
|
||||||
|
<Command>slangc %(FullPath) -profile sm_6_6 -target spirv -o %(Filename).spv</Command>
|
||||||
|
</CustomBuild>
|
||||||
|
<CustomBuild>
|
||||||
|
<Message>Compiling %(Filename)</Message>
|
||||||
|
</CustomBuild>
|
||||||
|
<CustomBuild>
|
||||||
|
<Outputs>%(Filename).spv</Outputs>
|
||||||
|
</CustomBuild>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include=".clang-format" />
|
<None Include=".clang-format" />
|
||||||
|
|
@ -154,14 +172,17 @@
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
|
||||||
<FileType>Document</FileType>
|
<FileType>Document</FileType>
|
||||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">slangc %(FullPath) -profile sm_6_6 -target spirv -o %(Filename).spv</Command>
|
|
||||||
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Compiling %(Filename).slang</Message>
|
|
||||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).spv</Outputs>
|
|
||||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">slangc %(FullPath) -profile sm_6_6 -target spirv -o %(Filename).spv</Command>
|
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">slangc %(FullPath) -profile sm_6_6 -target spirv -o %(Filename).spv</Command>
|
||||||
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Compiling %(Filename).slang</Message>
|
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Compiling %(Filename).slang</Message>
|
||||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).spv</Outputs>
|
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).spv</Outputs>
|
||||||
</CustomBuild>
|
</CustomBuild>
|
||||||
<None Include="Assets\Shaders\Bindless.slang" />
|
<None Include="Assets\Shaders\Bindless.slang">
|
||||||
|
<FileType>Document</FileType>
|
||||||
|
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">slangc %(FullPath) -profile sm_6_6 -target module -o %(Filename).slang-module</Command>
|
||||||
|
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).slang-module</Outputs>
|
||||||
|
</None>
|
||||||
|
<None Include="Assets\Shaders\Material.slang" />
|
||||||
|
<None Include="Assets\Shaders\PBR.slang" />
|
||||||
<None Include="PLAN.md">
|
<None Include="PLAN.md">
|
||||||
<SubType>
|
<SubType>
|
||||||
</SubType>
|
</SubType>
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,12 @@
|
||||||
<None Include="Assets\Shaders\Bindless.slang">
|
<None Include="Assets\Shaders\Bindless.slang">
|
||||||
<Filter>Resource Files\Shader Files</Filter>
|
<Filter>Resource Files\Shader Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="Assets\Shaders\PBR.slang">
|
||||||
|
<Filter>Resource Files\Shader Files</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="Assets\Shaders\Material.slang">
|
||||||
|
<Filter>Resource Files\Shader Files</Filter>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Blaze\AppState.h">
|
<ClInclude Include="Blaze\AppState.h">
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,7 @@ SDL_AppResult SDL_AppInit( void** appstate, int, char** )
|
||||||
|
|
||||||
AppState& appState = *static_cast<AppState*>( *appstate );
|
AppState& appState = *static_cast<AppState*>( *appstate );
|
||||||
|
|
||||||
Entity const* entity =
|
Entity const* entity = LoadModel( appState.renderDevice, appState.entityManager, "Assets/Models/DamagedHelmet.glb" );
|
||||||
LoadModel( appState.renderDevice, appState.entityManager, "Assets/Models/OrientationTest.glb" );
|
|
||||||
ASSERT( entity );
|
ASSERT( entity );
|
||||||
|
|
||||||
std::array pointLight = {
|
std::array pointLight = {
|
||||||
|
|
@ -58,9 +57,9 @@ SDL_AppResult SDL_AppInit( void** appstate, int, char** )
|
||||||
.attenuation = 1.0f,
|
.attenuation = 1.0f,
|
||||||
},
|
},
|
||||||
MiscData::PointLight{
|
MiscData::PointLight{
|
||||||
.position = { 0.0f, 12.0f, 0.0f },
|
.position = { 0.0f, 3.0f, 0.0f },
|
||||||
.range = 12,
|
.range = 12,
|
||||||
.color = { 0.0f, 1.0f, 0.0f },
|
.color = { 12.0f, 12.0f, 12.0f },
|
||||||
.attenuation = 1.0f,
|
.attenuation = 1.0f,
|
||||||
},
|
},
|
||||||
MiscData::PointLight{
|
MiscData::PointLight{
|
||||||
|
|
@ -263,6 +262,16 @@ SDL_AppResult SDL_AppIterate( void* appstate )
|
||||||
vkCmdPushConstants(
|
vkCmdPushConstants(
|
||||||
cmd, misc.pipelineLayout, VK_SHADER_STAGE_ALL_GRAPHICS, 0, sizeof worldTransform, &worldTransform );
|
cmd, misc.pipelineLayout, VK_SHADER_STAGE_ALL_GRAPHICS, 0, sizeof worldTransform, &worldTransform );
|
||||||
|
|
||||||
|
DirectX::XMMATRIX const inverseTransform = XMMatrixInverse( nullptr, worldTransform );
|
||||||
|
|
||||||
|
vkCmdPushConstants(
|
||||||
|
cmd,
|
||||||
|
misc.pipelineLayout,
|
||||||
|
VK_SHADER_STAGE_ALL_GRAPHICS,
|
||||||
|
sizeof worldTransform,
|
||||||
|
sizeof inverseTransform,
|
||||||
|
&inverseTransform );
|
||||||
|
|
||||||
if ( not entity.modelMesh.isNull() )
|
if ( not entity.modelMesh.isNull() )
|
||||||
{
|
{
|
||||||
ASSERT( current );
|
ASSERT( current );
|
||||||
|
|
@ -286,7 +295,7 @@ SDL_AppResult SDL_AppIterate( void* appstate )
|
||||||
cmd,
|
cmd,
|
||||||
misc.pipelineLayout,
|
misc.pipelineLayout,
|
||||||
VK_SHADER_STAGE_ALL_GRAPHICS,
|
VK_SHADER_STAGE_ALL_GRAPHICS,
|
||||||
sizeof worldTransform,
|
2 * sizeof worldTransform,
|
||||||
Material::GPU_DATA_SIZE,
|
Material::GPU_DATA_SIZE,
|
||||||
materialData );
|
materialData );
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,10 @@ void EntityManager::destroyEntity( Entity* entity )
|
||||||
for ( auto& material : entity->model.materials )
|
for ( auto& material : entity->model.materials )
|
||||||
{
|
{
|
||||||
vkDestroySampler( device, Take( material.sampler ), nullptr );
|
vkDestroySampler( device, Take( material.sampler ), nullptr );
|
||||||
pRenderDevice->textureManager->freeTexture( std::move( material.texture ) );
|
pRenderDevice->textureManager->freeTexture( std::move( material.albedoTextureID ) );
|
||||||
|
pRenderDevice->textureManager->freeTexture( std::move( material.normalTextureID ) );
|
||||||
|
pRenderDevice->textureManager->freeTexture( std::move( material.metalRoughTextureID ) );
|
||||||
|
pRenderDevice->textureManager->freeTexture( std::move( material.emissiveTextureID ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
pRenderDevice->bufferManager->freeBuffer( std::move( entity->model.vertexBuffer ) );
|
pRenderDevice->bufferManager->freeBuffer( std::move( entity->model.vertexBuffer ) );
|
||||||
|
|
|
||||||
|
|
@ -36,3 +36,5 @@
|
||||||
while ( false )
|
while ( false )
|
||||||
|
|
||||||
#define Take( OBJ ) std::exchange( OBJ, {} )
|
#define Take( OBJ ) std::exchange( OBJ, {} )
|
||||||
|
|
||||||
|
#define UNREACHABLE G_ASSERT( false )
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ bool MiscData::init( RenderDevice const& renderDevice )
|
||||||
VkPushConstantRange const pushConstantRange = {
|
VkPushConstantRange const pushConstantRange = {
|
||||||
.stageFlags = VK_SHADER_STAGE_ALL_GRAPHICS,
|
.stageFlags = VK_SHADER_STAGE_ALL_GRAPHICS,
|
||||||
.offset = 0,
|
.offset = 0,
|
||||||
.size = sizeof( DirectX::XMMATRIX ) + Material::GPU_DATA_SIZE,
|
.size = 2 * sizeof( DirectX::XMMATRIX ) + Material::GPU_DATA_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
std::array const descriptorSetLayouts = {
|
std::array const descriptorSetLayouts = {
|
||||||
|
|
@ -123,18 +123,24 @@ bool MiscData::init( RenderDevice const& renderDevice )
|
||||||
VkVertexInputAttributeDescription{
|
VkVertexInputAttributeDescription{
|
||||||
.location = 2,
|
.location = 2,
|
||||||
.binding = 0,
|
.binding = 0,
|
||||||
.format = VK_FORMAT_R32G32_SFLOAT,
|
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
|
||||||
.offset = offsetof( Vertex, texCoord0 ),
|
.offset = offsetof( Vertex, tangent ),
|
||||||
},
|
},
|
||||||
VkVertexInputAttributeDescription{
|
VkVertexInputAttributeDescription{
|
||||||
.location = 3,
|
.location = 3,
|
||||||
.binding = 0,
|
.binding = 0,
|
||||||
.format = VK_FORMAT_R32G32_SFLOAT,
|
.format = VK_FORMAT_R32G32_SFLOAT,
|
||||||
.offset = offsetof( Vertex, texCoord1 ),
|
.offset = offsetof( Vertex, texCoord0 ),
|
||||||
},
|
},
|
||||||
VkVertexInputAttributeDescription{
|
VkVertexInputAttributeDescription{
|
||||||
.location = 4,
|
.location = 4,
|
||||||
.binding = 0,
|
.binding = 0,
|
||||||
|
.format = VK_FORMAT_R32G32_SFLOAT,
|
||||||
|
.offset = offsetof( Vertex, texCoord1 ),
|
||||||
|
},
|
||||||
|
VkVertexInputAttributeDescription{
|
||||||
|
.location = 5,
|
||||||
|
.binding = 0,
|
||||||
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
|
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
|
||||||
.offset = offsetof( Vertex, color0 ),
|
.offset = offsetof( Vertex, color0 ),
|
||||||
},
|
},
|
||||||
|
|
@ -289,7 +295,7 @@ bool MiscData::init( RenderDevice const& renderDevice )
|
||||||
|
|
||||||
// Camera
|
// Camera
|
||||||
{
|
{
|
||||||
cameraData.cameraPosition = DirectX::XMVectorSet( 0.0f, 20.0f, -20.0f, 1.0f );
|
cameraData.cameraPosition = DirectX::XMVectorSet( 0.0f, 2.0f, -2.0f, 1.0f );
|
||||||
cameraTarget = DirectX::XMVectorSet( 0.0f, 0.0f, 0.0f, 1.0f );
|
cameraTarget = DirectX::XMVectorSet( 0.0f, 0.0f, 0.0f, 1.0f );
|
||||||
cameraUp = DirectX::XMVectorSet( 0.0f, 1.0f, 0.0f, 1.0f );
|
cameraUp = DirectX::XMVectorSet( 0.0f, 1.0f, 0.0f, 1.0f );
|
||||||
cameraData.viewMatrix = DirectX::XMMatrixLookAtLH( cameraData.cameraPosition, cameraTarget, cameraUp );
|
cameraData.viewMatrix = DirectX::XMMatrixLookAtLH( cameraData.cameraPosition, cameraTarget, cameraUp );
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -14,8 +14,9 @@ struct GlobalMemory;
|
||||||
|
|
||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
DirectX::XMFLOAT3 position = { 0.0f, 0.0f, 0.0f };
|
DirectX::XMFLOAT4 position = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||||
DirectX::XMFLOAT3 normal = { 1.0f, 1.0f, 1.0f };
|
DirectX::XMFLOAT4 normal = { 0.0f, 0.0f, 1.0f, 0.0f };
|
||||||
|
DirectX::XMFLOAT4 tangent = { 1.0f, 0.0f, 0.0f, 0.0f };
|
||||||
DirectX::XMFLOAT2 texCoord0 = { 0.0f, 0.0f };
|
DirectX::XMFLOAT2 texCoord0 = { 0.0f, 0.0f };
|
||||||
DirectX::XMFLOAT2 texCoord1 = { 0.0f, 0.0f };
|
DirectX::XMFLOAT2 texCoord1 = { 0.0f, 0.0f };
|
||||||
DirectX::XMFLOAT4 color0 = { 1.0f, 1.0f, 1.0f, 1.0f };
|
DirectX::XMFLOAT4 color0 = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||||
|
|
@ -42,21 +43,23 @@ struct ModelMesh
|
||||||
|
|
||||||
struct Material
|
struct Material
|
||||||
{
|
{
|
||||||
constexpr static size_t GPU_DATA_OFFSET = sizeof( VkSampler );
|
size_t constexpr static GPU_DATA_OFFSET = sizeof( VkSampler );
|
||||||
constexpr static size_t GPU_DATA_SIZE =
|
size_t constexpr static GPU_DATA_SIZE = 56;
|
||||||
sizeof( TextureID ) + sizeof( uint32_t ) + 2 * sizeof( float ) + sizeof( DirectX::XMFLOAT4 );
|
|
||||||
|
|
||||||
VkSampler sampler; // TODO: Reuse
|
VkSampler sampler; // TODO: Reuse
|
||||||
// To copy directly.
|
// To copy directly.
|
||||||
TextureID texture;
|
DirectX::XMFLOAT4 baseColor = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||||
uint32_t padding0; // FIXME: Wasting space.
|
DirectX::XMFLOAT4 emission = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||||
|
TextureID albedoTextureID;
|
||||||
|
TextureID normalTextureID;
|
||||||
|
TextureID metalRoughTextureID;
|
||||||
|
TextureID emissiveTextureID;
|
||||||
float roughness = 1.0f;
|
float roughness = 1.0f;
|
||||||
float metallic = 1.0f;
|
float metallic = 1.0f;
|
||||||
DirectX::XMFLOAT4 baseColor = { 1.0f, 1.0f, 1.0f, 1.0f };
|
|
||||||
|
|
||||||
[[nodiscard]] bool isNull() const
|
[[nodiscard]] bool isNull() const
|
||||||
{
|
{
|
||||||
return texture.isNull() or sampler;
|
return not( albedoTextureID and normalTextureID and metalRoughTextureID and emissiveTextureID and sampler );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
template struct RID<Texture>;
|
template struct RID<Texture>;
|
||||||
|
|
||||||
std::optional<TextureID> TextureManager::createTexture( VkExtent3D const extent, VkSampler sampler )
|
std::optional<TextureID> TextureManager::createTexture( VkExtent3D const extent, VkSampler const sampler, VkFormat const format )
|
||||||
{
|
{
|
||||||
if ( m_freeList.empty() )
|
if ( m_freeList.empty() )
|
||||||
{
|
{
|
||||||
|
|
@ -20,8 +20,6 @@ std::optional<TextureID> TextureManager::createTexture( VkExtent3D const extent,
|
||||||
ASSERT( m_pRenderDevice );
|
ASSERT( m_pRenderDevice );
|
||||||
RenderDevice const& renderDevice = *m_pRenderDevice;
|
RenderDevice const& renderDevice = *m_pRenderDevice;
|
||||||
|
|
||||||
VkFormat const format = VK_FORMAT_R8G8B8A8_SRGB;
|
|
||||||
|
|
||||||
VkImage texture;
|
VkImage texture;
|
||||||
VmaAllocation textureAllocation;
|
VmaAllocation textureAllocation;
|
||||||
VkImageView textureView;
|
VkImageView textureView;
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,8 @@ public:
|
||||||
void freeTexture( TextureID&& rid );
|
void freeTexture( TextureID&& rid );
|
||||||
|
|
||||||
DEPRECATE_JULY_2025
|
DEPRECATE_JULY_2025
|
||||||
[[nodiscard]] std::optional<TextureID> createTexture( VkExtent3D extent, VkSampler sampler );
|
[[nodiscard]] std::optional<TextureID> createTexture(
|
||||||
|
VkExtent3D extent, VkSampler sampler, VkFormat format = VK_FORMAT_R8G8B8A8_SRGB );
|
||||||
|
|
||||||
DEPRECATE_JULY_2025
|
DEPRECATE_JULY_2025
|
||||||
std::optional<VkImage> fetchImage( TextureID const& rid );
|
std::optional<VkImage> fetchImage( TextureID const& rid );
|
||||||
|
|
|
||||||
7
PLAN.md
7
PLAN.md
|
|
@ -21,7 +21,12 @@
|
||||||
- [X] Create Vertex buffer
|
- [X] Create Vertex buffer
|
||||||
- [X] Load texture
|
- [X] Load texture
|
||||||
- [X] Draw
|
- [X] Draw
|
||||||
- [ ] Refactor
|
- [ ] Render Sponza
|
||||||
|
- [X] Load GLTF Scene
|
||||||
|
- [ ] Support Albedo
|
||||||
|
- [ ] Support Normal
|
||||||
|
- [ ] Support Metal/Rough
|
||||||
|
- [ ] Support Emission
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
- [ ] Scene Rendering
|
- [ ] Scene Rendering
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue