Pipeline graphique
 Tout Structures de données Espaces de nommage Fichiers Fonctions Variables Définitions de type Énumérations Valeurs énumérées Macros
ShaderPhong.cpp
Aller à la documentation de ce fichier.
1 /*
2  * File: ShaderPhong.cpp
3  * Author: quartz
4  *
5  * Created on 26 octobre 2014, 15:43
6  */
7 
8 #include "ShaderPhong.h"
18 void ShaderPhong::PixelShader(void *In, void *Out, void *Param, std::size_t x, std::size_t y)
19 {
20  if(debug)
21  std::cout <<std::endl<<std::endl << "////////////////ETAPE PIXEL SHADER////////////////"<< std::endl;
22  pixelIN &in = *(pixelIN*)In;
23  pixelOUT &out = *(pixelOUT*)Out;
24 
25 
28  N.normalize();
29 
30  int I = 0;
31  Math::vecteur3d V = this->poscamLocal - pos;
32  V.normalize();
33  for(unsigned int u = 0; u < this->nlightLocal; u++)
34  {
35  Math::vecteur3d L = (this->lightsLocal[u].pos*-1) - pos;
36 
37 
38  //std::cout << "L x " << L.x <<", y " << L.y << ", z " << L.z <<std::endl;
39  L.normalize();
40 
41 /*
42  std::cout << "ligth x " << lightsLocal[u].pos.x << ", y " << lightsLocal[u].pos.y << ", z " << lightsLocal[u].pos.z << std::endl;
43  std::cout << "pos x " << pos.x <<", y " << pos.y << ", z " << pos.z <<std::endl;
44  std::cout << "norm x " << N.x <<", y " << N.y << ", z " << N.z <<std::endl;
45  std::cout << "L norm x " << L.x <<", y " << L.y << ", z " << L.z <<std::endl;
46 */
47  float cos = Math::dot3(L ,N);
48 
49  if(cos > 0)
50  {
51  Math::vecteur3d R = (2*N)*cos - L;
52 
53  float cosspecu = Math::dot3(R ,V);
54  cosspecu = pow(cosspecu,this->material.ns);
55  I += this->lightsLocal[u].intensiter * this->material.ks * cosspecu;
56 
57  }
58 
59  //std::cout << "cos " << cos << std::endl;
60 
61  if(cos >= 0 && cos <= 1)
62  I += cos * this->material.kd * this->lightsLocal[u].intensiter ;
63 
64  }
65  if(I > 255)
66  {
67  out.col.set(255);
68  }
69  else
70  {
71  out.col.set(I);
72  }
73 
74  int r = (material.col.r *out.col.r) / 255;
75  int g = (material.col.g *out.col.g) / 255;
76  int b = (material.col.b *out.col.b) / 255;
77 
78  out.col.r = r;
79  out.col.g = g;
80  out.col.b = b;
81 
82  if(debug)
83  {
84  std::cout << "Sortie du pixel Shader:";
85  out.print();
86  }
87 
88 
89 }
90 
92 {
93 
94 }
95 
97 {
98 }
99 
Light_Local * lightsLocal
Definition: ShaderBase.h:19
unsigned char r
Definition: definition.h:61
bool debug
Definition: ShaderBase.h:29
void PixelShader(void *In, void *Out, void *Param, std::size_t x, std::size_t y)
ShaderPhong::PixelShader(void *In, void *Out, void *Param, std::size_t x, std::size_t y) Fonction per...
Definition: ShaderPhong.cpp:18
virtual ~ShaderPhong()
Definition: ShaderPhong.cpp:96
float dot3(coord2d v1, coord2d v2)
Definition: libMath.h:30
Sommet * sommet
Definition: definition.h:134
void set(unsigned char t)
Definition: definition.h:64
float ns
Definition: Material.h:10
Math::vecteur3d PosBaricentrique(Math::coord2d P, FaceteEcran *facette, Sommet *somettransformer)
PosBaricentrique(Math::coord2d P,FaceteEcran *facette, Sommet *somettransformer) Fonction permetant d...
Definition: utils.cpp:142
unsigned int nlightLocal
Nombre de lampes actives.
Definition: ShaderBase.h:17
unsigned int intensiter
Definition: Light.h:34
float kd
coefficient de réflexion diffuse
Definition: Material.h:8
Math::vecteur3d poscamLocal
Definition: ShaderBase.h:22
bool normalize(const float nrm)
U.normalize(norm) normalisation (sur place) en passant la norme. Retourne faux si la norme est nulle...
Definition: libMath.h:55
unsigned char g
Definition: definition.h:61
rgb col
couleur de l'objet
Definition: Material.h:7
float ks
coefficient de réflexion spéculaire
Definition: Material.h:9
Math::vecteur3d pos
Position de la lampe.
Definition: Light.h:32
FaceteEcran * facette
Definition: definition.h:133
Math::coord2d P
Definition: definition.h:132
unsigned char b
Definition: definition.h:61
void print()
Definition: definition.h:146
Math::vecteur3d NBaricentrique(Math::coord2d P, FaceteEcran *facette, Sommet *somettransformer)
NBaricentrique(Math::coord2d P,FaceteEcran *facette, Sommet *somettransformer) Fonction permetant de ...
Definition: utils.cpp:79
Material material
Matériau de l'objet.
Definition: ShaderBase.h:26