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
Found a workaround: Instead of doing the calculating in the vertex shader, do it in the fragment shader. The precision error only occurs because the different vertexes have a uv value that is clos...
Answer
#2: Post edited
- Found a workaround: Instead of doing the calculating in the vertex shader, do it in the fragment shader.
- The precision error only occurs because the different vertexes have a `uv` value that is close together relative to the absolute value of `uv`. Which causes multiple fragments to have the same `uv` coordinates which causes this artefacts. By passing `uv` directly, with coordinates that only have the values `-1` `1`, each fragment shader instance gets its own `uv` value that is different from the others. The calculation inside the fragment shader can be done with double precision.
- The good thing is, the main program can pass `double` values, when the correct extensions are supported.
- The new fragment shader:
- ```
- #version 400
- //Moved zoom from the vertex shader. This is set by the main program.
- // with glUniformMatrix3dv()
- uniform dmat3 zoom;
- //uv values are not transformed.
- in vec2 uv;
- ...
- void main()
- {
- dvec2 uv_double = uv;
- uv_double = ( zoom * dvec3(uv_double,1)).xy ;
- //us uv_double from here on and not uv
- ...
- }
- ```
Disadvantage is that `glUniformMatrix3dv()` has to be supported and a other very minor disadvantage is that this is probably slower.
- Found a workaround: Instead of doing the calculating in the vertex shader, do it in the fragment shader.
- The precision error only occurs because the different vertexes have a `uv` value that is close together relative to the absolute value of `uv`. Which causes multiple fragments to have the same `uv` coordinates which causes this artefacts. By passing `uv` directly, with coordinates that only have the values `-1` `1`, each fragment shader instance gets its own `uv` value that is different from the others. The calculation inside the fragment shader can be done with double precision.
- The good thing is, the main program can pass `double` values, when the correct extensions are supported.
- The new fragment shader:
- ```
- #version 400
- //Moved zoom from the vertex shader. This is set by the main program.
- // with glUniformMatrix3dv()
- uniform dmat3 zoom;
- //uv values are not transformed.
- in vec2 uv;
- ...
- void main()
- {
- dvec2 uv_double = uv;
- uv_double = ( zoom * dvec3(uv_double,1)).xy ;
- //us uv_double from here on and not uv
- ...
- }
- ```
- Disadvantage is that `glUniformMatrix3dv()` is an extension any may not be supported everywhere. A other very minor disadvantage is that this is probably slower.
#1: Initial revision
Found a workaround: Instead of doing the calculating in the vertex shader, do it in the fragment shader. The precision error only occurs because the different vertexes have a `uv` value that is close together relative to the absolute value of `uv`. Which causes multiple fragments to have the same `uv` coordinates which causes this artefacts. By passing `uv` directly, with coordinates that only have the values `-1` `1`, each fragment shader instance gets its own `uv` value that is different from the others. The calculation inside the fragment shader can be done with double precision. The good thing is, the main program can pass `double` values, when the correct extensions are supported. The new fragment shader: ``` #version 400 //Moved zoom from the vertex shader. This is set by the main program. // with glUniformMatrix3dv() uniform dmat3 zoom; //uv values are not transformed. in vec2 uv; ... void main() { dvec2 uv_double = uv; uv_double = ( zoom * dvec3(uv_double,1)).xy ; //us uv_double from here on and not uv ... } ``` Disadvantage is that `glUniformMatrix3dv()` has to be supported and a other very minor disadvantage is that this is probably slower.