<commit_before>/**
 * Copyright (c) 2021 <NAME>
 * Licensed under the MIT License.
 * See LICENSE file for more information.
 */

#ifndef HSV_H
#define HSV_H

#include "shaderConfig.h"


// https://aras-p.info/texts/CompactNormalStorage.html#method04spheremap
FUNC_DECL vec2 PackNormalSpheremap(const vec3& n)
{
    float p  = sqrt(n.z() * 8 + 8);
    vec2 enc = vec2(n[0], n[1]) * (1.f / p);
    // enc += vec2(0.5f, 0.5f);
    return enc;
}

FUNC_DECL vec3 UnpackNormalSpheremap(const vec2& enc)
{
    // vec2 fenc = enc * 4 - vec2(2, 2);
    vec2 fenc = enc * 4;
    float f   = fenc.dot(fenc);
    if (f != f)
    {
        return vec3(0, 0, -1);
    }
    float g = sqrt(max(1 - f * 0.25f, 0.f));
    vec3 n(fenc[0] * g, fenc[1] * g, 1 - f * 0.5f);
    return n;
}

// https://aras-p.info/texts/CompactNormalStorage.html#method07stereo
FUNC_DECL vec2 PackNormalStereographic(vec3 n)
{
    float scale = 1.7777;<commit_msg>fix include guard<commit_after>/**
 * Copyright (c) 2021 <NAME>
 * Licensed under the MIT License.
 * See LICENSE file for more information.
 */

#ifndef NORMAL_PACKING_H
#define NORMAL_PACKING_H

#include "shaderConfig.h"


// https://aras-p.info/texts/CompactNormalStorage.html#method04spheremap
FUNC_DECL vec2 PackNormalSpheremap(const vec3& n)
{
    float p  = sqrt(n.z() * 8 + 8);
    vec2 enc = vec2(n[0], n[1]) * (1.f / p);
    // enc += vec2(0.5f, 0.5f);
    return enc;
}

FUNC_DECL vec3 UnpackNormalSpheremap(const vec2& enc)
{
    // vec2 fenc = enc * 4 - vec2(2, 2);
    vec2 fenc = enc * 4;
    float f   = fenc.dot(fenc);
    if (f != f)
    {
        return vec3(0, 0, -1);
    }
    float g = sqrt(max(1 - f * 0.25f, 0.f));
    vec3 n(fenc[0] * g, fenc[1] * g, 1 - f * 0.5f);
    return n;
}

// https://aras-p.info/texts/CompactNormalStorage.html#method07stereo
FUNC_DECL vec2 PackNormalStereographic(vec3 n)
{
    float scale = 1.7777;
{'fraction_non_alphanumeric': 0.1595744680851064, 'fraction_numerical': 0.05638297872340425, 'mean_word_length': 2.784708249496982, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6944325', 'n_tokens_mistral': 833, 'n_tokens_neox': 771, 'n_words': 187}