Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: specular, diffuse, and ambient

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2001
    Posts
    16

    specular, diffuse, and ambient

    Okay, I'm reading in a data file and the parser only reads in a single float value for specular and diffuse. My instructor says that specular, diffuse, and ambient should sum to one, so the parser doesn't bother to read in a value for ambient.

    Fine, but the data file has only ONE value for each? Each one requires an array with 4 float values, I know the first three on ambient is for an RGB color, but could anyone explain what each of the 4 numbers should be? My instructor said that I could easily find all 4 numbers from the single float.

    This is really important to my project as some of my objects are getting EXTREME glare causing exaggerated gradients of light and dark. Thank in advance.

  2. #2
    Intern Contributor
    Join Date
    Dec 2000
    Location
    Donetsk, Ukraine
    Posts
    55

    Re: specular, diffuse, and ambient

    Interesting, packing 4 floats in one... Ye may use float as 4byte array and put your Red Green Blue and Alpha values as fixed-point byte.

  3. #3
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: specular, diffuse, and ambient

    Strange requirements
    What I understood from the given explanations your ambient, diffuse and specular values of a material should sum up to 1.0.
    That means you need two values and can get the third calculated from them.
    You read one float for diffuse and one float for specular, right?
    That means you don't have any color informations in the data, right?
    That would mean you can only display greyscale materials where red, green and blue are all identical taken from the float you read or calculated and alpha is assumed to be 1.0 for opaque materials.

    The question is, do you have a material COLOR in some RGB in the file as three floats or not?
    If yes, and the diffuse and specular are only given as one float, you need to multiply the ambient color channels with the diffuse and specular scaling factors and put those into the diffuse and specular meterial properties.

    Though this is no lighting calculation, yet.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,797

    Re: specular, diffuse, and ambient

    Is the ONE value in the file actually a float? If it could be read in as an int, then it could just be a number in the form
    0xRRGGBBAA (or 0xAARRGGBB, or something else like that) To get float values from the first one, you could do something like so..

    n = ValueFromFile
    r = (float)((n & 0xFF000000) >> 24) / 255.0;
    g = (float)((n & 0x00FF0000) >> 16) / 255.0;
    b = (float)((n & 0x0000FF00) >> 8) / 255.0;
    a = (float)((n & 0x000000FF)) / 255.0;
    Deiussum
    Software Engineer and OpenGL enthusiast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •