materials read some properties from assimp
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-05-19 12:12:36 -04:00
parent ddb1145cb8
commit e151bdc34e
3 changed files with 59 additions and 13 deletions

View File

@ -16,20 +16,10 @@ struct Material {
/**
* The shininess value
*/
float metallic;
float shininess;
/**
* The shininess value
* The reflectivity value
*/
float roughness;
/**
* The shininess value
*/
float ior;
/**
* The shininess value
*/
float alpha;
float reflectivity;
};

View File

@ -1899,6 +1899,7 @@ Shader uniform parsing from source code
Visual shader uniform location caching
Remove old uniforms from shaders and code to push uniforms
Break out shader material into dedicated library file
Materials read some properties from assimp data

View File

@ -14,8 +14,11 @@ import org.lwjgl.assimp.AIString;
import org.lwjgl.assimp.AITexture;
import org.lwjgl.assimp.Assimp;
import org.lwjgl.opengl.GL45;
import org.lwjgl.system.MemoryStack;
import java.io.File;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.file.Path;
@ -23,6 +26,16 @@ import java.nio.file.Path;
* A material
*/
public class Material {
/**
* Default shininess
*/
public static final double DEFAULT_SHININESS = 0.0f;
/**
* The default reflectivity
*/
public static final double DEFAULT_REFLECTIVITY = 0.0f;
/**
@ -55,6 +68,16 @@ public class Material {
* texture pointer for the normal
*/
private int normalPointer;
/**
* The shininess value
*/
private double shininess = Material.DEFAULT_SHININESS;
/**
* The reflectivity value
*/
private double reflectivity = Material.DEFAULT_REFLECTIVITY;
/**
* A material that contains textures
@ -83,6 +106,11 @@ public class Material {
AIString aiPathString = AIString.calloc();
//read props
try(MemoryStack stack = MemoryStack.stackPush()){
//grab specific values
rVal.reflectivity = Material.readFloatProp(stack, Assimp.AI_MATKEY_REFLECTIVITY, input, Material.DEFAULT_REFLECTIVITY);
rVal.shininess = Material.readFloatProp(stack, Assimp.AI_MATKEY_SHININESS, input, Material.DEFAULT_SHININESS);
}
//read textures
PointerBuffer texturePtrBuff = scene.mTextures();
@ -270,6 +298,28 @@ public class Material {
normalPointer = pointer;
usesFetch = false;
}
/**
* Reads a float property from a material
* @param stack the memory stack
* @param key The key for the property
* @param input The input material
* @param defaultVal The default value
* @return The float value
*/
private static float readFloatProp(MemoryStack stack, String key, AIMaterial input, double defaultVal){
int numFloats = 1;
FloatBuffer buff = stack.callocFloat(numFloats);
IntBuffer floatCountBuff = stack.ints(numFloats);
ByteBuffer keyBuff = stack.ASCII(key);
if(Assimp.aiReturn_SUCCESS == Assimp.aiGetMaterialFloatArray(input, keyBuff, Assimp.aiTextureType_NONE, 0, buff, floatCountBuff)){
int numFloatsFound = floatCountBuff.get();
if(numFloatsFound > 0){
return buff.get();
}
}
return (float)defaultVal;
}
/**
* Applies the material
@ -299,6 +349,11 @@ public class Material {
openGLState.glBindTextureUnit(GL45.GL_TEXTURE0, texturePointer, GL45.GL_TEXTURE_2D);
Globals.renderingEngine.checkError();
}
//send physical properties
openGLState.getActiveShader().setUniform(openGLState, "material.shininess", this.shininess);
Globals.renderingEngine.checkError();
openGLState.getActiveShader().setUniform(openGLState, "material.reflectivity", this.reflectivity);
Globals.renderingEngine.checkError();
}
/**