Keep working on PBR...
Broken skybox sample!
This commit is contained in:
parent
dc45f43855
commit
85507bcfc3
3 changed files with 29 additions and 59 deletions
|
|
@ -22,7 +22,7 @@ int main()
|
|||
InitWindow(screenWidth, screenHeight, "raylib [models] example - pbr material");
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera camera = {{ 4.0f, 4.0f, 4.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
|
||||
Camera camera = {{ 4.0f, 4.0f, 4.0f }, { 0.0f, 0.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
|
||||
|
||||
// Load model and PBR material
|
||||
Model model = LoadModel("resources/pbr/trooper.obj");
|
||||
|
|
@ -37,17 +37,16 @@ int main()
|
|||
SetMaterialTexture(&model.material, TEXMAP_ROUGHNESS, LoadTexture("resources/pbr/trooper_roughness.png"));
|
||||
SetMaterialTexture(&model.material, TEXMAP_OCCLUSION, LoadTexture("resources/pbr/trooper_ao.png"));
|
||||
|
||||
SetShaderValuei(model.material.shader, GetShaderLocation(model.material.shader, "normals.enabled"), (int[1]){ 1 }, 1);
|
||||
|
||||
// Set textures filtering for better quality
|
||||
SetTextureFilter(model.material.maps[TEXMAP_ALBEDO].tex, FILTER_BILINEAR);
|
||||
SetTextureFilter(model.material.maps[TEXMAP_NORMAL].tex, FILTER_BILINEAR);
|
||||
SetTextureFilter(model.material.maps[TEXMAP_METALNESS].tex, FILTER_BILINEAR);
|
||||
SetTextureFilter(model.material.maps[TEXMAP_ROUGHNESS].tex, FILTER_BILINEAR);
|
||||
SetTextureFilter(model.material.maps[TEXMAP_OCCLUSION].tex, FILTER_BILINEAR);
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
//printf("TexMap %i ID: %i\n", i, model.material.maps[i].tex.id);
|
||||
}
|
||||
|
||||
int viewPosLoc = GetShaderLocation(model.material.shader, "viewPos");
|
||||
|
||||
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
|
||||
|
|
@ -63,7 +62,7 @@ int main()
|
|||
|
||||
// Send to material PBR shader camera view position
|
||||
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
|
||||
SetShaderValue(model.material.shader, model.material.shader.locs[LOC_MATRIX_VIEW], cameraPos, 3);
|
||||
SetShaderValue(model.material.shader, viewPosLoc, cameraPos, 3);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
|
|
|
|||
|
|
@ -24,23 +24,17 @@ int main()
|
|||
// Define the camera to look into our 3d world
|
||||
Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
|
||||
|
||||
// Load skybox model and shader
|
||||
#define PATH_SKYBOX_VS "resources/shaders/skybox.vs" // Path to skybox vertex shader
|
||||
#define PATH_SKYBOX_FS "resources/shaders/skybox.fs" // Path to skybox vertex shader
|
||||
#define PATH_TEXTURES_HDR "resources/pinetree.hdr"
|
||||
#define LOC_CUSTOM_SKYRESOLUTION 15
|
||||
|
||||
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
||||
Model skybox = LoadModelFromMesh(cube, false);
|
||||
skybox.material.shader = LoadShader(PATH_SKYBOX_VS, PATH_SKYBOX_FS);
|
||||
skybox.material.shader = LoadShader("resources/shaders/skybox.vs", "resources/shaders/skybox.fs");
|
||||
|
||||
Texture2D texHDR = LoadTexture(PATH_TEXTURES_HDR);
|
||||
Texture2D texHDR = LoadTexture("resources/pinetree.hdr");
|
||||
skybox.material.maps[TEXMAP_CUBEMAP].tex = rlGenMapCubemap(texHDR, 512);
|
||||
SetShaderValuei(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), (int[1]){ TEXMAP_CUBEMAP }, 1);
|
||||
|
||||
// Get skybox shader locations
|
||||
int skyProjectionLoc = GetShaderLocation(skybox.material.shader, "projection");
|
||||
skybox.material.shader.locs[LOC_MATRIX_VIEW] = GetShaderLocation(skybox.material.shader, "view");
|
||||
int skyViewLoc = GetShaderLocation(skybox.material.shader, "view");
|
||||
|
||||
// Then before rendering, configure the viewport to the actual screen dimensions
|
||||
Matrix proj = MatrixPerspective(60.0, (double)GetScreenWidth()/(double)GetScreenHeight(), 0.01, 1000.0);
|
||||
|
|
@ -60,7 +54,7 @@ int main()
|
|||
UpdateCamera(&camera); // Update camera
|
||||
|
||||
Matrix view = MatrixLookAt(camera.position, camera.target, camera.up);
|
||||
SetShaderValueMatrix(skybox.material.shader, skybox.material.shader.locs[LOC_MATRIX_VIEW], view);
|
||||
SetShaderValueMatrix(skybox.material.shader, skyViewLoc, view);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
|
|
|
|||
|
|
@ -16,9 +16,10 @@
|
|||
#define LIGHT_POINT 1
|
||||
|
||||
struct MaterialProperty {
|
||||
vec3 color;
|
||||
int useSampler;
|
||||
int enabled;
|
||||
sampler2D sampler;
|
||||
float value;
|
||||
vec3 color;
|
||||
};
|
||||
|
||||
struct Light {
|
||||
|
|
@ -65,7 +66,6 @@ const float PI = 3.14159265359;
|
|||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
vec3 ComputeMaterialProperty(MaterialProperty property);
|
||||
float DistributionGGX(vec3 N, vec3 H, float roughness);
|
||||
float GeometrySchlickGGX(float NdotV, float roughness);
|
||||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness);
|
||||
|
|
@ -73,14 +73,6 @@ vec3 fresnelSchlick(float cosTheta, vec3 F0);
|
|||
vec3 fresnelSchlickRoughness(float cosTheta, vec3 F0, float roughness);
|
||||
vec2 ParallaxMapping(vec2 texCoords, vec3 viewDir);
|
||||
|
||||
vec3 ComputeMaterialProperty(MaterialProperty property)
|
||||
{
|
||||
//if (property.useSampler == 1) return texture(property.sampler, texCoord).rgb;
|
||||
//else return property.color;
|
||||
|
||||
return texture(property.sampler, texCoord).rgb;
|
||||
}
|
||||
|
||||
float DistributionGGX(vec3 N, vec3 H, float roughness)
|
||||
{
|
||||
float a = roughness*roughness;
|
||||
|
|
@ -181,20 +173,18 @@ void main()
|
|||
vec3 refl = reflect(-view, normal);
|
||||
|
||||
// Check if parallax mapping is enabled and calculate texture coordinates to use based on height map
|
||||
//if (height.useSampler == 1) texCoord = ParallaxMapping(fragTexCoord, view);
|
||||
//else texCoord = fragTexCoord; // Use default texture coordinates
|
||||
|
||||
texCoord = fragTexCoord; // Use default texture coordinates
|
||||
if (height.enabled == 1) texCoord = ParallaxMapping(fragTexCoord, view);
|
||||
else texCoord = fragTexCoord; // Use default texture coordinates
|
||||
|
||||
// Fetch material values from texture sampler or color attributes
|
||||
vec3 color = pow(texture(albedo.sampler, texCoord).rgb, vec3(2.2));//pow(ComputeMaterialProperty(albedo), vec3(2.2));
|
||||
vec3 metal = texture(metalness.sampler, texCoord).rgb; //ComputeMaterialProperty(metalness);
|
||||
vec3 rough = texture(roughness.sampler, texCoord).rgb; //ComputeMaterialProperty(roughness);
|
||||
vec3 emiss = texture(emission.sampler, texCoord).rgb; //ComputeMaterialProperty(emission);
|
||||
vec3 ao = texture(occlusion.sampler, texCoord).rgb; //ComputeMaterialProperty(occlusion);
|
||||
vec3 color = pow(texture(albedo.sampler, texCoord).rgb, vec3(2.2));
|
||||
vec3 metal = texture(metalness.sampler, texCoord).rgb;
|
||||
vec3 rough = texture(roughness.sampler, texCoord).rgb;
|
||||
vec3 emiss = vec3(0);//texture(emission.sampler, texCoord).rgb;
|
||||
vec3 ao = texture(occlusion.sampler, texCoord).rgb;
|
||||
|
||||
// Check if normal mapping is enabled
|
||||
if (normals.useSampler == 1)
|
||||
if (normals.enabled == 1)
|
||||
{
|
||||
// Fetch normal map color and transform lighting values to tangent space
|
||||
normal = texture(normals.sampler, texCoord).rgb; //ComputeMaterialProperty(normals);
|
||||
|
|
|
|||
Loading…
Reference in a new issue