Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
prism/engine/base/shaders/brdf.frag.glsl
Joshua Goins ca2c2c9d3d Move all engine-specific models, materials etc. to a new base directory
This is a huge change, and basically breaks everything (as per usual!)

First of, this includes stuff like shaders so anything involving those
are broken and then fixed. A new BuildAssets cmake file is added to
aid in running AssetCompiler, and it seems to work fine on the engine
base assets.

The File API will eventually be revamped to handle this new way of
organizing the files and domains will eventually be gotten rid of all
together since I probably will replace it with game directory
priorities. As it stands right now, there isn't a way to easily
replace say - render_options.cfg with your own game-specific version.

Apple builds are probably broken by this commit (since I'm moving
around content and shader directories) to be fixed later.
2022-05-21 18:28:48 -04:00

48 lines
1.3 KiB
GLSL

#include "common.nocompile.glsl"
layout(location = 0) in vec2 inUV;
layout(location = 0) out vec2 outColor;
vec2 IntegrateBRDF(float NdotV, float roughness) {
vec3 V;
V.x = sqrt(1.0 - NdotV*NdotV);
V.y = 0.0;
V.z = NdotV;
float A = 0.0;
float B = 0.0;
const vec3 N = vec3(0.0, 0.0, 1.0);
const uint SAMPLE_COUNT = 1024u;
for(uint i = 0u; i < SAMPLE_COUNT; ++i) {
// generates a sample vector that's biased towards the
// preferred alignment direction (importance sampling).
const vec2 Xi = hammersley(i, SAMPLE_COUNT);
const vec3 H = importance_sample_ggx(Xi, N, roughness);
const vec3 L = 2.0 * dot(V, H) * H - V;
const float NdotL = max(L.z, 0.0);
const float NdotH = max(H.z, 0.0);
const float VdotH = max(dot(V, H), 0.0);
if(NdotL > 0.0) {
const float G = geometry_smith(N, V, L, roughness);
const float G_Vis = (G * VdotH) / (NdotH * NdotV);
const float Fc = pow(1.0 - VdotH, 5.0);
A += (1.0 - Fc) * G_Vis;
B += Fc * G_Vis;
}
}
A /= float(SAMPLE_COUNT);
B /= float(SAMPLE_COUNT);
return vec2(A, B);
}
void main() {
outColor = IntegrateBRDF(inUV.x, inUV.y);
}