mirror of
https://github.com/ApfelTeeSaft/vb01.git
synced 2026-08-26 19:33:45 +00:00
updated samples to use the new shader system
some bugfixes
This commit is contained in:
+2
-2
@@ -75,8 +75,8 @@ int main(){
|
||||
* and frame number.
|
||||
*/
|
||||
KeyframeChannel kcL;
|
||||
kcL.animatable = leftMat;
|
||||
kcL.type = KeyframeChannel::DIFFUSE_COLOR_X;
|
||||
kcL.animatable = leftMat->getUniform("diffuseColor");
|
||||
kcL.type = KeyframeChannel::UNIFORM_1;
|
||||
kcL.keyframes = vector<Keyframe>({
|
||||
KeyframeChannel::createKeyframe(Keyframe::LINEAR, 1, 0),
|
||||
KeyframeChannel::createKeyframe(Keyframe::LINEAR, 0, 1)
|
||||
|
||||
@@ -51,10 +51,9 @@ namespace vb01{
|
||||
}
|
||||
|
||||
void Light::initDepthMap(){
|
||||
string basePath = Root::getSingleton()->getLibPath() + "depthMap.";
|
||||
|
||||
glGenFramebuffers(1, &depthmapFBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, depthmapFBO);
|
||||
string basePath = Root::getSingleton()->getLibPath() + "depthMap";
|
||||
|
||||
if(type == POINT){
|
||||
depthMap = new Texture(depthMapSize);
|
||||
@@ -131,8 +130,10 @@ namespace vb01{
|
||||
|
||||
for(Node *n : descendants){
|
||||
vector<Mesh*> meshes = n->getMeshes();
|
||||
|
||||
for(Mesh *mesh : meshes){
|
||||
Material *mat = mesh->getMaterial();
|
||||
|
||||
if(mesh->isCastShadow() && n->isVisible() && mat && ((Material::BoolUniform*)mat->getUniform("lightingEnabled"))->value){
|
||||
Vector3 pos = n->localToGlobalPosition(Vector3::VEC_ZERO);
|
||||
Quaternion rot = n->localToGlobalOrientation(Quaternion::QUAT_W);
|
||||
@@ -140,6 +141,7 @@ namespace vb01{
|
||||
|
||||
if(rotAxis == Vector3::VEC_ZERO)
|
||||
rotAxis = Vector3::VEC_I;
|
||||
|
||||
mat4 model = translate(mat4(1.f), vec3(pos.x, pos.y, pos.z));
|
||||
model = rotate(model, rot.getAngle(), vec3(rotAxis.x, rotAxis.y, rotAxis.z));
|
||||
|
||||
@@ -147,12 +149,15 @@ namespace vb01{
|
||||
|
||||
if(type == POINT){
|
||||
vec3 dirs[] = {vec3(1, 0, 0), vec3(-1, 0, 0), vec3(0, 1, 0), vec3(0, -1, 0), vec3(0, 0, 1), vec3(0, 0, -1)};
|
||||
|
||||
for(int i = 0; i < 6; i++){
|
||||
vec3 upVec;
|
||||
|
||||
if(1 < i && i < 4)
|
||||
upVec = vec3(0, 0, -1);
|
||||
else
|
||||
upVec = vec3(0, -1, 0);
|
||||
|
||||
depthMapShader->setMat4(proj * lookAt(lightPos, lightPos + dirs[i], upVec), "shadowMat[" + to_string(i) + "]");
|
||||
}
|
||||
|
||||
|
||||
+5
-7
@@ -7,8 +7,6 @@
|
||||
#include "animation.h"
|
||||
#include "animationController.h"
|
||||
#include "animationChannel.h"
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
@@ -49,19 +47,19 @@ int main(){
|
||||
mat->addVariable("texturingEnabled", true);
|
||||
mat->addVariable("lightingEnabled", true);
|
||||
mat->addVariable("normalMapEnabled", true);
|
||||
mat->addVariable("specularMapEnabled", true);
|
||||
mat->addVariable("specularMapEnabled", false);
|
||||
|
||||
string im0[] = {TEX_PATH + "bricks.jpg"};
|
||||
Texture *diffuseTex = new Texture(im0, 1);
|
||||
mat->addVariable("textures[0]", diffuseTex);
|
||||
mat->addVariable("textures[0]", diffuseTex, false);
|
||||
|
||||
string im1[] = {TEX_PATH + "bricksNormal.jpg"};
|
||||
Texture *normalTex = new Texture(im1, 1, Texture::NORMAL);
|
||||
mat->addVariable("textures[1]", normalTex);
|
||||
mat->addVariable("textures[1]", normalTex, false);
|
||||
|
||||
string im2[] = {TEX_PATH + "bricksSpecular.jpg"};
|
||||
Texture *specularTex = new Texture(im2, 1, Texture::SPECULAR);
|
||||
mat->addVariable("textures[2]", specularTex);
|
||||
mat->addVariable("textures[2]", specularTex, false);
|
||||
|
||||
//Setting specular parameteres
|
||||
mat->addVariable("specularStrength", 1);
|
||||
@@ -79,7 +77,7 @@ int main(){
|
||||
Node *lightNode = new Node(Vector3::VEC_ZERO, Quaternion::QUAT_W, Vector3::VEC_IJK, "", new AnimationController());
|
||||
lightNode->addLight(light);
|
||||
rootNode->attachChild(lightNode);
|
||||
lightNode->setOrientation(Quaternion(.7, Vector3(1, 0, 0)));
|
||||
lightNode->setOrientation(Quaternion(.0, Vector3(1, 0, 0)));
|
||||
lightNode->setPosition(Vector3(0, 5, -5));
|
||||
|
||||
/*
|
||||
|
||||
+4
-1
@@ -66,17 +66,20 @@ namespace vb01{
|
||||
case Uniform::TEXTURE:{
|
||||
TextureUniform *u = (TextureUniform*)uni;
|
||||
shader->setInt(2 * i, u->name + (u->animatable ? ".pastTexture" : ""));
|
||||
shader->setBool(u->animatable, u->name + ".animated");
|
||||
|
||||
if(u->value->getNumFrames() > 1){
|
||||
shader->setInt(2 * i + 1, u->name + ".nextTexture");
|
||||
shader->setFloat(u->value->getMixRatio(), u->name + ".mixRatio");
|
||||
}
|
||||
|
||||
u->value->update(2 * i);
|
||||
|
||||
++i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ namespace vb01{
|
||||
|
||||
std::string name;
|
||||
Type type;
|
||||
Material *material = nullptr;
|
||||
|
||||
protected:
|
||||
virtual void animateComponent1(float val){}
|
||||
|
||||
@@ -162,7 +162,7 @@ namespace vb01{
|
||||
|
||||
shader->setBool(castShadow, "castShadow");
|
||||
shader->setBool(skeleton, "animated");
|
||||
shader->setBool(false, "environment");
|
||||
shader->setBool(false, "environmentMapEnabled");
|
||||
shader->setMat4(view, "view");
|
||||
shader->setMat4(proj, "proj");
|
||||
shader->setVec3(camPos, "camPos");
|
||||
|
||||
@@ -45,7 +45,7 @@ int main(){
|
||||
mat->addVariable("texturingEnabled", true);
|
||||
string images[] = {TEX_PATH + "defaultTexture.jpg"};
|
||||
Texture *texture = new Texture(images, 1);
|
||||
mat->addVariable("textures[0]", texture);
|
||||
mat->addVariable("textures[0]", texture, true);
|
||||
model->setMaterial(mat);
|
||||
rootNode->attachChild(model);
|
||||
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ namespace vb01{
|
||||
|
||||
string Shader::getName(){
|
||||
int dirId = path.find_last_of('/');
|
||||
return (dirId != -1 ? path.substr(dirId) : path);
|
||||
return (dirId != -1 ? path.substr(dirId + 1) : path);
|
||||
}
|
||||
|
||||
void Shader::initShaders(string vertShaderPath, string fragShaderPath, string geoShaderPath){
|
||||
|
||||
@@ -45,7 +45,7 @@ int main(){
|
||||
mat->addVariable("texturingEnabled", true);
|
||||
string images[] = {TEX_PATH + "defaultTexture.jpg"};
|
||||
Texture *texture = new Texture(images, 1);
|
||||
mat->addVariable("textures[0]", texture);
|
||||
mat->addVariable("textures[0]", texture, true);
|
||||
model->setMaterial(mat);
|
||||
rootNode->attachChild(model);
|
||||
|
||||
|
||||
@@ -28,8 +28,10 @@ namespace vb01{
|
||||
void Text::initFont(string fontPath, u16 firstChar, u16 lastChar){
|
||||
FT_Library ft;
|
||||
FT_Face face;
|
||||
|
||||
if(FT_Init_FreeType(&ft))
|
||||
cout << "Couldn't init Freetype\n";
|
||||
|
||||
if(FT_New_Face(ft, fontPath.c_str(), 0, &face))
|
||||
cout << "Could not load font\n";
|
||||
|
||||
@@ -42,6 +44,7 @@ namespace vb01{
|
||||
cout << "Could not load glyph\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
Glyph c;
|
||||
c.ch = i;
|
||||
c.texture = new Texture(face, i);
|
||||
@@ -65,14 +68,17 @@ namespace vb01{
|
||||
shader->setVec3(node->getPosition(), "pos");
|
||||
|
||||
Vector2 advanceOffset = Vector2::VEC_ZERO;
|
||||
|
||||
for(int i = (leftToRight ? 0 : entry.length() - 1); (leftToRight ? (i < entry.length()) : (i >= 0)); (leftToRight ? i++ : i--)){
|
||||
Glyph *glyphPtr = getGlyph(entry[i]);
|
||||
|
||||
if(!glyphPtr)
|
||||
continue;
|
||||
|
||||
Glyph glyph = *glyphPtr;
|
||||
prepareGlyphs(glyph, advanceOffset);
|
||||
Vector2 size = glyph.size, bearing = glyph.bearing;
|
||||
|
||||
if(horizontal)
|
||||
advanceOffset.x += (size.x + bearing.x);
|
||||
else
|
||||
@@ -85,6 +91,7 @@ namespace vb01{
|
||||
Vector2 origin = Vector2(nodePos.x, nodePos.y) + (advanceOffset * scale);
|
||||
|
||||
Vector2 size = glyph.size * scale, bearing = glyph.bearing * scale;
|
||||
|
||||
float data[] = {
|
||||
origin.x + bearing.x, origin.y - bearing.y, 0, 0,
|
||||
origin.x + bearing.x + size.x, origin.y - bearing.y, 1, 0,
|
||||
@@ -102,7 +109,11 @@ namespace vb01{
|
||||
glBindVertexArray(VAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, dataSize, data);
|
||||
glyph.texture->select(2);
|
||||
|
||||
int id = 2;
|
||||
material->getShader()->setInt(id, "textures[1].pastTexture");
|
||||
glyph.texture->select(id);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
}
|
||||
|
||||
@@ -122,9 +133,11 @@ namespace vb01{
|
||||
|
||||
Text::Glyph* Text::getGlyph(u16 ch){
|
||||
Glyph *glyph = nullptr;
|
||||
|
||||
for(Glyph &g : characters)
|
||||
if(g.ch == ch)
|
||||
glyph = &g;
|
||||
|
||||
return glyph;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,10 @@ uniform vec4 diffuseColor;
|
||||
|
||||
void main(){
|
||||
vec4 diffCol;
|
||||
|
||||
if(texturingEnabled){
|
||||
diffCol = texture(textures[0].pastTexture, texCoords);
|
||||
|
||||
if(textures[0].animated)
|
||||
diffCol = mix(diffCol, texture(textures[0].nextTexture, texCoords), textures[0].mixRatio);
|
||||
}
|
||||
|
||||
+2
-2
@@ -56,10 +56,10 @@ int main(){
|
||||
|
||||
string frames[]{TEX_PATH + "bricks.jpg", TEX_PATH + "defaultTexture.jpg"};
|
||||
Texture *texture = new Texture(frames, 2);
|
||||
textMat->addVariable("textures[0]", texture);
|
||||
textMat->addVariable("textures[0]", texture, true);
|
||||
|
||||
for(int i = 0; i < numTexts; i++){
|
||||
Text *text = new Text(FONT_PATH + fonts[i], texts[i]);
|
||||
Text *text = new Text(FONT_PATH + fonts[i], texts[i], 0, 60000);
|
||||
text->setLeftToRight(leftToRight[i]);
|
||||
text->setScale(.5);
|
||||
text->setHorizontal(horizontal[i]);
|
||||
|
||||
Reference in New Issue
Block a user