# Copyright (c) 2022, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#

class ShaderPresets:
    SHADERS = {

        "Minimal Volume Shader": """\
NV_IDX_XAC_VERSION_1_0

using namespace nv::index::xac;

class Volume_sample_program
{
    NV_IDX_VOLUME_SAMPLE_PROGRAM
public:
    NV_IDX_DEVICE_INLINE_MEMBER
    void initialize() {}

    NV_IDX_DEVICE_INLINE_MEMBER
    int execute(
        const Sample_info_self& sample_info,
              Sample_output&    sample_output)
    {
        // get reference to the volume and its colormap
        const auto& volume = state.self;
        const Colormap& colormap = state.self.get_colormap();

        // generate a volume sampler
        const auto sampler = volume.generate_sampler<float>();

        // get current sample position
        const float3& sample_position = sample_info.sample_position_object_space;

        // sample the volume at the current position
        const float sample_value = sampler.fetch_sample(sample_position);

        // apply the colormap
        const float4 sample_color = colormap.lookup(sample_value);

        // store the output color
        sample_output.set_color(sample_color);

        return NV_IDX_PROG_OK;
    }
};
""",

        "Red Shader": """\
NV_IDX_XAC_VERSION_1_0

using namespace nv::index::xac;

class Volume_sample_program
{
    NV_IDX_VOLUME_SAMPLE_PROGRAM
public:
    NV_IDX_DEVICE_INLINE_MEMBER
    void initialize() {}

    NV_IDX_DEVICE_INLINE_MEMBER
    int execute(
        const Sample_info_self& sample_info,
              Sample_output&    sample_output)
    {
        // get reference to the volume and its colormap
        const auto& volume = state.self;
        const Colormap& colormap = state.self.get_colormap();

        // generate a volume sampler
        const auto sampler = volume.generate_sampler<float>();

        // get current sample position
        const float3& sample_position = sample_info.sample_position_object_space;

        // sample the volume at the current position
        const float sample_value = sampler.fetch_sample(sample_position);

        // apply the colormap
        float4 sample_color = colormap.lookup(sample_value);

        // make it more reddish
        sample_color.x = 1.f;

        // store the output color
        sample_output.set_color(sample_color);

        return NV_IDX_PROG_OK;
    }
};
""",

    }

    def get_labels():
        return list(ShaderPresets.SHADERS.keys())

    def get(label):
        if label in ShaderPresets.SHADERS:
            return ShaderPresets.SHADERS[label]
        else:
            return None

    def has(label):
        return (label in ShaderPresets.SHADERS)
