procedural-3d-engine/data/shaders/hlsl/deferredmultisampling/deferred.frag
Sascha Willems feb939096f
Merge glTF branch (#747)
* Added helper function for easy pipeline vertex input state create info structure setup from glTF model vertex class

* Split glTF loader into header and implementation

* Updated sample to use glTF

* Removed collada files

Replaced assets are now part of the asset pack

* Return value for glTF model vertex input state create info helper

* Removed unused assets

* Use glTF assets

* Added default material for glTF node's without materials

* Use glTF assets

* Apply pre-transforms to normals

* Use glTF assets

* Use glTF assets

* Use vertex input state from glTF model class

* Scene setup

* Use glTF assets

* Use glTF assets

* Display error message and exit if glTF file could not be loaded

* Use glTF assets

* Use glTF assets

* Use glTF assets

* Remove unused buffer binds

* Use glTF assets

* Remove no longer used model files

* Remove no longer used model files

* Added support for rendering glTF models with images

* glTF model normal pre-transform ignores translation

* Use glTF assets

* Use glTF assets

* Use glTF assets

* Use glTF assets

* Use glTF assets

* Only add combined image samplers to pool if actually used in the scene

* Use global descriptor set layouts

* Use global descriptor set layouts

* Use glTF assets

* Use glTF assets

* Use glTF assets

Code cleanup
Updated GLSL and HLSL shaders

* Use glTF assets

Code cleanup

* Use glTF assets

Code cleanup
Updated GLSL and HLSL shaders

* Remove no-longer used model

* Use glTF assets

Code cleanup
Updated GLSL and HLSL shaders

* Use glTF assets

Code cleanup
Updated GLSL and HLSL shaders
Removed no-longer used model

* Use glTF assets

Code cleanup
Use RGBA texture instead of different compressed formats
Removed no-longer used assets

* Adnrdoid build file

* Use glTF assets

Code cleanup and refactoring
Updated GLSL and HLSL shaders

* Added vertex count and way of passing additional memory property type flags to glTF loader

* Use glTF assets

Updated GLSL and HLSL shaders
Removed no-longer used assets

* Use glTF assets

Updated GLSL and HLSL shaders

* Remove unfinished sample

* Completely reworked push constants sample

Use glTF assets
Updated GLSL and HLSL shaders
Removed no-longer used assets

* Android CMake build files

* Removed un-used asset

* Explicit buffer binding function

* Use glTF assets

Code cleanup
Updated GLSL and HLSL shaders

* Use glTF assets

Code cleanup

* Use glTF assets

Code cleanup
Removed no-longer used assets

* Use glTF assets

Code cleanup
Updated GLSL and HLSL shaders
Removed no-longer used assets

* Remove no-longer used asset

* Use glTF assets

Code cleanup and refactoring
Performance optimizations
Updated GLSL and HLSL shaders
Removed no-longer used assets

* Use glTF assets

Code cleanup and refactoring
Updated GLSL and HLSL shaders
Removed no-longer used assets

* Use glTF assets

Code cleanup and refactoring
Updated GLSL and HLSL shaders
Removed no-longer used assets

* Use glTF assets

Code cleanup and refactoring
Removed no-longer used assets

* Use glTF assets

Code cleanup and refactoring
Removed no-longer used assets

* Use glTF assets

Code cleanup and refactoring

* Use glTF assets

Code cleanup and refactoring

* Use glTF assets

Code cleanup and refactoring
Removed no-longer used assets

* Pass vertex size and calculate multiplier in shaders instead of hard-coding

With this, changes to the glTF vertex structure won't break the ray tracing samples

* Load tangents (if present)

* Use glTF assets

Code cleanup and heavy refactoring
Reworked debug display code

* Android build

* Normal mapping fixes

Udpated HLSL shaders

* Use glTF assets

Code cleanup and heavy refactoring
Reworked debug display code
Updated GLSL and HLSL shaders

* Code cleanup, comments

* Use glTF assets

Code cleanup and heavy refactoring
Reworked debug display code
Updated GLSL and HLSL shaders

* Added sample count to framebuffer create info

* Removed no-longer used assets

* Android build

Removed no-longer used assets

* Code cleanup and heavy refactoring

Updated GLSL and HLSL shaders
Use tangents stored in GLSL instead of calculating them in the fragment shader

* Renamed textured PBR sample main cpp file

* Use glTF assets

Code cleanup and refactoring
Updated GLSL and HLSL shaders
Removed no-longer used assets

* Use glTF assets

Removed no-longer used assets

* Android build files

* Android build files

* Use glTF assets

Removed no-longer used assets

* Fixed HLSL shaders

* Android build files

* Use glTF assets

Updated GLSL and HLSL shaders
Removed no-longer used assets

* Use glTF assets

Updated GLSL and HLSL shaders
Removed no-longer used assets

* Added flag to disable glTF image loading

Useful for samples that use their own textures or don't use textures at all to speed up loading

* Use glTF assets

Code cleanup
Use Sponza scene instead of Sibenik to better highlight the effect
Updated GLSL and HLSL shaders

* Updated Android build files

* Removed left-over comment

* Use Sponza scene for the SSAO sample

* Removed unused code

* Removed ASSIMP

No longer required as all samples now use the glTF file format

* Added missing vertex shader stage

* Removed old ASSIMP-based model loader

* Added support for loading external glTF images from ktx

Android fixes for loading external buffer files

* Scene setup

* Added missing shader stages

* Removed ASSIMP from build files

* Fixed compiler warning

* Removed ASSIMP from readmes

* Android build files cleanup

* Replaced ktx submodule with only the files required for this repo

The ktx submodule was a tad too big and contained lots of files not required for this repo

* Moved ktx build files into base project

* Use glTF assets

* Use glTF assets

* Removed license files, will be moved to asset pack

* Use RGBA textures

* Use RGBA cubemp texture with face assignment based on original images

Refs #679

* Android build files

* Removed textures

All textures will be moved to the asset pack

* Ignore asset folders

* Removed font

Fonts will be moved to the asset pack

* Link to gltf asset pack

* Updated gitignore

* Android build file
2020-07-28 20:20:38 +02:00

125 lines
No EOL
3 KiB
GLSL

// Copyright 2020 Google LLC
Texture2DMS<float4> texturePosition : register(t1);
SamplerState samplerPosition : register(s1);
Texture2DMS<float4> textureNormal : register(t2);
SamplerState samplerNormal : register(s2);
Texture2DMS<float4> textureAlbedo : register(t3);
SamplerState samplerAlbedo : register(s3);
struct Light {
float4 position;
float3 color;
float radius;
};
struct UBO
{
Light lights[6];
float4 viewPos;
int debugDisplayTarget;
};
cbuffer ubo : register(b4) { UBO ubo; }
[[vk::constant_id(0)]] const int NUM_SAMPLES = 8;
#define NUM_LIGHTS 6
// Manual resolve for MSAA samples
float4 resolve(Texture2DMS<float4> tex, int2 uv)
{
float4 result = float4(0.0, 0.0, 0.0, 0.0);
for (int i = 0; i < NUM_SAMPLES; i++)
{
uint status = 0;
float4 val = tex.Load(uv, i, int2(0, 0), status);
result += val;
}
// Average resolved samples
return result / float(NUM_SAMPLES);
}
float3 calculateLighting(float3 pos, float3 normal, float4 albedo)
{
float3 result = float3(0.0, 0.0, 0.0);
for(int i = 0; i < NUM_LIGHTS; ++i)
{
// Vector to light
float3 L = ubo.lights[i].position.xyz - pos;
// Distance from light to fragment position
float dist = length(L);
// Viewer to fragment
float3 V = ubo.viewPos.xyz - pos;
V = normalize(V);
// Light to fragment
L = normalize(L);
// Attenuation
float atten = ubo.lights[i].radius / (pow(dist, 2.0) + 1.0);
// Diffuse part
float3 N = normalize(normal);
float NdotL = max(0.0, dot(N, L));
float3 diff = ubo.lights[i].color * albedo.rgb * NdotL * atten;
// Specular part
float3 R = reflect(-L, N);
float NdotR = max(0.0, dot(R, V));
float3 spec = ubo.lights[i].color * albedo.a * pow(NdotR, 8.0) * atten;
result += diff + spec;
}
return result;
}
float4 main([[vk::location(0)]] float2 inUV : TEXCOORD0) : SV_TARGET
{
int2 attDim; int sampleCount;
texturePosition.GetDimensions(attDim.x, attDim.y, sampleCount);
int2 UV = int2(inUV * attDim);
float3 fragColor;
uint status = 0;
// Debug display
if (ubo.debugDisplayTarget > 0) {
switch (ubo.debugDisplayTarget) {
case 1:
fragColor.rgb = texturePosition.Load(UV, 0, int2(0, 0), status).rgb;
break;
case 2:
fragColor.rgb = textureNormal.Load(UV, 0, int2(0, 0), status).rgb;
break;
case 3:
fragColor.rgb = textureAlbedo.Load(UV, 0, int2(0, 0), status).rgb;
break;
case 4:
fragColor.rgb = textureAlbedo.Load(UV, 0, int2(0, 0), status).aaa;
break;
}
return float4(fragColor, 1.0);
}
#define ambient 0.15
// Ambient part
float4 alb = resolve(textureAlbedo, UV);
fragColor = float3(0.0, 0.0, 0.0);
// Calualte lighting for every MSAA sample
for (int i = 0; i < NUM_SAMPLES; i++)
{
float3 pos = texturePosition.Load(UV, i, int2(0, 0), status).rgb;
float3 normal = textureNormal.Load(UV, i, int2(0, 0), status).rgb;
float4 albedo = textureAlbedo.Load(UV, i, int2(0, 0), status);
fragColor += calculateLighting(pos, normal, albedo);
}
fragColor = (alb.rgb * ambient) + fragColor / float(NUM_SAMPLES);
return float4(fragColor, 1.0);
}