void generateStars(float side, int star_count) { // simple effect to render a star billboard vl::ref<vl::Effect> effect = new vl::Effect; // speedup tip: this allows VL to batch all the stars together greatly speeding up the rendering and avoiding switching textures back and forth with the trees. effect->setRenderRank(1); effect->shader()->enable(vl::EN_BLEND); effect->shader()->enable(vl::EN_DEPTH_TEST); effect->shader()->gocTextureSampler(0)->setTexture( new vl::Texture("images/sun.png", vl::TF_RGBA, true) ); vl::ref<vl::Geometry> star = generateQuad(); for(int i=0; i<star_count; i++) { // new billboard vl::ref<vl::Billboard> billboard = new vl::Billboard; // set spherical billboard type: orient the object always towards the camera. billboard->setType(vl::BT_SphericalBillboard); // add billboard to the transform tree rendering()->as<vl::Rendering>()->transform()->addChild(billboard.get()); // compute a random point on the skydome vl::real x = vl::random(-1.0f,+1.0f); vl::real y = vl::random(0,2.0f); vl::real z = vl::random(-1.0f,+1.0f); vl::vec3 n(x,y,z); n.normalize(); n = n * sqrt(side*side/2.0f); n.y() *= 0.2f; // set the billboard position and rotation center. billboard->setPosition( n ); // add the star actor sceneManager()->tree()->addActor(star.get(), effect.get(), billboard.get()); } }
void prepare() { VulkanExampleBase::prepare(); setupVertexDescriptions(); loadTextures(); generateQuad(); prepareUniformBuffers(); setupDescriptorSetLayout(); preparePipelines(); setupDescriptorPool(); setupDescriptorSet(); buildCommandBuffers(); prepared = true; }
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); } void prepare() { VulkanExampleBase::prepare(); generateQuad(); loadMeshes(); setupVertexDescriptions(); prepareUniformBuffers(); prepareTextureTarget(TEX_DIM, TEX_DIM, DEPTH_FORMAT); setupDescriptorSetLayout(); preparePipelines(); setupDescriptorPool(); setupDescriptorSets(); prepareOffscreenFramebuffer();
void generateTrees(float side, int tree_count) { // simple effect to render a tree billboard vl::ref<vl::Effect> effect = new vl::Effect; // speedup tip: this allows VL to batch all the trees together greatly speeding up the rendering and avoiding switching textures back and forth with the stars. effect->setRenderRank(2); effect->shader()->setRenderState( new vl::Light, 0 ); effect->shader()->enable(vl::EN_BLEND); effect->shader()->enable(vl::EN_DEPTH_TEST); effect->shader()->gocDepthMask()->set(false); effect->shader()->enable(vl::EN_LIGHTING); effect->shader()->gocLight(0)->setLinearAttenuation(0.025f); effect->shader()->gocTextureSampler(0)->setTexture( new vl::Texture("images/tree.png") ); vl::ref<vl::Geometry> tree = generateQuad(); tree->transform( vl::mat4::getTranslation(0,+0.5f,0) ); tree->transform( vl::mat4::getScaling(1.0f,+2.0f,1.0f) ); tree->computeNormals(); for(int i=0; i<tree_count; i++) { // new billboard vl::ref<vl::Billboard> billboard = new vl::Billboard; // set axis-aligned billboard type: rotate the billboard towards the camera but only around the specified axis. billboard->setType(vl::BT_AxisAlignedBillboard); billboard->setAxis(vl::vec3(0,1.0f,0)); // bind billboard to the transform tree rendering()->as<vl::Rendering>()->transform()->addChild(billboard.get()); // generate a random position vl::real x = vl::random(-side/2.0f,+side/2.0f); vl::real y = 0; vl::real z = vl::random(-side/2.0f,+side/2.0f); billboard->setPosition( vl::vec3(x,y,z) ); // add the tree actor sceneManager()->tree()->addActor(tree.get(), effect.get(), billboard.get()); } }