# Set opacity based on distance from camera

**URL:** https://discourse.paraview.org/t/set-opacity-based-on-distance-from-camera/4814
**Category:** ParaView Support
**Created:** [July 10, 2020, 8:40pm UTC](https://discourse.paraview.org/t/set-opacity-based-on-distance-from-camera/4814 "2020-07-10T20:40:56Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![woodscn](https://discourse.paraview.org/user_avatar/discourse.paraview.org/woodscn/32/3226_2.png) [@woodscn](https://discourse.paraview.org/u/woodscn)
#### Post date: [July 10, 2020, 8:40pm UTC](https://discourse.paraview.org/t/set-opacity-based-on-distance-from-camera/4814/1 "2020-07-10T20:40:56Z")

</div>

I have a point source, and I want to set the opacity of the individual points based on the distance from the camera view. Is there a way for me to do this? Interactivity would be nice, but even something that allows me to get individual frames would be okay.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [July 13, 2020, 8:32am UTC](https://discourse.paraview.org/t/set-opacity-based-on-distance-from-camera/4814/2 "2020-07-13T08:32:21Z")

</div>

Nothing out of the box, I’m afraid.

One would need to implement a dedicated representation plugin for that.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [July 13, 2020, 7:12pm UTC](https://discourse.paraview.org/t/set-opacity-based-on-distance-from-camera/4814/3 "2020-07-13T19:12:49Z")

</div>

Isn’t this same as depth-of-field that the ray-tracing (OSPray/Optix) support?

cc: @Dave_DeMarle

---

<div class="post-metadata">

### Author: ![Dave\_DeMarle](https://discourse.paraview.org/user_avatar/discourse.paraview.org/dave_demarle/32/27_2.png) [@Dave\_DeMarle](https://discourse.paraview.org/u/Dave_DeMarle)
#### Post date: [July 13, 2020, 8:35pm UTC](https://discourse.paraview.org/t/set-opacity-based-on-distance-from-camera/4814/4 "2020-07-13T20:35:32Z")

</div>

Close but not exactly. DOF makes things in general blurrier in the distance instead of more clear. @woodscn you might want to try it out and see if it can achieve a similar enough effect to what you are going for.

A glsl shader tweak (likely exposed within a dedicated representation plugin) that takes z into account when computing alpha could do what you want and should have a neglible render time cost. One constraint is that it has to interact nicely with depth peeling for correctness.

---

<div class="post-metadata">

### Author: ![woodscn](https://discourse.paraview.org/user_avatar/discourse.paraview.org/woodscn/32/3226_2.png) [@woodscn](https://discourse.paraview.org/u/woodscn)
#### Post date: [July 20, 2020, 5:52pm UTC](https://discourse.paraview.org/t/set-opacity-based-on-distance-from-camera/4814/5 "2020-07-20T17:52:30Z")

</div>

@Dave_DeMarle I’m looking at this, but I’m not seeing any options related to depth-of-field. I’m using Paraview 5.8.0 on Windows. The default settings aren’t doing quite what I want, so it looks like I may need to look into plugins instead.

---

<div class="post-metadata">

### Author: ![Dave\_DeMarle](https://discourse.paraview.org/user_avatar/discourse.paraview.org/dave_demarle/32/27_2.png) [@Dave\_DeMarle](https://discourse.paraview.org/u/Dave_DeMarle)
#### Post date: [July 20, 2020, 6:03pm UTC](https://discourse.paraview.org/t/set-opacity-based-on-distance-from-camera/4814/6 "2020-07-20T18:03:03Z")

</div>

More specifics.

 ![DOF](https://discourse.paraview.org/uploads/default/original/2X/5/535432011853cfa2610dbba811989ce070ce679d.png)

thanks

---

<div class="post-metadata">

### Author: ![Dave\_DeMarle](https://discourse.paraview.org/user_avatar/discourse.paraview.org/dave_demarle/32/27_2.png) [@Dave\_DeMarle](https://discourse.paraview.org/u/Dave_DeMarle)
#### Post date: [July 20, 2020, 6:10pm UTC](https://discourse.paraview.org/t/set-opacity-based-on-distance-from-camera/4814/7 "2020-07-20T18:10:17Z")

</div>

And you probably don’t need to go the full plugin route for opacity with distance.

See instead the “Use Shader Replacements” checkbox on the (advanced) display section of the properties tab. In the resulting dialog you can fill in code that gets built into vtkOpenGLPolyDataMapper’s glsl. See [https://lorensen.github.io/VTKExamples/site/Cxx/#shaders](https://lorensen.github.io/VTKExamples/site/Cxx/#shaders) for some ideas.

I am thinking that this is most likely the best path forward for you.

---

<div class="post-metadata">

### Author: ![woodscn](https://discourse.paraview.org/user_avatar/discourse.paraview.org/woodscn/32/3226_2.png) [@woodscn](https://discourse.paraview.org/u/woodscn)
#### Post date: [July 20, 2020, 6:13pm UTC](https://discourse.paraview.org/t/set-opacity-based-on-distance-from-camera/4814/8 "2020-07-20T18:13:20Z")

</div>

Sounds good. Thanks!
