<p>Image and Samplers differ in many ways. Unlike Samplers, images can only be addressed with an integer coordinate that ranges from  (0,0) to (x,y), where x and y are the width and height of the image. They support random access reads like texelFetch, and support no filtering as you're accessing raw texels. The most interesting thing with images is that they support read and write access, in Open GLES there are limitations, wherein an image may only be specified as readonly or writeonly, not both, in desktop GL though you may specify an image as read/write so that you can both read and write to that image in a single pass. </p>

<p>Using a sampler, if you wanted to write a color into it you'd have to use an FBO, then a second pass to consume that. With images, you can do this all in one pass by writing to the image and reading from it, you'd have to handle the synchronisation yourself of course.
Images are very useful for image processing etc.</p>

CC BY-SA 3.0
2016-09-12T18:28:23.067Z
2016-09-12T18:28:23.067Z
Fred Garnier
<ul>
<li>Images creation is the same as texture, but it must be binded as
image to image units. These are equivalent of "texture units".</li>
<li>With them you can arbitrarily perform read/write/modify operations
using <code>imageStore/imageLoad</code> or atomic operations at some coordinates. Unlike samplers these
coordinates are in unsigned integer range.</li>
<li>They do not need to be part of framebuffer color attachments to write
into them. This is useful and simplify some techniques like injecting
data into volume textures and is used in compute shaders. No need to use draw calls with buffer data upload.</li>
<li>There is no mipmapping or texture filtering available when doing
operation on texture binded as image.</li>
</ul>

CC BY-SA 3.0
2016-09-14T00:46:37.490Z
Is there a typo in the third bullet point? I'm guessing it should say "they do _not_ need to be part of framebuffer color attachments to write into them"?
Nathan Reed
CC BY-SA 3.0
2016-09-14T09:05:20.380Z
Yes you are right. Hmm strange, I meant the opposite - edited.
mdkdy
CC BY-SA 3.0
2016-09-12T18:24:17.537Z
2016-09-14T09:05:31.750Z
2016-09-14T09:05:31.750Z
mdkdy
<p>Unlike samplers imageLoad (Load in HLSL) requires a texel coordinate (integer). This will load the value at that location only. The range of the coordinate can be (0,0) to (image width, image height). Because only an integer can be supplied no sampling is applied to blend between multiple texels (e.g. bilinear in 2D). I'd therefore <strong>assume</strong> it is a cheaper operation.</p>

<p>Image processing algorithms such as blurs often use image load so that discrete texel values can be processed.</p>

CC BY-SA 3.0
2016-09-12T17:48:52.590Z
2016-09-12T18:22:19.587Z
2016-09-12T18:22:19.587Z
Syntac_
<p>Reading through some code about voxelization I found the following line in the fragment shader</p>

<p><code>layout (binding = 0, r32f ) coherent uniform writeonly image3D volumeTexture;</code></p>

<p>I have only used <code>samplers</code> in the past and have never seen <code>image3D</code> before. </p>

<p>I have read the entries about <a href="https://www.opengl.org/wiki/Sampler_(GLSL)" rel="noreferrer">Sampler Varibles</a> and <a href="https://www.opengl.org/wiki/Image_Load_Store#Image_variables" rel="noreferrer">Image Variables</a> but I really don't grasp the differences, advantages/disadvantages between Sampler and Image.</p>

<p>Can someone help me pointing out what are the difference between these two types of variables and when should I used one over the other?</p>

CC BY-SA 3.0
2016-09-12T18:16:56.613Z
The title refers to `Image2D` and the code and body refer to `image3D`. Does one of these need to be edited? Which one are you asking about?
trichoplax is on Codidact now
<glsl>
What is the difference between a Sampler and an Image variables in GLSL?
BRabbit27
# What is the difference between a Sampler and an Image variables in GLSL?

(Asked by: username_0 on 2016-09-12)

Reading through some code about voxelization I found the following line in the fragment shader

`layout (binding = 0, r32f ) coherent uniform writeonly image3D volumeTexture;`

I have only used `samplers` in the past and have never seen `image3D` before.

I have read the entries about [Sampler Varibles](https://www.opengl.org/wiki/Sampler_(GLSL)) and [Image Variables](https://www.opengl.org/wiki/Image_Load_Store#Image_variables) but I really don't grasp the differences, advantages/disadvantages between Sampler and Image.

Can someone help me pointing out what are the difference between these two types of variables and when should I used one over the other?

**Tags:** glsl

> **Comments:**
> **username_1**: The title refers to `Image2D` and the code and body refer to `image3D`. Does one of these need to be edited? Which one are you asking about?  

---

## 3 answers

### Answer by username_5 on 2016-09-12. Score: 4 | Accepted answer

Unlike samplers imageLoad (Load in HLSL) requires a texel coordinate (integer). This will load the value at that location only. The range of the coordinate can be (0,0) to (image width, image height). Because only an integer can be supplied no sampling is applied to blend between multiple texels (e.g. bilinear in 2D). I'd therefore **assume** it is a cheaper operation.

Image processing algorithms such as blurs often use image load so that discrete texel values can be processed.


---

### Answer by username_2 on 2016-09-12. Score: 6

Image and Samplers differ in many ways. Unlike Samplers, images can only be addressed with an integer coordinate that ranges from (0,0) to (x,y), where x and y are the width and height of the image. They support random access reads like texelFetch, and support no filtering as you're accessing raw texels. The most interesting thing with images is that they support read and write access, in Open GLES there are limitations, wherein an image may only be specified as readonly or writeonly, not both, in desktop GL though you may specify an image as read/write so that you can both read and write to that image in a single pass.

Using a sampler, if you wanted to write a color into it you'd have to use an FBO, then a second pass to consume that. With images, you can do this all in one pass by writing to the image and reading from it, you'd have to handle the synchronisation yourself of course.
Images are very useful for image processing etc.


---

### Answer by username_3 on 2016-09-12. Score: 6

* Images creation is the same as texture, but it must be binded as
  image to image units. These are equivalent of "texture units".
* With them you can arbitrarily perform read/write/modify operations
  using `imageStore/imageLoad` or atomic operations at some coordinates. Unlike samplers these
  coordinates are in unsigned integer range.
* They do not need to be part of framebuffer color attachments to write
  into them. This is useful and simplify some techniques like injecting
  data into volume textures and is used in compute shaders. No need to use draw calls with buffer data upload.
* There is no mipmapping or texture filtering available when doing
  operation on texture binded as image.

> **Comments:**
> **username_4**: Is there a typo in the third bullet point? I'm guessing it should say "they do _not_ need to be part of framebuffer color attachments to write into them"?  
> **username_3**: Yes you are right. Hmm strange, I meant the opposite - edited.  

---

