### IOR to F0 Conversion Formula and Example Source: https://context7.com/rre36/lab-pbr/llms.txt Provides the formula for converting Index of Refraction (IOR) to F0 reflectance and the method for calculating the labPBR green channel value. Includes examples for common materials. ```text Formula reference (manual conversion): F0 = ((IOR - 1) / (IOR + 1))^2 labPBR green channel value = round(F0 * 229) // max dielectric value = 229 Example: Water IOR ≈ 1.333 → F0 ≈ 0.020 → green ≈ 5 Glass IOR ≈ 1.500 → F0 ≈ 0.040 → green ≈ 9 Diamond IOR ≈ 2.417 → F0 ≈ 0.172 → green ≈ 39 ``` -------------------------------- ### Apply Porosity-Based Wetness Simulation in GLSL Source: https://context7.com/rre36/lab-pbr/llms.txt This GLSL snippet demonstrates how to simulate wetness effects based on material porosity. Porosity, decoded from the blue channel of a specular map, controls how much a material darkens and loses reflectance when wet. ```glsl // --- Applying porosity-based wetness in a shader --- // wetness: 0.0 = dry, 1.0 = fully saturated (driven by weather/puddle system) uniform float wetness; // porosity decoded from blue channel (see specular map decoding above) // float porosity = ...; // 0.0–1.0 float wetnessEffect = porosity * wetness; // Darken albedo when wet vec3 wetAlbedo = albedo * (1.0 - wetnessEffect * 0.3); // Reduce roughness (surface becomes smoother when wet) float wetRoughness = mix(linearRoughness, 0.0, wetnessEffect); // Representative porosity reference values: // Sand → porosity raw value 64 (1.00 normalized) // Wool → porosity raw value 38 (0.59 normalized) // Wood → porosity raw value 12 (0.19 normalized) // Metal → porosity raw value 0 (0.00 normalized — impermeable) ``` -------------------------------- ### LAB-PBR Metal Data Lookup Table in GLSL Source: https://context7.com/rre36/lab-pbr/llms.txt This GLSL code provides a lookup table for predefined metal N (IOR) and K (extinction) values based on the metal ID extracted from the green channel of the _s texture. It also handles the custom metal case where the albedo texture is used as F0. ```glsl // Predefined metal N (IOR) and K (extinction) values — labPBR v1.3 // Usage: look up by metalID = int(specSample.g * 255.0) struct MetalData { vec3 N; vec3 K; }; MetalData getMetalData(int id) { if (id == 230) return MetalData(vec3(2.9114, 2.9497, 2.5845), vec3(3.0893, 2.9318, 2.7670)); // Iron if (id == 231) return MetalData(vec3(0.18299, 0.42108, 1.3734), vec3(3.4242, 2.3459, 1.7704)); // Gold if (id == 232) return MetalData(vec3(1.3456, 0.96521, 0.61722), vec3(7.4746, 6.3995, 5.3031)); // Aluminum if (id == 233) return MetalData(vec3(3.1071, 3.1812, 2.3230), vec3(3.3314, 3.3291, 3.1350)); // Chrome if (id == 234) return MetalData(vec3(0.27105, 0.67693, 1.3164), vec3(3.6092, 2.6248, 2.2921)); // Copper if (id == 235) return MetalData(vec3(1.9100, 1.8300, 1.4400), vec3(3.5100, 3.4000, 3.1800)); // Lead if (id == 236) return MetalData(vec3(2.3757, 2.0847, 1.8453), vec3(4.2655, 3.7153, 3.1365)); // Platinum if (id == 237) return MetalData(vec3(0.15943, 0.14512, 0.13547), vec3(3.9291, 3.1900, 2.3808)); // Silver // id == 255: use albedo as F0 (custom metal) return MetalData(vec3(0.0), vec3(0.0)); } ``` -------------------------------- ### labPBR Compliance Checklist for Shaderpacks Source: https://context7.com/rre36/lab-pbr/llms.txt This GLSL code outlines the required and optional components for a shaderpack to be compliant with labPBR. It details texture channel assignments and shader logic that must be implemented. ```glsl // ===================================================================== // REQUIRED for labPBR compliance (shaderpack side) // ===================================================================== // 1. Decode RGB channels of _s into correct material data (see above). // 2. Decode F0/reflectance from green channel; handle metal range 230–255. // - Hardcoded metals (230–237) are OPTIONAL. // 3. Reconstruct normal Z from XY using: float z = sqrt(max(0.0, 1.0 - dot(normal.xy, normal.xy))); // ===================================================================== // OPTIONAL (must be on by default if implemented, except POM) // ===================================================================== // 4. Porosity — blue channel of _s, values 0–64 // 5. SSS — blue channel of _s, values 65–255 // 6. Emission — alpha channel of _s, values 0–254 (255 = ignore) // 7. Material AO — blue channel of _n, values 0–255 (0 = max AO) // 8. POM — alpha channel of _n as heightmap (can be off by default) // 9. Hardcoded metals — green channel 230–237 // ===================================================================== // REQUIRED for labPBR compliance (resource pack side) // ===================================================================== // 1. Use correct channel assignments in _s texture (see spec above). // OPTIONAL (resource pack side): // - Provide a normalmap (_n) // - Store heightmap in _n alpha // - Use material AO in _n blue // - Provide porosity data in _s blue (0–64) // - Use emission in _s alpha (0–254) // - Use SSS in _s blue (65–255) ``` -------------------------------- ### labPBR F0 Storage Encoding Source: https://context7.com/rre36/lab-pbr/llms.txt Explains the change in F0 (reflectance at normal incidence) storage from a square-rooted value to linear storage in labPBR v1.3. The maximum dielectric value is noted. ```text Previous encoding: f0 was stored as sqrt(f0) and decoded by squaring: f0_linear = f0_stored^2. New encoding: f0_linear = f0_stored (direct linear storage). Note: value 229/255 ≈ 0.898 represents the maximum dielectric F0, NOT 1.0, preserving the metal ID range above 229. ``` -------------------------------- ### Decode Material AO in Shaderpack Source: https://github.com/rre36/lab-pbr/wiki/Version-History This code demonstrates how material AO was decoded in shaderpacks for labPBR v1.2. It involves normalizing the normalmap and extracting AO based on the texture's RGB length. ```glsl normals = normalize(normalTexture.rgb); ao = length(normalTexture.rgb); ``` -------------------------------- ### labPBR AO Storage Encoding Source: https://context7.com/rre36/lab-pbr/llms.txt Compares the previous and current methods for storing Ambient Occlusion (AO) in the normal map for labPBR. The new encoding stores AO directly in the blue channel. ```text Previous encoding (v1.1 and earlier): • Bring normalmap XYZ into [-1, 1] and normalize. • Multiply sqrt(ao) (range 17–255) into the normal. • AO decoded in shader: normals = normalize(normalTexture.rgb); ao = length(normalTexture.rgb); New encoding (v1.2+): • AO stored directly in the blue channel (linear, 0–255). • Z reconstructed via: sqrt(1.0 - dot(normal.xy, normal.xy)) ``` -------------------------------- ### Decode Normal Map (_n) Texture in GLSL Source: https://context7.com/rre36/lab-pbr/llms.txt This snippet shows how to decode the XY components of the surface normal, material ambient occlusion (AO), and heightmap from a single _n texture in a GLSL shader. The Z component of the normal is reconstructed mathematically. ```glsl // --- Decoding the _n (normal) texture in a GLSL shader --- uniform sampler2D normalTex; // bound to the _n texture vec4 normSample = texture2D(normalTex, texcoord); // Red / Green: normal XY, remapped from [0,1] to [-1,1] vec2 normalXY = normSample.rg * 2.0 - 1.0; // Blue: material AO — stored linearly; 0 = max occlusion, 255 = no occlusion float materialAO = normSample.b; // 0.0 (fully occluded) to 1.0 (unoccluded) // Alpha: heightmap for POM — minimum value of 1 recommended to avoid shader artefacts float height = normSample.a; // 0.0 represents 25% depth; use ≥ 1/255 in practice // Reconstruct Z component (Pythagorean theorem, normal is unit-length) float normalZ = sqrt(max(0.0, 1.0 - dot(normalXY, normalXY))); vec3 normal = normalize(vec3(normalXY, normalZ)); // --- Example: applying material AO to ambient lighting --- vec3 ambientColor = vec3(0.3, 0.3, 0.35); vec3 litAmbient = ambientColor * materialAO; // --- Example: using heightmap for basic POM offset --- // (actual POM is shader-specific; this is a simplified illustration) vec2 pomOffset = viewDir.xy * (1.0 - height) * pomDepthScale; vec2 pomCoord = texcoord + pomOffset; ``` -------------------------------- ### Decode Specular Map (_s) in GLSL Source: https://context7.com/rre36/lab-pbr/llms.txt This GLSL code decodes the various material properties encoded in the red, green, blue, and alpha channels of the _s (specular) texture map according to the LAB-PBR format. It handles smoothness, reflectance (F0), metalness, porosity, subsurface scattering, and emissiveness. ```glsl // --- Decoding the _s (specular) texture in a GLSL shader uniform sampler2D specularTex; // bound to the _s texture vec4 specSample = texture2D(specularTex, texcoord); // Red channel: perceptual smoothness → linear roughness float perceptualSmoothness = specSample.r; float linearRoughness = pow(1.0 - perceptualSmoothness, 2.0); // Inverse: perceptualSmoothness = 1.0 - sqrt(linearRoughness); // Green channel: F0 reflectance (0–229) or metal ID (230–255) float f0Raw = specSample.g * 255.0; float f0; bool isMetal = false; int metalID = 0; if (f0Raw >= 230.0) { // Hardcoded metal (230 = Iron, 231 = Gold, … 237 = Silver, 255 = custom albedo-as-F0) isMetal = true; metalID = int(f0Raw); // use lookup table below } else { // Dielectric: f0 stored linearly (v1.3+) f0 = f0Raw / 255.0; // value 229 → ~0.898 (not 1.0) } // Blue channel: porosity (0–64) or SSS (65–255) on dielectrics float blueVal = specSample.b * 255.0; float porosity = 0.0; float sss = 0.0; if (!isMetal) { if (blueVal <= 64.0) { porosity = blueVal / 64.0; // 0.0 (dry) – 1.0 (max absorbent) } else { sss = (blueVal - 65.0) / 190.0; } } // Alpha channel: emissiveness (0 = none, 254 = full; 255 = ignore) float emissive = 0.0; if (specSample.a * 255.0 < 255.0) { emissive = specSample.a * (255.0 / 254.0); // remap to [0, 1] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.