Can't pass values into the shader

Hi I’m working on Blender’s source code trying to insert glsl shading into Blender’s 3d Viewport.

I’ve tried everything and I can’t understand why I can’t pass values into the shader. I don’t get any error from gdb nor from gldb.

First of all when Blender starts, if glsl is supported a simple shader is initialized:

  void init_lambert_shader(void)
{
  unsigned int local_vertex_shader, local_fragment_shader;
  GLint  vert_compiled, frag_compiled;
  GLint  linked;
  GLint local_program;
  
  char *vertex_shader = read_shader_file("/home/maike/shaders/l.vert");
  char *fragment_shader = read_shader_file("/home/maike/shaders/l.frag");

  local_vertex_shader = glCreateShaderObjectARB(GL_VERTEX_SHADER);
  local_fragment_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER);
  
  glShaderSourceARB(local_vertex_shader, 1, &vertex_shader, NULL);
  glShaderSourceARB(local_fragment_shader, 1, &fragment_shader, NULL);
    
  glCompileShaderARB(local_vertex_shader);
  glGetObjectParameterivARB(local_vertex_shader, GL_COMPILE_STATUS, &vert_compiled);
  
  glCompileShaderARB(local_fragment_shader);
  glGetObjectParameterivARB(local_fragment_shader, GL_COMPILE_STATUS, &frag_compiled);

  if (!vert_compiled){
    printf("
erro
");
    return;
  }
  if(!frag_compiled){
    printf("
errof
");
    return;
  }
  
  local_program = glCreateProgramObjectARB();
  glAttachObjectARB(local_program, local_vertex_shader);
  glAttachObjectARB(local_program, local_fragment_shader);

  glLinkProgramARB(local_program);
  glGetProgramivARB(local_program, GL_LINK_STATUS, &linked);
  
  if (!linked){
    printf("
erro2
");
    return;
  }
  
  lambert = local_program;
  lambert_ref = glGetUniformLocationARB(local_program, "ref");
}

where lambert and lambert_ref are static globals.

then everytime anything needs update this function is called:

 void glsl_draw_mesh(Base *base){
  Object *ob = base->object;
  DerivedMesh *dm= mesh_get_derived_final(ob, get_viewedit_datamask());
  CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
  MFace *face = cddm->mface;
  MVert *vert = cddm->mvert;
  DrawColors colors;

  float *nors = dm->getFaceDataArray(dm, CD_NORMAL);
  int i;

  get_colors(&colors);
  draw_outline(base, ob, &colors);
  glUseProgramObjectARB(get_material_shader());
  glShadeModel(face->flag & ME_SMOOTH?GL_SMOOTH:GL_FLAT);
     
  print_log();

  for(i = 0; i < dm->numFaceData; i++, face++){
    set_lambert_param(ob->data, face);    
    set_draw_color(ob->data, face, &colors);

    glBegin(face->v4?GL_QUADS:GL_TRIANGLES);
    if(!(face->flag & ME_SMOOTH)){
      if(nors){
	glNormal3fv(nors);
      }
      else{
	float nor[3];
	if(face->v4) {
	  CalcNormFloat4(vert[face->v1].co, vert[face->v2].co, vert[face->v3].co, vert[face->v4].co, nor);
	} 
	else {
	  CalcNormFloat(vert[face->v1].co, vert[face->v2].co, vert[face->v3].co, nor);
	}
	glNormal3fv(nor);	
      }
    }

    create_vertex(ob, vert, face->v1, face->flag);
    create_vertex(ob, vert, face->v2, face->flag);
    create_vertex(ob, vert, face->v3, face->flag);
    if(face->v4)
       create_vertex(ob, vert, face->v4, face->flag);
  
    if(nors) nors += 3;

    glEnd();
  }

  glUseProgramObjectARB(0);
  glShadeModel(GL_FLAT);
}
 

and I try to pass the uniform’s value in:

 void set_lambert_param(Mesh *mesh, MFace *face)
{ 
  Material *mat; 
  GLint location = get_lambert_ref();
  int error;

  if(location == -1)
      exit(0);

  if(mesh->mat){
    mat = mesh->mat[face->mat_nr];
    glUniform1fARB(location, mat->ref);
  }
  else
    glUniform1fARB(location, 0.8); 
} 

I’ve tried to do the same with Attribute but it doesn’t work either.
The shaders compile and work fine, but it receives any value as 0.0 or as 1.0.

I’ve corrected every single error that Gdb and Gldb detected and still I can’t send values into the shader.

Help on this subject would be really great.

Thanks.

I’d sprinkle in a few calls to glGetError() to see if you’re doing something wrong somewhere.

I’ve printed location, and if i have 2 uniforms it prints out 0 and 1 as respective locations.

I’ve put a glGetError() after passing the uniform and it prints out 0.

The shaders compile perfectly and the program is successfully linked. The calculations within the shader work fine except when passing values by uniforms ou attributes which are set to 0.0 or 1.0 as I declared them as floats.

You would need to call

glUseProgramObjectARB(get_material_shader());

before passing the uniform’s value.
The ProgramObject needs to be made part of the current state.

It’s a Blender problem.
I’ve copied my code into another app and it works fine.
Now I have to discover what the problem is.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.