Sunday, July 24, 2022
HomeGame Developmentopengl - match GLTF/assimp/unreal materials phrases to my shader

opengl – match GLTF/assimp/unreal materials phrases to my shader


I am making an attempt to render a easy scene I exported from unreal engine. I exported it as gltf, and it seems okay in blender and home windows preview.
however whereas loading this mannequin in my code, I do not know the way to map sure properties to my shader, and that is the place I ask you.

That is the piece of my fragment shader chargeable for “lighting up” the scene. The LightIndex is solely an index into an array of PointLightData. MaterialDiffuse, MaterialSpecular and MaterialShininess are learn both from a texture, vertex array or uniform, relying if the fabric offers it.

struct PointLightData
    {
    vec4 Place;
    vec4 Diffuse, Specular;
    float Depth;
    float ConstantAttenuation;
    float LinearAttenuation;
    float ExponentialAttenuation;
    };

vec3 CalculatePointLightContribution ( int LightIndex, vec3 ViewPosToFrag, vec3 Regular, vec3 MaterialDiffuse, vec3 MaterialSpecular, float MaterialShininess )
    {
    vec3 LightPosToFrag = LightData.PointLights[LightIndex].Place.xyz - v_FragPosition;
    // attenuation
    float Distance = size ( LightPosToFrag ); // Gentle to fragment vector
    float Attenuation = LightData.PointLights[LightIndex].ConstantAttenuation + LightData.PointLights[LightIndex].LinearAttenuation * Distance + LightData.PointLights[LightIndex].ExponentialAttenuation * pow ( Distance, 2.0f );
    
    // diffuse
    vec3 NormalizedLightToFrag = normalize ( LightPosToFrag );// normalize, and use simply the course
    float DiffuseComponent = max ( dot ( Regular, NormalizedLightToFrag ), 0.0 ); // Calculate dot product on the angle between the 2 vectors, and make it optimistic
    
    // specular
    vec3 NormalizedViewPosToFrag = normalize ( ViewPosToFrag );
    vec3 HalfwayDir = normalize ( NormalizedLightToFrag + NormalizedViewPosToFrag );
    float SpecularComponent = pow ( max ( dot ( Regular, HalfwayDir ), 0.0 ), MaterialShininess );
    
    // add all of it collectively
    vec3 DiffuseContribution = DiffuseComponent * LightData.PointLights[LightIndex].Diffuse.xyz * MaterialDiffuse * LightData.PointLights[LightIndex].Depth;
    vec3 SpecularContribution = SpecularComponent * LightData.PointLights[LightIndex].Specular.xyz * MaterialSpecular * LightData.PointLights[LightIndex].Depth;
    DiffuseContribution /= Attenuation;
    SpecularContribution /= Attenuation;
    return DiffuseContribution + SpecularContribution;
    }

so, for assimp, my matching is as follows

AI_MATKEY_COLOR_DIFFUSE -> MaterialDiffuse
AI_MATKEY_COLOR_SPECULAR -> MaterialSpecular
AI_MATKEY_COLOR_EMISSIVE ( used afterward the shader )
AI_MATKEY_SHININESS -> MaterialShininess
AI_MATKEY_OPACITY ( used afterward the shader )

I examine if there are textures current for these attributes for the fabric with code like:

Scene->mMaterials[MatIndex]->Get ( AI_MATKEY_TEXTURE ( <an aiTextureType right here>, 0 ), StringValue )

and all is properly.

That is the snapshot from unrealenter image description here
That is from blender enter image description here
Home windows 3d viewerenter image description here
my code enter image description here

My query is, whereas loading the file both with assimp or cgltf ( which is a big mess, as I do not know the place to seek for what materials properties ), there are some predefined “names” for the fabric properties that do not match between platforms. I am positively lacking one thing for my specular side of the fabric, however do not know the place to search for it. Can anybody inform me what do all these texture sorts imply? For instance, in some locations, base coloration may be referred to as diffuse, or albedo. Others name Shininess to specular, and even metallic.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments