This topic is 710 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I have a 16bit RGB565 and I have the result from dot product and its 0->1.

I would like to map the dot product value from light source to the normal vector in a mesh to 16bit color value.

uint16_t floatToRGB565(float input)
{
uint8_t x = input*255;
uint8_t r = (x&248u);//0xff-0x07, 5msb mask
uint8_t g = (x&252u);//0xff-0x03, 6msb mask
uint8_t b = (x&248u);//0xff-0x07, 6msb mask

return (r<<8)|(g<<3)|(b>>3);// assuming r is at msb
}

dp = Dot_Product_3D((vector_3d_ptr)&normal,
(vector_3d_ptr)&light_source);

// test if light ray is reflecting off surface

if (dp > 0)
{

float intens ;
uint16_t colorMod;
int r,g,b;
float Red, Green, Blue, result;
intensity = ambient_light + dp;

if (intensity > 1)
intensity = 1;
if (intensity < 0)
intensity = 0;
r = the_object->polys[curr_poly].color >> 11;
g = (the_object->polys[curr_poly].color >>5)&0x00FF;
b = the_object->polys[curr_poly].color & 0x0000FF;
Red = r*intensity;
Green = g*intensity;
Blue = b*intensity;
result = (int)(Red * 31) << 11 | (int)(Green * 63) << 5 | (int)(Blue * 31);
colorMod = floatToRGB565(result);
// printf("\nintensity of polygon %d is %f",curr_poly,intensity);

} // end if light is reflecting off surface
else{
int r,g,b;
float Red, Green, Blue, result;
float colorModulate;
uint16_t colorMod;
r = the_object->polys[curr_poly].color >> 11;
g = (the_object->polys[curr_poly].color >>5)&0x00FF;
b = the_object->polys[curr_poly].color & 0x0000FF;
Red = r*ambient_light;
Green = g*ambient_light;
Blue = b*ambient_light;
colorModulate = (int)(Red * 31) << 11 | (int)(Green * 63) << 5 | (int)(Blue * 31);
colorMod = floatToRGB565(colorModulate);
}
} // end if use flat shading

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• Forum Statistics

• Total Topics
632991
• Total Posts
3009753
• Who's Online (See full list)

There are no registered users currently online

×