-
Notifications
You must be signed in to change notification settings - Fork 486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lens flare cleanup and colorization #2927
Changes from 4 commits
1238d34
cf9a9b2
32ceebd
9fba67c
0e30af9
7e43502
f0d051b
372b456
99aa3af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
// The input texture, which is set up by the Ogre Compositor infrastructure. | ||
uniform sampler2D RT; | ||
uniform sampler2D noiseRGBA; | ||
|
||
uniform float time; | ||
uniform vec3 viewport; | ||
|
||
// light pos in clip space | ||
|
@@ -11,16 +9,8 @@ uniform vec3 lightPos; | |
// lens flare scale | ||
uniform float scale; | ||
|
||
float noise(float t) | ||
{ | ||
// 256 is the size of noiseRGBA texture | ||
return texture2D(noiseRGBA, vec2(t, 0.0) / vec2(256.0)).x; | ||
} | ||
|
||
float noise(vec2 t) | ||
{ | ||
return texture2D(noiseRGBA,(t + vec2(time)) / vec2(256.0)).x; | ||
} | ||
// lens flare color | ||
uniform vec3 color; | ||
|
||
vec3 lensflare(vec2 uv,vec2 pos) | ||
{ | ||
|
@@ -30,11 +20,8 @@ vec3 lensflare(vec2 uv,vec2 pos) | |
|
||
float ang = atan(main.y, main.x); | ||
float dist = length(main); dist = pow(dist,.1); | ||
float n = noise(vec2((ang-time/9.0)*16.0,dist*32.0)); | ||
|
||
float f0 = 1.0/(length(uv-pos)*16.0/scale+1.0); | ||
|
||
f0 = f0+f0*(sin((ang+time/18.0 + noise(abs(ang)+n/2.0)*2.0)*12.0)*.1+dist*.1+.8); | ||
float f0 = 2.0/(length(uv-pos)*16.0/scale+1.0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed 1.0 to 2.0 here. After removing the legacy animated effect (which was causing ugly visual artifacts) and cc() (which had almost no effect on color), I boosted this number to restore the LensFlare's original appearance. In my opinion, we should not do this because it makes the LensFlare look washed out and maintains a very big hotspot over the light source. Those features would never have been there if the broken animated effect had never been included. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so do you recommend There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer 1.0 because the legacy animation effect made the whole lens flare look overdone. I think a more realistic lens flare effect would have excluded it. The only reason to keep 2.0 is so that appearance does not change significantly. |
||
|
||
float f2 = max(1.0/(1.0+32.0*pow(length(uvd+0.8*pos),2.0)),.0)*00.25; | ||
float f22 = max(1.0/(1.0+32.0*pow(length(uvd+0.85*pos),2.0)),.0)*00.23; | ||
|
@@ -67,13 +54,6 @@ vec3 lensflare(vec2 uv,vec2 pos) | |
return c; | ||
} | ||
|
||
// color modifier | ||
vec3 cc(vec3 color, float factor, float factor2) | ||
{ | ||
float w = color.x+color.y+color.z; | ||
return mix(color,vec3(w)*factor,w*factor2); | ||
} | ||
|
||
void main() | ||
{ | ||
// return if light is behind the view | ||
|
@@ -97,9 +77,8 @@ void main() | |
pos.x *= aspect; | ||
|
||
// compute lens flare | ||
vec3 color = vec3(1.4,1.2,1.0)*lensflare(uv, pos.xy); | ||
color = cc(color,.5,.1); | ||
vec3 finalColor = color * lensflare(uv, pos.xy); | ||
|
||
// apply lens flare | ||
gl_FragColor = texture2D(RT, gl_TexCoord[0].xy) + vec4(color, 1.0); | ||
gl_FragColor = texture2D(RT, gl_TexCoord[0].xy) + vec4(finalColor, 1.0); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1545,23 +1545,22 @@ material Gazebo/WideLensMap | |
} | ||
|
||
|
||
vertex_program Gazebo/CameraLesnFlareVS glsl | ||
vertex_program Gazebo/CameraLensFlareVS glsl | ||
{ | ||
source camera_lens_flare_vs.glsl | ||
} | ||
|
||
fragment_program Gazebo/CameraLesnFlareFS glsl | ||
fragment_program Gazebo/CameraLensFlareFS glsl | ||
{ | ||
source camera_lens_flare_fs.glsl | ||
|
||
default_params | ||
{ | ||
param_named RT int 0 | ||
param_named noiseRGBA int 1 | ||
param_named time float 0.0 | ||
param_named viewport float3 0.0 0.0 0.0 | ||
param_named lightPos float3 0 0 0 | ||
param_named scale float 1.0 | ||
param_named color float3 1.4 1.2 1.0 | ||
} | ||
} | ||
|
||
|
@@ -1571,19 +1570,15 @@ material Gazebo/CameraLensFlare | |
{ | ||
pass | ||
{ | ||
vertex_program_ref Gazebo/CameraLesnFlareVS { } | ||
fragment_program_ref Gazebo/CameraLesnFlareFS { } | ||
vertex_program_ref Gazebo/CameraLensFlareVS { } | ||
fragment_program_ref Gazebo/CameraLensFlareFS { } | ||
|
||
texture_unit RT | ||
{ | ||
tex_coord_set 0 | ||
tex_address_mode border | ||
filtering linear linear linear | ||
} | ||
texture_unit noiseRGBA | ||
{ | ||
texture noise_rgba.png | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can remove this png file as I don't think it's used else where: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ compositor CameraLensFlare/Default | |
technique | ||
{ | ||
// Temporary textures | ||
texture rt0 target_width target_height PF_A8R8G8B8 | ||
texture rt0 target_width target_height PF_FLOAT32_RGB | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both issues would benefit from an sdf param because most cases can work with a smaller, integer texture. Always using a FLOAT32 texture should work for every case but often waste graphics memory. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm working on a custom SDFormat parameter in scpeters@8e88380, just need to finish writing the test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm ready to approve all parts of this pull request except for this line. Can we revert it and come back to it later, perhaps in the context of #2928? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. Reverted to PF_A8R8G8B8 |
||
|
||
target rt0 | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,10 @@ namespace gazebo | |
/// \brief Plugin that adds lens flare effect to a camera or multicamera | ||
/// sensor | ||
/// The plugin has the following optional parameter: | ||
/// <scale> Scale of lens flare. Must be greater than 0 | ||
/// <scale> Scale of lens flare. Must be greater than 0 | ||
/// <color> Color of lens flare. | ||
/// \todo A potentially useful feature would be an option for contantly | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
/// updating the flare color to match the light source color. | ||
class GAZEBO_VISIBLE LensFlareSensorPlugin : public SensorPlugin | ||
{ | ||
/// \brief Constructor. | ||
|
@@ -41,6 +44,14 @@ namespace gazebo | |
public: virtual void Load(sensors::SensorPtr _sensor, | ||
sdf::ElementPtr _sdf); | ||
|
||
/// \brief Set the scale of lens flare. | ||
/// \param[in] _scale Scale of lens flare | ||
public: void SetScale(const double _scale); | ||
|
||
/// \brief Set the color of lens flare. | ||
/// \param[in] _color Color of lens flare | ||
public: void SetColor(const ignition::math::Vector3d& _color); | ||
|
||
/// \brief Add lens flare effect to a camera | ||
/// \param[in] _camera Camera to add the lens flare effect to. | ||
private: void AddLensFlare(rendering::CameraPtr _camera); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass by const ref here as well. For consistency with gazebo coding style, can you put
&
next to variable name, i.e.&_color
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done