Team Ai
Apppublic

OpenMotionLab/MotionGPT

sourceHugging Facemitupdated 1y agoView on Hugging Face
118likes
flat.frag127 linesDownload Raw Back to shaders
1#version 330 core2///////////////////////////////////////////////////////////////////////////////3// Structs4///////////////////////////////////////////////////////////////////////////////5 6struct Material {7    vec3 emissive_factor;8 9#ifdef USE_METALLIC_MATERIAL10    vec4 base_color_factor;11    float metallic_factor;12    float roughness_factor;13#endif14 15#ifdef USE_GLOSSY_MATERIAL16    vec4 diffuse_factor;17    vec3 specular_factor;18    float glossiness_factor;19#endif20 21#ifdef HAS_NORMAL_TEX22    sampler2D normal_texture;23#endif24#ifdef HAS_OCCLUSION_TEX25    sampler2D occlusion_texture;26#endif27#ifdef HAS_EMISSIVE_TEX28    sampler2D emissive_texture;29#endif30#ifdef HAS_BASE_COLOR_TEX31    sampler2D base_color_texture;32#endif33#ifdef HAS_METALLIC_ROUGHNESS_TEX34    sampler2D metallic_roughness_texture;35#endif36#ifdef HAS_DIFFUSE_TEX37    sampler2D diffuse_texture;38#endif39#ifdef HAS_SPECULAR_GLOSSINESS_TEX40    sampler2D specular_glossiness;41#endif42};43 44///////////////////////////////////////////////////////////////////////////////45// Uniforms46///////////////////////////////////////////////////////////////////////////////47uniform Material material;48uniform vec3 cam_pos;49 50#ifdef USE_IBL51uniform samplerCube diffuse_env;52uniform samplerCube specular_env;53#endif54 55///////////////////////////////////////////////////////////////////////////////56// Inputs57///////////////////////////////////////////////////////////////////////////////58 59in vec3 frag_position;60#ifdef NORMAL_LOC61in vec3 frag_normal;62#endif63#ifdef HAS_NORMAL_TEX64#ifdef TANGENT_LOC65#ifdef NORMAL_LOC66in mat3 tbn;67#endif68#endif69#endif70#ifdef TEXCOORD_0_LOC71in vec2 uv_0;72#endif73#ifdef TEXCOORD_1_LOC74in vec2 uv_1;75#endif76#ifdef COLOR_0_LOC77in vec4 color_multiplier;78#endif79 80///////////////////////////////////////////////////////////////////////////////81// OUTPUTS82///////////////////////////////////////////////////////////////////////////////83 84out vec4 frag_color;85 86///////////////////////////////////////////////////////////////////////////////87// Constants88///////////////////////////////////////////////////////////////////////////////89const float PI = 3.141592653589793;90const float min_roughness = 0.04;91 92///////////////////////////////////////////////////////////////////////////////93// Utility Functions94///////////////////////////////////////////////////////////////////////////////95vec4 srgb_to_linear(vec4 srgb)96{97#ifndef SRGB_CORRECTED98    // Fast Approximation99    //vec3 linOut = pow(srgbIn.xyz,vec3(2.2));100    //101    vec3 b_less = step(vec3(0.04045),srgb.xyz);102    vec3 lin_out = mix( srgb.xyz/vec3(12.92), pow((srgb.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), b_less );103    return vec4(lin_out, srgb.w);104#else105    return srgb;106#endif107}108 109///////////////////////////////////////////////////////////////////////////////110// MAIN111///////////////////////////////////////////////////////////////////////////////112void main()113{114 115    // Compute albedo116    vec4 base_color = material.base_color_factor;117#ifdef HAS_BASE_COLOR_TEX118    base_color = base_color * texture(material.base_color_texture, uv_0);119#endif120 121#ifdef COLOR_0_LOC122    base_color *= color_multiplier;123#endif124 125    frag_color = clamp(base_color, 0.0, 1.0);126}127