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
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...
#2: Post edited
- 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
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?