small changes
This commit is contained in:
parent
0872b425b1
commit
c534c7b4e7
@ -50,21 +50,21 @@ void MyGLWidget::buildScene()
|
|||||||
SkyboxModule* skybox = new SkyboxModule(skyboxCubemap);
|
SkyboxModule* skybox = new SkyboxModule(skyboxCubemap);
|
||||||
|
|
||||||
// create a mesh
|
// create a mesh
|
||||||
//Mesh* myGrid = new GridMesh(10, 10, true); //new Sphere(2);
|
//Mesh* myMesh = new GridMesh(10, 10, true);
|
||||||
Mesh* myGrid = Utils::loadOBJ("../data/sword.obj");
|
//Mesh* myMesh = Utils::loadOBJ("../data/sword.obj");
|
||||||
myGrid->initGL();
|
Mesh* myMesh = new Sphere(4);
|
||||||
|
myMesh->initGL();
|
||||||
|
|
||||||
//
|
|
||||||
std::string vertSource = Utils::fileToString("../phong.vert");
|
std::string vertSource = Utils::fileToString("../phong.vert");
|
||||||
std::string fragSource = Utils::fileToString("../phong.frag");
|
std::string fragSource = Utils::fileToString("../phong.frag");
|
||||||
Shader* phongShader = new Shader(vertSource, fragSource);
|
Shader* phongShader = new Shader(vertSource, fragSource);
|
||||||
PhongMaterial* mat = new PhongMaterial(phongShader, glm::vec3(1), glm::vec3(1), 20.0f);
|
PhongMaterial* mat = new PhongMaterial(phongShader, glm::vec3(1), glm::vec3(1), 20.0f);
|
||||||
Texture* tex = new Texture("../data/noise.png");
|
Texture* tex = new Texture(); //new Texture("../data/noise.png");
|
||||||
mat->setTexture(tex);
|
mat->setTexture(tex);
|
||||||
|
|
||||||
Entity* myEntity = new Entity(myGrid, mat);
|
Entity* myEntity = new Entity(myMesh, mat);
|
||||||
glm::mat4* transform = myEntity->getTransform();
|
glm::mat4* transform = myEntity->getTransform();
|
||||||
*transform = glm::scale(*transform, glm::vec3(0.01f));
|
//*transform = glm::scale(*transform, glm::vec3(0.01f));
|
||||||
|
|
||||||
Lights* directionnalLights = new Lights();
|
Lights* directionnalLights = new Lights();
|
||||||
directionnalLights->addLight(glm::vec3(6, 4, -4), glm::vec3(0.7f, 0.6f, 0.4f)); // sun
|
directionnalLights->addLight(glm::vec3(6, 4, -4), glm::vec3(0.7f, 0.6f, 0.4f)); // sun
|
||||||
|
@ -39,13 +39,12 @@ vec3 computeLight(in vec3 kd, in vec3 ks, in float ns, in vec3 color, in vec3 no
|
|||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
int i;
|
int i;
|
||||||
vec3 kd = vec3(0.5);
|
vec3 kd = vec3(texture2D(baseTexture, varTexCoord));
|
||||||
vec3 light = 0.1*kd;
|
vec3 light = 0.1*kd;
|
||||||
vec3 myNormal = normalize(varNormal + 0.3 - 0.6*vec3(texture2D(baseTexture, varTexCoord)));
|
|
||||||
for(i=0; i<nbDirLights && i<4; ++i)
|
for(i=0; i<nbDirLights && i<4; ++i)
|
||||||
light += computeLight(kd, materialKs, materialNs, dirLights[i*2+1], myNormal, lightDirInView[i], halfVecInView[i]);
|
light += computeLight(kd, materialKs, materialNs, dirLights[i*2+1], varNormal, lightDirInView[i], halfVecInView[i]);
|
||||||
for(i=0; i<nbPointLights && i+nbDirLights<4; ++i)
|
for(i=0; i<nbPointLights && i+nbDirLights<4; ++i)
|
||||||
light += computeLight(kd, materialKs, materialNs, pointLights[i*2+1], myNormal, lightDirInView[nbDirLights+i], halfVecInView[nbDirLights+i]);
|
light += computeLight(kd, materialKs, materialNs, pointLights[i*2+1], varNormal, lightDirInView[nbDirLights+i], halfVecInView[nbDirLights+i]);
|
||||||
|
|
||||||
outColor = vec4(light, 1);
|
outColor = vec4(light, 1);
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,6 @@
|
|||||||
#include "glassert.h"
|
#include "glassert.h"
|
||||||
#include <glm/ext.hpp>
|
#include <glm/ext.hpp>
|
||||||
|
|
||||||
const std::string Shader::DEFAULT_VERT = "#version 330\nlayout(location = 0)in vec3 inPosition;\nvoid main(){gl_Position = vec4(inPosition, 1.0);}";
|
|
||||||
const std::string Shader::DEFAULT_FRAG = "#version 330\nlayout(location = 0)out vec4 outColor;\nvoid main(){outColor = vec4(1, 0, 0, 1);}";
|
|
||||||
|
|
||||||
Shader::Shader(const std::string &vertexSource, const std::string &fragmentSource)
|
Shader::Shader(const std::string &vertexSource, const std::string &fragmentSource)
|
||||||
{
|
{
|
||||||
program = glAssert(glCreateProgram());
|
program = glAssert(glCreateProgram());
|
||||||
|
2
shader.h
2
shader.h
@ -7,8 +7,6 @@
|
|||||||
|
|
||||||
class Shader
|
class Shader
|
||||||
{
|
{
|
||||||
static const std::string DEFAULT_VERT;
|
|
||||||
static const std::string DEFAULT_FRAG;
|
|
||||||
GLuint program;
|
GLuint program;
|
||||||
GLuint createShader(const std::string &source, GLenum shaderType);
|
GLuint createShader(const std::string &source, GLenum shaderType);
|
||||||
void printShaderInfoLog(GLuint shaderId);
|
void printShaderInfoLog(GLuint shaderId);
|
||||||
|
@ -73,11 +73,11 @@ int Sphere::getEdge(int a, int b)
|
|||||||
v.normal = v.position;
|
v.normal = v.position;
|
||||||
|
|
||||||
// u/v sphériques, cohérents sur toute la sphère sauf des artefacts au niveau des u==0
|
// u/v sphériques, cohérents sur toute la sphère sauf des artefacts au niveau des u==0
|
||||||
//float newU = (v.position.x < 0 ? 1.5f : 1.f) + atan(v.position.z/v.position.x)/(2*M_PI);
|
float newU = (v.position.x < 0 ? 1.5f : 1.f) + atan(v.position.z/v.position.x)/(2*M_PI);
|
||||||
//float newV = acos(v.position.y)/M_PI;
|
float newV = acos(v.position.y)/M_PI;
|
||||||
//v.texCoord = glm::vec2(newU - floor(newU), newV);
|
v.texCoord = glm::vec2(newU - floor(newU), newV);
|
||||||
// alternative, u/v moyennés :
|
// alternative, u/v moyennés :
|
||||||
v.texCoord = (v0.texCoord + v1.texCoord)/2.f;
|
//v.texCoord = (v0.texCoord + v1.texCoord)/2.f;
|
||||||
|
|
||||||
vid = vertices.size();
|
vid = vertices.size();
|
||||||
addVertex(v);
|
addVertex(v);
|
||||||
|
@ -14,7 +14,7 @@ std::string Utils::fileToString(const std::string &filename)
|
|||||||
return in.readAll().toStdString();
|
return in.readAll().toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Utils::loadOBJ(const std::string &filename)
|
/*void Utils::loadOBJ(const std::string &filename)
|
||||||
{
|
{
|
||||||
// loadOBJ
|
// loadOBJ
|
||||||
// mtllib -> loadMTL
|
// mtllib -> loadMTL
|
||||||
@ -81,7 +81,7 @@ void Utils::loadOBJ(const std::string &filename)
|
|||||||
line = in.readLine();
|
line = in.readLine();
|
||||||
}
|
}
|
||||||
f.close();
|
f.close();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void Utils::loadMTL(const std::string &filename)
|
void Utils::loadMTL(const std::string &filename)
|
||||||
{
|
{
|
||||||
|
3
utils.h
3
utils.h
@ -10,7 +10,8 @@ class Utils
|
|||||||
public:
|
public:
|
||||||
static std::string fileToString(const std::string &filename);
|
static std::string fileToString(const std::string &filename);
|
||||||
static Mesh* loadOBJ(const std::string &filename);
|
static Mesh* loadOBJ(const std::string &filename);
|
||||||
|
//static void loadOBJ(const std::string &filename);
|
||||||
|
static void loadMTL(const std::string &filename);
|
||||||
class Image
|
class Image
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user