diff --git a/lightSample.cpp b/lightSample.cpp index 7d70df3..f8ad059 100644 --- a/lightSample.cpp +++ b/lightSample.cpp @@ -3,6 +3,7 @@ #include "material.h" #include "node.h" #include "light.h" +#include "model.h" #include "animation.h" #include "animationController.h" #include "animationChannel.h" @@ -27,29 +28,31 @@ int main(){ Node *rootNode = root->getRootNode(); Camera *cam = root->getCamera(); - cam->setPosition(Vector3(0, 1, 1) * 30); + cam->setPosition(Vector3(0, 1, 1) * 20); cam->lookAt(Vector3(0, -1, -1).norm(), Vector3(0, 1, -1).norm()); - Box *box = new Box(Vector3(20, 1, 20)); - Node *boxNode = new Node(); + Model *box = new Model(MODEL_PATH + "platform.vb"); Material *mat = new Material(); mat->setTexturingEnabled(true); mat->setLightingEnabled(true); - string images[] = {TEX_PATH + "bricks.jpg"}; - Texture *texture = new Texture(images, 1); - mat->addDiffuseMap(texture); + mat->setNormalMapEnabled(true); + string im0[] = {TEX_PATH + "bricks.jpg"}; + string im1[] = {TEX_PATH + "bricksNormal.jpg"}; + Texture *diffuseTex = new Texture(im0, 1); + mat->addDiffuseMap(diffuseTex); + Texture *normalTex = new Texture(im1, 1, Texture::NORMAL); + mat->addNormalMap(normalTex); box->setMaterial(mat); - boxNode->attachMesh(box); - rootNode->attachChild(boxNode); + rootNode->attachChild(box); Light *light = new Light(Light::SPOT); light->setColor(Vector3(1, 1, 1)); Node *lightNode = new Node(Vector3::VEC_ZERO, Quaternion::QUAT_W, Vector3::VEC_IJK, "", new AnimationController()); lightNode->addLight(light); rootNode->attachChild(lightNode); - lightNode->setOrientation(Quaternion(1.57, Vector3(1, 0, 0))); + lightNode->setOrientation(Quaternion(1.2, Vector3(1, 0, 0))); lightNode->setPosition(Vector3(0, 5, 0)); KeyframeChannel kcA; diff --git a/material.cpp b/material.cpp index a914d80..b5a2857 100755 --- a/material.cpp +++ b/material.cpp @@ -96,8 +96,8 @@ namespace vb01{ shader->setBool(lightingEnabled, "lightingEnabled"); shader->setBool(normalMapEnabled, "normalMapEnabled"); for(int i = 0; i < 4; i++){ - shader->setInt(TEXTURE_SLOTS[i], "textures[" + to_string(TEXTURE_SLOTS[i]) + "].pastTexture"); - shader->setInt(TEXTURE_SLOTS[i] + 1, "textures[" + to_string(TEXTURE_SLOTS[i]) + "].nextTexture"); + shader->setInt(TEXTURE_SLOTS[i], "textures[" + to_string(i) + "].pastTexture"); + shader->setInt(TEXTURE_SLOTS[i] + 1, "textures[" + to_string(i) + "].nextTexture"); } shader->setInt(TEXTURE_SLOTS[4], "environmentMap"); } @@ -121,7 +121,7 @@ namespace vb01{ for(Texture *t : textures){ int id = t->getTextureTypeId() * 2; - shader->setBool(t->getNumFrames() > 0, "textures[" + to_string(id) + "].animated"); + shader->setBool(t->getNumFrames() > 1, "textures[" + to_string(id) + "].animated"); shader->setFloat(t->getMixRatio(), "textures[" + to_string(id) + "].mixRatio"); t->update(id); } diff --git a/particleEmitterSample.cpp b/particleEmitterSample.cpp new file mode 100644 index 0000000..d889cac --- /dev/null +++ b/particleEmitterSample.cpp @@ -0,0 +1,60 @@ +#include "root.h" +#include "node.h" +#include "particleEmitter.h" +#include "material.h" +#include "texture.h" +#include "animation.h" +#include "animationController.h" +#include "animationChannel.h" + +using namespace std; +using namespace vb01; + +int main(){ + const string PATH = "../", TEX_PATH = PATH + "samples/textures/", MODEL_PATH = PATH + "samples/models/"; + string skyboxTextures[] = { + TEX_PATH + "top.jpg", + TEX_PATH + "bottom.jpg", + TEX_PATH + "left.jpg", + TEX_PATH + "right.jpg", + TEX_PATH + "front.jpg", + TEX_PATH + "back.jpg" + }; + + Root *root = Root::getSingleton(); + root->start(800, 600, PATH, "Particle emitter sample"); + root->createSkybox(skyboxTextures); + Node *rootNode = root->getRootNode(); + + Camera *cam = root->getCamera(); + cam->setPosition(Vector3(0, 0, 1) * 1); + cam->lookAt(Vector3(0, 0, -1).norm(), Vector3(0, 1, 0).norm()); + + ParticleEmitter *emitter = new ParticleEmitter(1); + Node *emitterNode = new Node(Vector3::VEC_ZERO, Quaternion::QUAT_W, Vector3::VEC_IJK, "", new AnimationController()); + + Material *mat = new Material(Material::MATERIAL_PARTICLE); + mat->setTexturingEnabled(true); + mat->setLightingEnabled(false); + string images[] = {TEX_PATH + "smoke00.png"}; + Texture *texture = new Texture(images, 1); + mat->addDiffuseMap(texture); + + emitter->setMaterial(mat); + emitter->setStartColor(Vector4(1, 1, 1, 1)); + emitter->setEndColor(Vector4(1, 0, 1, 1)); + emitter->setStartSize(Vector2(1, 1) * .1); + emitter->setEndSize(Vector2(1, 1) * .1); + emitter->setLowLife(.3); + emitter->setHighLife(.4); + emitter->setSpeed(.01); + emitter->setSpread(360); + + emitterNode->attachParticleEmitter(emitter); + rootNode->attachChild(emitterNode); + emitterNode->setOrientation(Quaternion(-1.57, Vector3(1, 0, 0))); + + while(true) + root->update(); + return 0; +} diff --git a/samples/models/platform.vb b/samples/models/platform.vb new file mode 100644 index 0000000..9f468c2 --- /dev/null +++ b/samples/models/platform.vb @@ -0,0 +1,143 @@ +{ +MESH: Cube +pos: 0.0 0.0 0.0 +rot: 1.0 0.0 0.0 -0.0 +scale: 1.0 1.0 1.0 +parent: - +skeleton: - +numElements: 20 36 0 0 +groups: +vertices: +9.375428199768066 9.375428199768066 1.0 -0.5773491859436035 -0.5773491859436035 0.5773491859436035 +10.0 10.0 -1.0 0.5773491859436035 0.5773491859436035 -0.5773491859436035 +9.375428199768066 -9.375428199768066 1.0 -0.5773491859436035 0.5773491859436035 0.5773491859436035 +10.0 -10.0 -1.0 0.5773491859436035 -0.5773491859436035 -0.5773491859436035 +-9.375428199768066 9.375428199768066 1.0 0.5773491859436035 -0.5773491859436035 0.5773491859436035 +-10.0 10.0 -1.0 -0.5773491859436035 0.5773491859436035 -0.5773491859436035 +-9.375428199768066 -9.375428199768066 1.0 0.5773491859436035 0.5773491859436035 0.5773491859436035 +-10.0 -10.0 -1.0 -0.5773491859436035 -0.5773491859436035 -0.5773491859436035 +10.0 -10.0 1.0 0.7070833444595337 -0.7070833444595337 0.0 +-10.0 -10.0 1.0 -0.7070833444595337 -0.7070833444595337 0.0 +10.0 10.0 1.0 0.7070833444595337 0.7070833444595337 0.0 +-10.0 10.0 1.0 -0.7070833444595337 0.7070833444595337 0.0 +10.0 -10.0 2.5973665714263916 0.5773491859436035 -0.5773491859436035 0.5773491859436035 +-10.0 -10.0 2.5973665714263916 -0.5773491859436035 -0.5773491859436035 0.5773491859436035 +10.0 10.0 2.5973665714263916 0.5773491859436035 0.5773491859436035 0.5773491859436035 +-10.0 10.0 2.5973665714263916 -0.5773491859436035 0.5773491859436035 0.5773491859436035 +9.375428199768066 -9.375428199768066 2.5973665714263916 -0.3014923632144928 0.3014923632144928 0.904507577419281 +-9.375428199768066 -9.375428199768066 2.5973665714263916 0.3014923632144928 0.3014923632144928 0.904507577419281 +9.375428199768066 9.375428199768066 2.5973665714263916 -0.3014923632144928 -0.3014923632144928 0.904507577419281 +-9.375428199768066 9.375428199768066 2.5973665714263916 0.3014923632144928 -0.3014923632144928 0.904507577419281 +faces: +4 0.9604101181030273 0.0 -1.0 0.0 0.0 0.0 -1.0 0.0 +2 0.4956846237182617 0.4647254943847656 -1.0 0.0 0.0 0.0 -1.0 0.0 +0 0.4956846237182617 0.0 -1.0 0.0 0.0 0.0 -1.0 0.0 +8 0.5352740287780762 0.9604101181030273 0.0 0.0 -1.0 1.0 0.0 0.0 +7 0.5848426818847656 0.4647254943847656 0.0 0.0 -1.0 1.0 0.0 0.0 +3 0.5848426818847656 0.9604101181030273 0.0 0.0 -1.0 1.0 0.0 0.0 +9 0.6244320869445801 0.9604101181030273 0.0 0.0 -1.0 -0.0 -1.0 -0.0 +5 0.6740007400512695 0.4647254943847656 0.0 0.0 -1.0 -0.0 -1.0 -0.0 +7 0.6740007400512695 0.9604101181030273 0.0 0.0 -1.0 -0.0 -1.0 -0.0 +1 0.4956846237182617 0.0 1.0 0.0 0.0 0.0 -1.0 0.0 +7 0.0 0.4956846237182617 1.0 0.0 0.0 0.0 -1.0 0.0 +5 0.0 0.0 1.0 0.0 0.0 0.0 -1.0 0.0 +10 0.713590145111084 0.9604101181030273 0.0 0.0 -1.0 -0.0 1.0 0.0 +3 0.7631587982177734 0.4647254943847656 0.0 0.0 -1.0 -0.0 1.0 0.0 +1 0.7631587982177734 0.9604101181030273 0.0 0.0 -1.0 -0.0 1.0 0.0 +11 0.8027482032775879 0.9604101181030273 0.0 0.0 -1.0 -1.0 0.0 0.0 +1 0.8523168563842773 0.4647254943847656 0.0 0.0 -1.0 -1.0 0.0 0.0 +5 0.8523168563842773 0.9604101181030273 0.0 0.0 -1.0 -1.0 0.0 0.0 +9 0.6244320869445801 0.9604101181030273 0.0 0.0 -1.0 -0.0 -1.0 -0.0 +15 0.5848426818847656 0.4647254943847656 0.0 0.0 -0.9999999403953552 -0.0 -0.9999999403953552 -0.0 +11 0.6244320869445801 0.4647254943847656 0.0 0.0 -1.0 -0.0 -1.0 -0.0 +2 0.8919060230255127 0.9294509887695312 0.0 0.0 -1.0 -0.0 -0.9999999403953552 -0.0 +18 0.8523166179656982 0.4647254943847656 0.0 0.0 -1.0 -0.0 -0.9999999403953552 -0.0 +0 0.8919060230255127 0.4647254943847656 0.0 0.0 -1.0 -0.0 -0.9999999403953552 -0.0 +0 0.9314956665039062 0.9294509887695312 0.0 0.0 -1.0 0.9999999403953552 0.0 0.0 +19 0.8919062614440918 0.4647254943847656 0.0 0.0 -1.0 0.9999999403953552 0.0 0.0 +4 0.9314956665039062 0.4647254943847656 0.0 0.0 -1.0 0.9999999403953552 0.0 0.0 +8 0.5352740287780762 0.9604101181030273 0.0 0.0 -1.0 1.0 0.0 0.0 +13 0.4956846237182617 0.4647254943847656 0.0 0.0 -0.9999999403953552 0.9999999403953552 0.0 0.0 +9 0.5352740287780762 0.4647254943847656 0.0 0.0 -1.0 1.0 0.0 0.0 +17 0.4802055358886719 0.9758901596069336 -1.0 -1.4785427993047051e-05 0.0 1.4785427993047051e-05 -1.0 0.0 +12 0.0 0.9913692474365234 -1.0 1.4343298062158283e-05 0.0 -1.4343298062158283e-05 -1.0 0.0 +16 0.015479087829589844 0.9758901596069336 -1.0 1.3944924830866512e-05 0.0 -1.3944924830866512e-05 -1.0 0.0 +16 0.015479087829589844 0.9758901596069336 -1.0 1.3944924830866512e-05 0.0 -1.3944924830866512e-05 -1.0 0.0 +14 0.0 0.4956846237182617 -1.0 -1.3590316484624054e-05 0.0 1.3590316484624054e-05 -1.0 0.0 +18 0.01548004150390625 0.5111637115478516 -1.0 -1.4771365385968238e-05 0.0 1.4771365385968238e-05 -1.0 0.0 +19 0.4802055358886719 0.511164665222168 -1.0 -1.5412135326187126e-05 0.0 1.5412135326187126e-05 -1.0 0.0 +13 0.4956846237182617 0.9913692474365234 -0.9999999403953552 -1.4854152141197119e-05 0.0 1.4854152141197119e-05 -0.9999999403953552 0.0 +17 0.4802055358886719 0.9758901596069336 -1.0 -1.4785427993047051e-05 0.0 1.4785427993047051e-05 -1.0 0.0 +18 0.01548004150390625 0.5111637115478516 -1.0 -1.4771365385968238e-05 0.0 1.4771365385968238e-05 -1.0 0.0 +15 0.4956846237182617 0.4956846237182617 -0.9999999403953552 -1.54771696543321e-05 0.0 1.54771696543321e-05 -0.9999999403953552 0.0 +19 0.4802055358886719 0.511164665222168 -1.0 -1.5412135326187126e-05 0.0 1.5412135326187126e-05 -1.0 0.0 +10 0.713590145111084 0.9604101181030273 0.0 0.0 -1.0 -0.0 1.0 0.0 +12 0.6740007400512695 0.4647254943847656 0.0 0.0 -0.9999999403953552 -0.0 0.9999999403953552 0.0 +8 0.713590145111084 0.4647254943847656 0.0 0.0 -1.0 -0.0 1.0 0.0 +4 0.9710850715637207 0.9294509887695312 0.0 0.0 -1.0 -0.0 0.9999999403953552 0.0 +17 0.9314956665039062 0.4647254943847656 0.0 0.0 -1.0 -0.0 0.9999999403953552 0.0 +6 0.9710850715637207 0.4647254943847656 0.0 0.0 -1.0 -0.0 0.9999999403953552 0.0 +6 0.9999997615814209 0.4647254943847656 0.0 0.0 -1.0 -0.9999999403953552 0.0 0.0 +16 0.9604103565216064 0.0 0.0 0.0 -1.0 -0.9999999403953552 0.0 0.0 +2 0.9999997615814209 0.0 0.0 0.0 -1.0 -0.9999999403953552 0.0 0.0 +11 0.8027482032775879 0.9604101181030273 0.0 0.0 -1.0 -1.0 0.0 0.0 +14 0.7631587982177734 0.4647254943847656 0.0 0.0 -0.9999999403953552 -0.9999999403953552 0.0 0.0 +10 0.8027482032775879 0.4647254943847656 0.0 0.0 -1.0 -1.0 0.0 0.0 +4 0.9604101181030273 0.0 -1.0 0.0 0.0 0.0 -1.0 0.0 +6 0.9604101181030273 0.4647254943847656 -1.0 0.0 0.0 0.0 -1.0 0.0 +2 0.4956846237182617 0.4647254943847656 -1.0 0.0 0.0 0.0 -1.0 0.0 +8 0.5352740287780762 0.9604101181030273 0.0 0.0 -1.0 1.0 0.0 0.0 +9 0.5352740287780762 0.4647254943847656 0.0 0.0 -1.0 1.0 0.0 0.0 +7 0.5848426818847656 0.4647254943847656 0.0 0.0 -1.0 1.0 0.0 0.0 +9 0.6244320869445801 0.9604101181030273 0.0 0.0 -1.0 -0.0 -1.0 -0.0 +11 0.6244320869445801 0.4647254943847656 0.0 0.0 -1.0 -0.0 -1.0 -0.0 +5 0.6740007400512695 0.4647254943847656 0.0 0.0 -1.0 -0.0 -1.0 -0.0 +1 0.4956846237182617 0.0 1.0 0.0 0.0 0.0 -1.0 0.0 +3 0.4956846237182617 0.4956846237182617 1.0 0.0 0.0 0.0 -1.0 0.0 +7 0.0 0.4956846237182617 1.0 0.0 0.0 0.0 -1.0 0.0 +10 0.713590145111084 0.9604101181030273 0.0 0.0 -1.0 -0.0 1.0 0.0 +8 0.713590145111084 0.4647254943847656 0.0 0.0 -1.0 -0.0 1.0 0.0 +3 0.7631587982177734 0.4647254943847656 0.0 0.0 -1.0 -0.0 1.0 0.0 +11 0.8027482032775879 0.9604101181030273 0.0 0.0 -1.0 -1.0 0.0 0.0 +10 0.8027482032775879 0.4647254943847656 0.0 0.0 -1.0 -1.0 0.0 0.0 +1 0.8523168563842773 0.4647254943847656 0.0 0.0 -1.0 -1.0 0.0 0.0 +9 0.6244320869445801 0.9604101181030273 0.0 0.0 -1.0 -0.0 -1.0 -0.0 +13 0.5848426818847656 0.9604101181030273 0.0 0.0 -1.0 -0.0 -1.0 -0.0 +15 0.5848426818847656 0.4647254943847656 0.0 0.0 -0.9999999403953552 -0.0 -0.9999999403953552 -0.0 +2 0.8919060230255127 0.9294509887695312 0.0 0.0 -1.0 -0.0 -1.0 -0.0 +16 0.8523166179656982 0.9294509887695312 0.0 0.0 -1.0 -0.0 -1.0 -0.0 +18 0.8523166179656982 0.4647254943847656 0.0 0.0 -1.0 -0.0 -1.0 -0.0 +0 0.9314956665039062 0.9294509887695312 0.0 0.0 -1.0 0.9999999403953552 0.0 0.0 +18 0.8919062614440918 0.9294509887695312 0.0 0.0 -1.0 0.9999999403953552 0.0 0.0 +19 0.8919062614440918 0.4647254943847656 0.0 0.0 -1.0 0.9999999403953552 0.0 0.0 +8 0.5352740287780762 0.9604101181030273 0.0 0.0 -1.0 1.0 0.0 0.0 +12 0.4956846237182617 0.9604101181030273 0.0 0.0 -1.0 1.0 0.0 0.0 +13 0.4956846237182617 0.4647254943847656 0.0 0.0 -0.9999999403953552 0.9999999403953552 0.0 0.0 +17 0.4802055358886719 0.9758901596069336 -1.0 -1.4785427993047051e-05 0.0 1.4785427993047051e-05 -1.0 0.0 +13 0.4956846237182617 0.9913692474365234 -0.9999999403953552 -1.4854152141197119e-05 0.0 1.4854152141197119e-05 -0.9999999403953552 0.0 +12 0.0 0.9913692474365234 -1.0 1.4343298062158283e-05 0.0 -1.4343298062158283e-05 -1.0 0.0 +16 0.015479087829589844 0.9758901596069336 -1.0 1.3944924830866512e-05 0.0 -1.3944924830866512e-05 -1.0 0.0 +12 0.0 0.9913692474365234 -1.0 1.4343298062158283e-05 0.0 -1.4343298062158283e-05 -1.0 0.0 +14 0.0 0.4956846237182617 -1.0 -1.3590316484624054e-05 0.0 1.3590316484624054e-05 -1.0 0.0 +19 0.4802055358886719 0.511164665222168 -1.0 -1.5412135326187126e-05 0.0 1.5412135326187126e-05 -1.0 0.0 +15 0.4956846237182617 0.4956846237182617 -0.9999999403953552 -1.54771696543321e-05 0.0 1.54771696543321e-05 -0.9999999403953552 0.0 +13 0.4956846237182617 0.9913692474365234 -0.9999999403953552 -1.4854152141197119e-05 0.0 1.4854152141197119e-05 -0.9999999403953552 0.0 +18 0.01548004150390625 0.5111637115478516 -1.0 -1.4771365385968238e-05 0.0 1.4771365385968238e-05 -1.0 0.0 +14 0.0 0.4956846237182617 -1.0 -1.3590316484624054e-05 0.0 1.3590316484624054e-05 -1.0 0.0 +15 0.4956846237182617 0.4956846237182617 -0.9999999403953552 -1.54771696543321e-05 0.0 1.54771696543321e-05 -0.9999999403953552 0.0 +10 0.713590145111084 0.9604101181030273 0.0 0.0 -1.0 -0.0 1.0 0.0 +14 0.6740007400512695 0.9604101181030273 0.0 0.0 -1.0 -0.0 1.0 0.0 +12 0.6740007400512695 0.4647254943847656 0.0 0.0 -0.9999999403953552 -0.0 0.9999999403953552 0.0 +4 0.9710850715637207 0.9294509887695312 0.0 0.0 -1.0 -0.0 1.0 0.0 +19 0.9314956665039062 0.9294509887695312 0.0 0.0 -1.0 -0.0 1.0 0.0 +17 0.9314956665039062 0.4647254943847656 0.0 0.0 -1.0 -0.0 1.0 0.0 +6 0.9999997615814209 0.4647254943847656 0.0 0.0 -1.0 -0.9999999403953552 0.0 0.0 +17 0.9604103565216064 0.4647254943847656 0.0 0.0 -1.0 -0.9999999403953552 0.0 0.0 +16 0.9604103565216064 0.0 0.0 0.0 -1.0 -0.9999999403953552 0.0 0.0 +11 0.8027482032775879 0.9604101181030273 0.0 0.0 -1.0 -1.0 0.0 0.0 +15 0.7631587982177734 0.9604101181030273 0.0 0.0 -1.0 -1.0 0.0 0.0 +14 0.7631587982177734 0.4647254943847656 0.0 0.0 -0.9999999403953552 -0.9999999403953552 0.0 0.0 +shapeKeys: +animations: 0 +drivers: 0 +} diff --git a/samples/textures/smoke00.png b/samples/textures/smoke00.png new file mode 100755 index 0000000..9be9e34 Binary files /dev/null and b/samples/textures/smoke00.png differ diff --git a/samples/textures/smoke01.png b/samples/textures/smoke01.png new file mode 100755 index 0000000..6843be4 Binary files /dev/null and b/samples/textures/smoke01.png differ diff --git a/samples/textures/smoke02.png b/samples/textures/smoke02.png new file mode 100755 index 0000000..991b787 Binary files /dev/null and b/samples/textures/smoke02.png differ diff --git a/samples/textures/smoke03.png b/samples/textures/smoke03.png new file mode 100755 index 0000000..81f2305 Binary files /dev/null and b/samples/textures/smoke03.png differ diff --git a/samples/textures/smoke04.png b/samples/textures/smoke04.png new file mode 100755 index 0000000..63cde32 Binary files /dev/null and b/samples/textures/smoke04.png differ diff --git a/samples/textures/smoke05.png b/samples/textures/smoke05.png new file mode 100755 index 0000000..541874d Binary files /dev/null and b/samples/textures/smoke05.png differ diff --git a/texture.frag b/texture.frag index 372e2f6..ddc3133 100755 --- a/texture.frag +++ b/texture.frag @@ -78,6 +78,7 @@ void main(){ vec4 finalColor = diffuseColor; if(texturingEnabled){ vec4 textureColor = texture(textures[0].pastTexture, texCoords); + vec4 mixedTexColor = mix(textureColor, texture(textures[0].nextTexture, texCoords), textures[0].mixRatio); finalColor = (textures[0].animated ? mix(textureColor, texture(textures[0].nextTexture, texCoords), textures[0].mixRatio) : textureColor); } @@ -85,13 +86,14 @@ void main(){ if(lightingEnabled){ if(normalMapEnabled){ vec3 n = vec3(texture(textures[1].pastTexture, texCoords)); + if(textures[1].animated) + n = mix(n, texture(textures[1].nextTexture, texCoords).rgb, textures[1].mixRatio); normal = mat3(tan, biTan, norm) * n; } vec3 diffuseColor = vec3(0), specularColor = vec3(0); float coef = 1; - for(int i = 0; i < numLights; i++){ vec3 lightDir = vec3(0), reflectVec, viewDir = normalize(camPos - fragPos); float attenuation = 1.0;