All pastes #636048 Raw Edit

Someone

public text v1 · immutable
#636048 ·published 2007-07-27 15:58 UTC
rendered paste body
/* ------------------------------------------- */
/* ------- Texture Generation ---------------- */
/* ------------------------------------------- */

static void glsl_cb_add_tex(GLSL_ColorBand colorband, short type)
{
  float texels[4];
  ColorBand *cb = colorband->colorband;
  int i;

  if(colorband->tex_set)
    glDeleteTextures(1, &colorband->texid);

  for(i = 0; i < 512; i++){
    do_colorband(cb, (float) i / 511, texels);
    colorband->tex[i][0] = texels[0];
    colorband->tex[i][1] = texels[1];
    colorband->tex[i][2] = texels[2];
    colorband->tex[i][3] = texels[3];
  }

  glGenTextures(1, &colorband->texid);
  glActiveTexture(GL_TEXTURE0 + type);
  glBindTexture(GL_TEXTURE_1D, colorband->texid);
  glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, COLORBAND_WIDTH, 0, GL_RGBA, GL_UNSIGNED_BYTE, colorband->tex);
  glEnable(GL_TEXTURE_1D);
  colorband->tex_set = 1;
  glActiveTexture(GL_TEXTURE0);
}


/* -------------------------------------------- */
/* ---- Uniforms sent by frame ---------------- */
/* -------------------------------------------- */

void glsl_update_colorband_uniforms(GLuint program, Material *mat, int index)
{
  char *diff_fac, *spec_fac;
  char *diff_tex, *spec_tex;
  
  GLSL_Material material = BLI_ghash_lookup(matHash, mat);

  if(!material) return;


  if(mat->mode & MA_RAMP_COL){
    GLSL_ColorBand colorband = material->diff_ramp;

    diff_fac = glsl_string(5, 0, "u_mat_", GINT, index, 0, "_ramp_", GINT, 0, 0, "_fac");
    glUniform1f(glsl_uniform_location(program, diff_fac), mat->rampfac_col);

    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_1D, colorband->texid);
    diff_tex = glsl_string(5, 0, "u_mat_", GINT, index, 0, "_ramp_", GINT, 0, 0, "_tex");
    glUniform1i(glsl_uniform_location(program, diff_tex), 1);
    glEnable(GL_TEXTURE_1D);
    

    MEM_freeN(diff_fac);     
    MEM_freeN(diff_tex);
    printf("\nGLSL Diffuse Colorband Uniform sent\n");
  }
  if(mat->mode & MA_RAMP_SPEC){
    GLSL_ColorBand colorband = material->spec_ramp;

    spec_fac = glsl_string(5, 0, "u_mat_", GINT, index, 0, "_ramp_", GINT, 1, 0, "_fac");    
    glUniform1f(glsl_uniform_location(program, spec_fac), mat->rampfac_spec);   

    glActiveTexture(GL_TEXTURE2);
    glBindTexture(GL_TEXTURE_1D, colorband->texid);
    spec_tex = glsl_string(5, 0, "u_mat_", GINT, index, 0, "_ramp_", GINT, 1, 0, "_tex");
    glUniform1i(glsl_uniform_location(program, spec_tex), 2);
    glEnable(GL_TEXTURE_1D);

    MEM_freeN(spec_fac);
    MEM_freeN(spec_tex);
    printf("\nGLSL Specular Colorband Uniform sent\n");
  }
  
  glActiveTexture(GL_TEXTURE0);
}