Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

71%
+3 −0
Q&A OpenGL: Pass a double vector from vertex shader to fragment shader

TL;DR: How to pass a interpolated double vector, such as a dvec2, from the vertex shader to the fragment shader? I have a vertex shader. In this the output variable out vec2 uv; is set. And i have...

1 answer  ·  posted 9mo ago by H_H‭  ·  last activity 9mo ago by H_H‭

Question glsl OpenGL
#2: Post edited by user avatar H_H‭ · 2023-08-22T16:48:53Z (9 months ago)
Add description and image to explain why `float` isn't precise enough.
  • TL;DR: How to pass a interpolated `double` vector, such as a `dvec2`, from the vertex shader to the fragment shader?
  • I have a vertex shader. In this the output variable `out vec2 uv;` is set. And i have a fragment shader, in this the (intperpolated) input variable `in vec2 uv;` is expected. This works, and the relevant shader parts looks like this:
  • Vertex shader:
  • ```
  • #version 400
  • out vec2 uv;
  • ...
  • void main()
  • {
  • uv = calculateUv();
  • ...
  • }
  • ```
  • Fragment shader:
  • ```
  • #version 400
  • in vec2 uv;
  • ...
  • void main()
  • {
  • doSomething(uv);
  • ...
  • }
  • ```
  • However, this uses only `float` or 32 bit precision. When i change it to `double` precision, by using `dvec2` instead of `vec2`, it no longer works and i get a
  • > error C7570: 64 bit input 'uv' should be flat
  • error. I can set `uv` to `flat`, but then it is no longer interpolated and it doesn't work as expected (the `uv` value is the same for all `fragments` on a face, which is not what i want). Non-working shaders:
  • Vertex shader:
  • ```
  • #version 400
  • out dvec2 uv;
  • ...
  • void main()
  • {
  • uv = calculateUv();
  • ...
  • }
  • ```
  • Fragment shader:
  • ```
  • #version 400
  • in dvec2 uv;
  • ...
  • void main()
  • {
  • doSomething(uv);
  • ...
  • }
  • ```
  • It isn't a problem of not accepting double in general, inside the shader i can use `double` based types such `dvec2` without any problem as long as i don't want to pass it to a other shader.
  • Any idea how to pass a `dvec2`? Or any workaround?
  • TL;DR: How to pass a interpolated `double` vector, such as a `dvec2`, from the vertex shader to the fragment shader?
  • I have a vertex shader. In this the output variable `out vec2 uv;` is set. And i have a fragment shader, in this the (intperpolated) input variable `in vec2 uv;` is expected. This works, and the relevant shader parts looks like this:
  • Vertex shader:
  • ```
  • #version 400
  • out vec2 uv;
  • ...
  • void main()
  • {
  • uv = calculateUv();
  • ...
  • }
  • ```
  • Fragment shader:
  • ```
  • #version 400
  • in vec2 uv;
  • ...
  • void main()
  • {
  • doSomething(uv);
  • ...
  • }
  • ```
  • However, this uses only `float` or 32 bit precision. When i change it to `double` precision, by using `dvec2` instead of `vec2`, it no longer works and i get a
  • > error C7570: 64 bit input 'uv' should be flat
  • error. I can set `uv` to `flat`, but then it is no longer interpolated and it doesn't work as expected (the `uv` value is the same for all `fragments` on a face, which is not what i want). Non-working shaders:
  • Vertex shader:
  • ```
  • #version 400
  • out dvec2 uv;
  • ...
  • void main()
  • {
  • uv = calculateUv();
  • ...
  • }
  • ```
  • Fragment shader:
  • ```
  • #version 400
  • in dvec2 uv;
  • ...
  • void main()
  • {
  • doSomething(uv);
  • ...
  • }
  • ```
  • It isn't a problem of not accepting double in general, inside the shader i can use `double` based types such `dvec2` without any problem as long as i don't want to pass it to a other shader.
  • Why `double` precession is needed: I draw a fractal and want to zoom. This is possible by changing the `uv`-coordinates but at a high zoom level, there are big artefacts from big, pixel-like, regions on the screen having the same `uv` value.![artefacts](https://software.codidact.com/uploads/lw5jy3pkcta336xi14ehwhshuris)
  • Any idea how to pass a `dvec2`? Or any workaround?
#1: Initial revision by user avatar H_H‭ · 2023-08-22T16:37:55Z (9 months ago)
OpenGL: Pass a double vector from vertex shader to fragment shader
TL;DR: How to pass a interpolated `double` vector, such as a `dvec2`, from the vertex shader to the fragment shader?

I have a vertex shader. In this the output variable `out vec2 uv;` is set. And i have a fragment shader, in this the (intperpolated) input variable `in vec2 uv;` is expected. This works, and the relevant shader parts looks like this:

Vertex shader:
```
#version 400

out vec2 uv;

...

void main()
{
  uv = calculateUv();
  ...
}

```

Fragment shader:
```
#version 400

in vec2 uv;

...

void main()
{
  doSomething(uv);
  ...
}

```

However, this uses only `float` or 32 bit precision. When i change it to `double` precision, by using `dvec2` instead of `vec2`, it no longer works and i get a 

> error C7570: 64 bit input 'uv' should be flat


 error. I can set `uv` to `flat`, but then it is no longer interpolated and it doesn't work as expected (the `uv` value is the same for all `fragments` on a face, which is not what i want). Non-working shaders:

Vertex shader:
```
#version 400

out dvec2 uv;

...

void main()
{
  uv = calculateUv();
  ...
}

```

Fragment shader:
```
#version 400

in dvec2 uv;

...

void main()
{
  doSomething(uv);
  ...
}

```

It isn't a problem of not accepting double in general, inside the shader i can use `double` based types such `dvec2` without any problem as long as i don't want to pass it to a other shader.

Any idea how to pass a `dvec2`? Or any workaround?