Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if SUPPORT_SPECULAR_REFLECTION
- auto normal = polygon.plane.Normal();
- if(polygon.normalmap >= 0)
- {
- // Load sample from normalmap
- #if TEXTUREMODE==2
- xyz<float> rgb = BilinearTextureFetch<32>(polygon.normalmap, {u,v}, {u0,v0});
- #else
- unsigned c = texturedata[polygon.normalmap][ (u % txth) * txtw + (v % txtw) ];
- xyz<float> rgb = dergb(c);
- #endif
- // Convert it into a vector of 3 floats
- auto perturb = rgb * (1 / 127.5f) - 1.f;
- // Tweak the normal by that vector
- normal = normal * perturb[2]
- - polygon.tangent * perturb[1]
- + polygon.bitangent * perturb[0];
- }
- xyz<float> point = xyz<float>(prop(5), prop(6), prop(7)); // 3D location of this pixel in space
- auto addlight = [&] (const Light& l)
- {
- constexpr float fade_distance = 655360, fade_power = 2;
- xyz<float> light_to_point = (l.v - point);
- xyz<float> V = (observer - point).Normalized(); // point to camera
- float v = V.DotProduct(normal);
- float factor = light_to_point.Normalized().DotProduct( normal * (v+v) - V );
- if(factor > 0)
- {
- // Do phong/roughness adjustment
- factor = std::pow(factor, 12.0f);
- // Do distance fading to compensate for the point-light
- factor /= 1 + std::pow(light_to_point.Length()*2 / fade_distance, fade_power);
- pix += l.rgb * factor;
- }
- };
- for(const auto& l: level.lights) addlight(l);
- /*for(const auto& d: level.decorations)
- for(const auto& l: d.object->lights) addlight(l);*/
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement