rename
This commit is contained in:
parent
d742d49486
commit
ddbd1f9ae5
3 changed files with 15 additions and 14 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
in vec4 pos_model;
|
||||
in vec3 vec_normal;
|
||||
in vec4 smcoord;
|
||||
in vec4 shadowMapCoord;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
|
@ -12,7 +12,7 @@ uniform vec4 couleur;
|
|||
uniform vec4 lumPos[max];
|
||||
uniform mat4 view;
|
||||
uniform vec4 lumColor[max];
|
||||
uniform sampler2D sm;
|
||||
uniform sampler2D shadowmap;
|
||||
|
||||
void main() {
|
||||
const vec3 vue = vec3(0, 0, -1);
|
||||
|
@ -22,8 +22,8 @@ void main() {
|
|||
vec3 torche = normalize(pos_model.xyz - lumPos[i].xyz);
|
||||
float intensite_lumineuse = clamp(dot(vec_normal, -torche), 0., 1.);
|
||||
|
||||
vec3 smpcoord = smcoord.xyz / smcoord.w;
|
||||
if(texture(sm, smpcoord.xy).r < smpcoord.z) {
|
||||
vec3 shadowMapPcoord = shadowMapCoord.xyz / shadowMapCoord.w;
|
||||
if(texture(shadowmap, shadowMapPcoord.xy).r < shadowMapPcoord.z) {
|
||||
intensite_lumineuse = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ layout(location = 1) in vec3 normal;
|
|||
|
||||
out vec4 pos_model;
|
||||
out vec3 vec_normal;
|
||||
out vec4 smcoord;
|
||||
out vec4 shadowMapCoord;
|
||||
|
||||
uniform mat4 proj, model, view;
|
||||
uniform mat4 lightView, lightProjection;
|
||||
|
@ -16,6 +16,6 @@ void main() {
|
|||
pos_model = model * vec4(pos, 1);
|
||||
vec_normal = normalize(transpose(inverse(model)) * vec4(normal, 0)).xyz;
|
||||
|
||||
smcoord = bias * lightProjection * lightView * pos_model;
|
||||
shadowMapCoord = bias * lightProjection * lightView * pos_model;
|
||||
gl_Position = proj * view * pos_model;
|
||||
}
|
||||
|
|
17
src/manif.c
17
src/manif.c
|
@ -7,7 +7,7 @@ static GLuint _planId = 0;
|
|||
static struct manifestant _herosId[HEROS_NUMBER];
|
||||
|
||||
#define SHADOW_MAP_SIDE 1024
|
||||
static GLuint _fbo = 0, _smTex = 0;
|
||||
static GLuint _fbo = 0, _shadow_map_tex = 0;
|
||||
|
||||
static const char *matrix_proj = "proj";
|
||||
static const char *matrix_model = "model";
|
||||
|
@ -62,8 +62,8 @@ static void init(void) {
|
|||
gl4duGenMatrix(GL_FLOAT, matrix_lproj);
|
||||
|
||||
// Création et paramétrage de la Texture de shadow map
|
||||
glGenTextures(1, &_smTex);
|
||||
glBindTexture(GL_TEXTURE_2D, _smTex);
|
||||
glGenTextures(1, &_shadow_map_tex);
|
||||
glBindTexture(GL_TEXTURE_2D, _shadow_map_tex);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, SHADOW_MAP_SIDE,
|
||||
|
@ -93,7 +93,7 @@ static void draw(void) {
|
|||
glCullFace(GL_FRONT);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,
|
||||
_smTex, 0);
|
||||
_shadow_map_tex, 0);
|
||||
glViewport(0, 0, SHADOW_MAP_SIDE, SHADOW_MAP_SIDE);
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
for (int i = 0; i < HEROS_NUMBER; ++i) {
|
||||
|
@ -148,16 +148,17 @@ static void draw(void) {
|
|||
drawManifestant(matrix_model, &_herosId[i], deplacement, GL_TRUE);
|
||||
}
|
||||
|
||||
int max_gpu = 3; // HEROS_NUMBER;
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, _smTex);
|
||||
glBindTexture(GL_TEXTURE_2D, _shadow_map_tex);
|
||||
int max_gpu = 3; // HEROS_NUMBER;
|
||||
glUniform4fv(glGetUniformLocation(_pId[0], "lumPos"), max_gpu,
|
||||
(float *)lumpos);
|
||||
glUniform4fv(glGetUniformLocation(_pId[0], "lumColor"), max_gpu,
|
||||
(float *)lumcolor);
|
||||
glUniform1i(glGetUniformLocation(_pId[0], "sm"), 0);
|
||||
glUniform1i(glGetUniformLocation(_pId[0], "shadowmap"), 0);
|
||||
|
||||
deplacement += (float)(0.4 * M_PI * dt);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glUseProgram(0);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
@ -166,7 +167,7 @@ static void draw(void) {
|
|||
|
||||
static void deinit(void) {
|
||||
if (_fbo) {
|
||||
glDeleteTextures(1, &_smTex);
|
||||
glDeleteTextures(1, &_shadow_map_tex);
|
||||
glDeleteFramebuffers(1, &_fbo);
|
||||
_fbo = 0;
|
||||
}
|
||||
|
|
Reference in a new issue