Moved some material attributes to push constants
WIP updates to hello_cube smoke test; now rendering grid of cubes
This commit is contained in:
@@ -105,6 +105,7 @@ void KRScene::render(KRNode::RenderInfo& ri)
|
|||||||
{
|
{
|
||||||
|
|
||||||
// ---------- Start: Vulkan Debug Code ----------
|
// ---------- Start: Vulkan Debug Code ----------
|
||||||
|
/*
|
||||||
if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_FORWARD_OPAQUE) {
|
if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_FORWARD_OPAQUE) {
|
||||||
KRMesh* sphereMesh = getContext().getMeshManager()->getMaxLODModel("__sphere");
|
KRMesh* sphereMesh = getContext().getMeshManager()->getMaxLODModel("__sphere");
|
||||||
if (sphereMesh && sphereMesh->isReady()) {
|
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);
|
sphereMesh->renderNoMaterials(ri.commandBuffer, info.renderPass, "Vulkan Test", "vulkan_test", 1.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
// ---------- End: Vulkan Debug Code ----------
|
// ---------- End: Vulkan Debug Code ----------
|
||||||
|
|
||||||
if (getFirstLight() == NULL) {
|
if (getFirstLight() == NULL) {
|
||||||
addDefaultLights();
|
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.
|
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)
|
// Get lights from outer nodes (directional lights, which have no bounds)
|
||||||
@@ -139,15 +136,15 @@ void KRScene::render(KRNode::RenderInfo& ri)
|
|||||||
KRNode* node = (*itr);
|
KRNode* node = (*itr);
|
||||||
KRPointLight* point_light = dynamic_cast<KRPointLight*>(node);
|
KRPointLight* point_light = dynamic_cast<KRPointLight*>(node);
|
||||||
if (point_light) {
|
if (point_light) {
|
||||||
point_lights.push_back(point_light);
|
ri.point_lights.push_back(point_light);
|
||||||
}
|
}
|
||||||
KRDirectionalLight* directional_light = dynamic_cast<KRDirectionalLight*>(node);
|
KRDirectionalLight* directional_light = dynamic_cast<KRDirectionalLight*>(node);
|
||||||
if (directional_light) {
|
if (directional_light) {
|
||||||
directional_lights.push_back(directional_light);
|
ri.directional_lights.push_back(directional_light);
|
||||||
}
|
}
|
||||||
KRSpotLight* spot_light = dynamic_cast<KRSpotLight*>(node);
|
KRSpotLight* spot_light = dynamic_cast<KRSpotLight*>(node);
|
||||||
if (spot_light) {
|
if (spot_light) {
|
||||||
spot_lights.push_back(spot_light);
|
ri.spot_lights.push_back(spot_light);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,10 @@
|
|||||||
#version 450
|
#version 450
|
||||||
#extension GL_GOOGLE_include_directive : enable
|
#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
|
//#extension GL_EXT_shadow_samplers : require
|
||||||
|
|
||||||
layout(location = 0) out vec4 colorOut;
|
layout(location = 0) out vec4 colorOut;
|
||||||
@@ -428,7 +432,7 @@ void main()
|
|||||||
#else
|
#else
|
||||||
mediump vec3 view_space_normal = vec3(model_view_inverse_transpose_matrix * vec4(normal, 1.0));
|
mediump vec3 view_space_normal = vec3(model_view_inverse_transpose_matrix * vec4(normal, 1.0));
|
||||||
#endif
|
#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
|
#else
|
||||||
#if HAS_DIFFUSE_MAP == 1
|
#if HAS_DIFFUSE_MAP == 1
|
||||||
#if ALPHA_TEST == 1
|
#if ALPHA_TEST == 1
|
||||||
@@ -453,13 +457,13 @@ void main()
|
|||||||
mediump float lamberFactor = max(0.0,dot(lightVec, normal));
|
mediump float lamberFactor = max(0.0,dot(lightVec, normal));
|
||||||
#endif
|
#endif
|
||||||
mediump float specularFactor = 0.0;
|
mediump float specularFactor = 0.0;
|
||||||
if(material_shininess > 0.0) {
|
if(PushConstants.material_shininess > 0.0) {
|
||||||
#if GBUFFER_PASS == 3
|
#if GBUFFER_PASS == 3
|
||||||
specularFactor = gbuffer_specular_factor;
|
specularFactor = gbuffer_specular_factor;
|
||||||
#else
|
#else
|
||||||
mediump float halfVecDot = dot(halfVec,normal);
|
mediump float halfVecDot = dot(halfVec,normal);
|
||||||
if(halfVecDot > 0.0) {
|
if(halfVecDot > 0.0) {
|
||||||
specularFactor = max(0.0,pow(halfVecDot, material_shininess));
|
specularFactor = max(0.0,pow(halfVecDot, PushConstants.material_shininess));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -542,7 +546,7 @@ void main()
|
|||||||
|
|
||||||
#if ENABLE_DIFFUSE == 1
|
#if ENABLE_DIFFUSE == 1
|
||||||
// -------------------- Add diffuse light --------------------
|
// -------------------- Add diffuse light --------------------
|
||||||
colorOut += diffuseMaterial * vec4(material_diffuse * lamberFactor, 1.0);
|
colorOut += diffuseMaterial * vec4(PushConstants.material_diffuse * lamberFactor, 1.0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// -------------------- Apply material_alpha --------------------
|
// -------------------- Apply material_alpha --------------------
|
||||||
@@ -625,4 +629,6 @@ void main()
|
|||||||
#if BONE_COUNT > 0
|
#if BONE_COUNT > 0
|
||||||
colorOut.b = 1.0;
|
colorOut.b = 1.0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
colorOut.a = 1.0; // HACK?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,10 @@
|
|||||||
#version 450
|
#version 450
|
||||||
#extension GL_GOOGLE_include_directive : enable
|
#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 = 0) in vec3 vertex_position;
|
||||||
layout(location = 1) in vec3 vertex_normal;
|
layout(location = 1) in vec3 vertex_normal;
|
||||||
|
|
||||||
@@ -273,7 +277,7 @@ layout( push_constant ) uniform constants
|
|||||||
|
|
||||||
#if ENABLE_PER_PIXEL == 1
|
#if ENABLE_PER_PIXEL == 1
|
||||||
layout(location=6) out mediump vec3 lightVec;
|
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
|
#if HAS_SPEC_MAP_OFFSET == 1 || HAS_SPEC_MAP_SCALE == 1
|
||||||
layout(location = 8) out highp vec2 spec_uv;
|
layout(location = 8) out highp vec2 spec_uv;
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ bool smoke_load()
|
|||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
kCameraNodeHandle = 10,
|
kCameraNodeHandle = 10,
|
||||||
kCubeNodeHandle = 11
|
kLightNodeHandle = 11,
|
||||||
|
kCubeNodeHandle = 12
|
||||||
};
|
};
|
||||||
|
|
||||||
KrLoadResourceInfo load_resource_info = {};
|
KrLoadResourceInfo load_resource_info = {};
|
||||||
@@ -79,7 +80,7 @@ bool smoke_load()
|
|||||||
res = KrCreateScene(&create_scene_info);
|
res = KrCreateScene(&create_scene_info);
|
||||||
assert(res == KR_SUCCESS);
|
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::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);
|
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.location = KR_SCENE_NODE_APPEND_CHILD;
|
||||||
create_camera_info.newNodeHandle = kCameraNodeHandle;
|
create_camera_info.newNodeHandle = kCameraNodeHandle;
|
||||||
create_camera_info.sceneHandle = kSceneResourceHandle;
|
create_camera_info.sceneHandle = kSceneResourceHandle;
|
||||||
create_camera_info.node.pName = "my_camera";
|
create_camera_info.node.pName = "default_camera";
|
||||||
create_camera_info.node.camera.surfaceHandle = 1;
|
create_camera_info.node.camera.surfaceHandle = 0;
|
||||||
create_camera_info.node.translate = hydra::Vector3::Create(1.0, 5.0, 3.0);
|
create_camera_info.node.translate = cameraPos;
|
||||||
create_camera_info.node.rotate = cameraRot.eulerXYZ();
|
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;
|
// create_camera_info.node.camera.skybox_texture = kSkyboxTextureResourceHandle;
|
||||||
res = KrCreateNode(&create_camera_info);
|
res = KrCreateNode(&create_camera_info);
|
||||||
assert(res == KR_SUCCESS);
|
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
|
// Add a cube to the scene
|
||||||
KrCreateNodeInfo create_cube_info = { KR_STRUCTURE_TYPE_CREATE_NODE };
|
KrCreateNodeInfo create_cube_info = { KR_STRUCTURE_TYPE_CREATE_NODE };
|
||||||
res = KrInitNodeInfo(&create_cube_info.node, KR_STRUCTURE_TYPE_NODE_MODEL);
|
res = KrInitNodeInfo(&create_cube_info.node, KR_STRUCTURE_TYPE_NODE_MODEL);
|
||||||
@@ -112,5 +131,17 @@ bool smoke_load()
|
|||||||
res = KrCreateNode(&create_cube_info);
|
res = KrCreateNode(&create_cube_info);
|
||||||
assert(res == KR_SUCCESS);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user