Moved some material attributes to push constants

WIP updates to hello_cube smoke test; now rendering grid of cubes
This commit is contained in:
2025-05-16 01:44:19 -07:00
parent 6a136cf0ee
commit 9db005c55c
4 changed files with 58 additions and 20 deletions

View File

@@ -105,6 +105,7 @@ void KRScene::render(KRNode::RenderInfo& ri)
{
// ---------- Start: Vulkan Debug Code ----------
/*
if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_FORWARD_OPAQUE) {
KRMesh* sphereMesh = getContext().getMeshManager()->getMaxLODModel("__sphere");
if (sphereMesh && sphereMesh->isReady()) {
@@ -121,17 +122,13 @@ void KRScene::render(KRNode::RenderInfo& ri)
sphereMesh->renderNoMaterials(ri.commandBuffer, info.renderPass, "Vulkan Test", "vulkan_test", 1.0);
}
}
*/
// ---------- End: Vulkan Debug Code ----------
if (getFirstLight() == NULL) {
addDefaultLights();
}
std::vector<KRPointLight*> point_lights;
std::vector<KRDirectionalLight*>directional_lights;
std::vector<KRSpotLight*>spot_lights;
std::set<KRNode*> outerNodes = std::set<KRNode*>(m_nodeTree.getOuterSceneNodes()); // HACK - Copying the std::set as it is potentially modified as KRNode's update their bounds during the iteration. This is very expensive and will be eliminated in the future.
// Get lights from outer nodes (directional lights, which have no bounds)
@@ -139,15 +136,15 @@ void KRScene::render(KRNode::RenderInfo& ri)
KRNode* node = (*itr);
KRPointLight* point_light = dynamic_cast<KRPointLight*>(node);
if (point_light) {
point_lights.push_back(point_light);
ri.point_lights.push_back(point_light);
}
KRDirectionalLight* directional_light = dynamic_cast<KRDirectionalLight*>(node);
if (directional_light) {
directional_lights.push_back(directional_light);
ri.directional_lights.push_back(directional_light);
}
KRSpotLight* spot_light = dynamic_cast<KRSpotLight*>(node);
if (spot_light) {
spot_lights.push_back(spot_light);
ri.spot_lights.push_back(spot_light);
}
}

View File

@@ -32,6 +32,10 @@
#version 450
#extension GL_GOOGLE_include_directive : enable
// TODO - HACK! Need to dynamically set these defines...
#define ENABLE_DIFFUSE 1
#define ENABLE_PER_PIXEL 1
//#extension GL_EXT_shadow_samplers : require
layout(location = 0) out vec4 colorOut;
@@ -428,7 +432,7 @@ void main()
#else
mediump vec3 view_space_normal = vec3(model_view_inverse_transpose_matrix * vec4(normal, 1.0));
#endif
colorOut = vec4(view_space_normal * 0.5 + 0.5, material_shininess / 100.0);
colorOut = vec4(view_space_normal * 0.5 + 0.5, PushConstants.material_shininess / 100.0);
#else
#if HAS_DIFFUSE_MAP == 1
#if ALPHA_TEST == 1
@@ -453,13 +457,13 @@ void main()
mediump float lamberFactor = max(0.0,dot(lightVec, normal));
#endif
mediump float specularFactor = 0.0;
if(material_shininess > 0.0) {
if(PushConstants.material_shininess > 0.0) {
#if GBUFFER_PASS == 3
specularFactor = gbuffer_specular_factor;
#else
mediump float halfVecDot = dot(halfVec,normal);
if(halfVecDot > 0.0) {
specularFactor = max(0.0,pow(halfVecDot, material_shininess));
specularFactor = max(0.0,pow(halfVecDot, PushConstants.material_shininess));
}
#endif
}
@@ -542,7 +546,7 @@ void main()
#if ENABLE_DIFFUSE == 1
// -------------------- Add diffuse light --------------------
colorOut += diffuseMaterial * vec4(material_diffuse * lamberFactor, 1.0);
colorOut += diffuseMaterial * vec4(PushConstants.material_diffuse * lamberFactor, 1.0);
#endif
// -------------------- Apply material_alpha --------------------
@@ -625,4 +629,6 @@ void main()
#if BONE_COUNT > 0
colorOut.b = 1.0;
#endif
colorOut.a = 1.0; // HACK?
}

View File

@@ -32,6 +32,10 @@
#version 450
#extension GL_GOOGLE_include_directive : enable
// TODO - HACK! Need to dynamically set these defines...
#define ENABLE_DIFFUSE 1
#define ENABLE_PER_PIXEL 1
layout(location = 0) in vec3 vertex_position;
layout(location = 1) in vec3 vertex_normal;
@@ -273,7 +277,7 @@ layout( push_constant ) uniform constants
#if ENABLE_PER_PIXEL == 1
layout(location=6) out mediump vec3 lightVec;
layout(location=7) out out mediump vec3 halfVec;
layout(location=7) out mediump vec3 halfVec;
#if HAS_SPEC_MAP_OFFSET == 1 || HAS_SPEC_MAP_SCALE == 1
layout(location = 8) out highp vec2 spec_uv;

View File

@@ -44,7 +44,8 @@ bool smoke_load()
enum
{
kCameraNodeHandle = 10,
kCubeNodeHandle = 11
kLightNodeHandle = 11,
kCubeNodeHandle = 12
};
KrLoadResourceInfo load_resource_info = {};
@@ -79,7 +80,7 @@ bool smoke_load()
res = KrCreateScene(&create_scene_info);
assert(res == KR_SUCCESS);
hydra::Vector3 cameraPos = hydra::Vector3::Create(1.0, 5.0, 3.0);
hydra::Vector3 cameraPos = hydra::Vector3::Create(70, 0.5, 0.25);
hydra::Matrix4 cameraMat = hydra::Matrix4::LookAt(cameraPos, hydra::Vector3::Create(0.0, 0.0, 0.0), hydra::Vector3::Up());
hydra::Quaternion cameraRot = hydra::Quaternion::FromRotationMatrix(cameraMat);
@@ -91,14 +92,32 @@ bool smoke_load()
create_camera_info.location = KR_SCENE_NODE_APPEND_CHILD;
create_camera_info.newNodeHandle = kCameraNodeHandle;
create_camera_info.sceneHandle = kSceneResourceHandle;
create_camera_info.node.pName = "my_camera";
create_camera_info.node.camera.surfaceHandle = 1;
create_camera_info.node.translate = hydra::Vector3::Create(1.0, 5.0, 3.0);
create_camera_info.node.rotate = cameraRot.eulerXYZ();
create_camera_info.node.pName = "default_camera";
create_camera_info.node.camera.surfaceHandle = 0;
create_camera_info.node.translate = cameraPos;
create_camera_info.node.rotate = -cameraRot.eulerXYZ();
//
// create_camera_info.node.translate = hydra::Vector3::Create(0.0, 5.0, 0.0);
// create_camera_info.node.camera.skybox_texture = kSkyboxTextureResourceHandle;
res = KrCreateNode(&create_camera_info);
assert(res == KR_SUCCESS);
/*
// Add a light to the scene
KrCreateNodeInfo create_light_info = { KR_STRUCTURE_TYPE_CREATE_NODE };
res = KrInitNodeInfo(&create_light_info.node, KR_STRUCTURE_TYPE_NODE_DIRECTIONAL_LIGHT);
assert(res == KR_SUCCESS);
create_light_info.relativeNodeHandle = KR_NULL_HANDLE;
create_light_info.location = KR_SCENE_NODE_APPEND_CHILD;
create_light_info.newNodeHandle = kLightNodeHandle;
create_light_info.sceneHandle = kSceneResourceHandle;
create_light_info.node.pName = "my_light";
create_light_info.node.rotate = hydra::Vector3::Create(0.25, 0.25, 0.37);
res = KrCreateNode(&create_light_info);
assert(res == KR_SUCCESS);
*/
// Add a cube to the scene
KrCreateNodeInfo create_cube_info = { KR_STRUCTURE_TYPE_CREATE_NODE };
res = KrInitNodeInfo(&create_cube_info.node, KR_STRUCTURE_TYPE_NODE_MODEL);
@@ -112,5 +131,17 @@ bool smoke_load()
res = KrCreateNode(&create_cube_info);
assert(res == KR_SUCCESS);
for (int x = -5; x < 5; x++) {
for (int y = -5; y < 5; y++) {
for (int z = -5; z < 5; z++) {
create_cube_info.node.translate.x = x * 10;
create_cube_info.node.translate.y = y * 10;
create_cube_info.node.translate.z = z * 10;
res = KrCreateNode(&create_cube_info);
assert(res == KR_SUCCESS);
}
}
}
return true;
}