|
Post by scalion on Jan 23, 2024 15:55:34 GMT 1
Hi all,
Shaders are very powerfull
Zoom in real time with texture animation. Use + and - to add or substract iterations
Left Mouse clic zoom in, Right mouse clic zoom out !
Left + Right clic reset view.
That's all !
|
|
|
Post by Roger Cabo on Jan 23, 2024 19:27:38 GMT 1
unfortunately my screen stays complete in a single color.. nothing happens while pressing the mouse LMB||RMB||MOVE. ----- would love to add this in the same was like the shader.g32 one just for fun! No idea if its possible... int hexid; vec3 hpos, point, pt; float tcol, bcol, hitbol, hexpos, fparam=0.;
mat2 rot(float a) { // The "rot" function takes an angle "a" as input and returns a 2x2 rotation matrix. // This matrix is created using the sine and cosine of the input angle "a," allowing for a 2D rotation around the origin (0,0).
float s=sin(a),c=cos(a); return mat2(c,s,-s,c); }
vec3 path(float t) { // This function, "path," takes a parameter "t" and returns a 3D vector ("vec3"). // The vector is generated by combining sine and cosine functions applied to the input "t" in a specific way to create a path in 3D space. // It's a mathematical representation of a path with changing x, y, and z coordinates as "t" varies, which can be used for animations or simulations.
return vec3(sin(t*.3+cos(t*.2)*.5)*4.,cos(t*.2)*3.,t); }
float hexagon( in vec2 p, in float r ) { // The "hexagon" function takes a 2D point "p" and a radius "r" as input and calculates the distance of the point from the center of a hexagon with the given radius. // It uses mathematical operations to determine the distance of the point to the hexagon's edges and returns the signed distance to the hexagon.
const vec3 k = vec3(-0.866025404,0.5,0.577350269); p = abs(p); p -= 2.0*min(dot(k.xy,p),0.0)*k.xy; p -= vec2(clamp(p.x, -k.z*r, k.z*r), r); return length(p)*sign(p.y); }
float hex(vec2 p) {
// The "hex" function takes a 2D point "p" and creates a hexagonal pattern by modifying the coordinates of the point. // It scales the x-coordinate by a constant factor and shifts the y-coordinate based on the x-coordinate to create the hexagonal grid effect. // It then calculates the distance of the modified point from the hexagon's edges and returns this distance.
p.x *= 0.57735*2.0; p.y+=mod(floor(p.x),2.0)*0.5; p=abs((mod(p,1.0)-0.5)); return abs(max(p.x*1.5 + p.y, p.y*2.0) - 1.0); }
mat3 lookat(vec3 dir) { // The "lookat" function generates a 3x3 matrix to orient an object or camera to face a given direction, with a defined upward direction.
vec3 up=vec3(0.,1.,0.); vec3 rt=normalize(cross(dir,up)); return mat3(rt, cross(rt,dir), dir); }
float hash12(vec2 p) { // The "hash12" function takes a 2D vector "p" as input and generates a pseudo-random value based on it. // It multiplies the input vector by 1000, applies some mathematical operations involving fractals and dot products, // and finally returns a pseudo-random value between 0 and 1. This function is often used in procedural // generation and noise functions to create randomness or variation in computer graphics and simulations.
p*=1000.; vec3 p3 = fract(vec3(p.xyx) * .1031); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.x + p3.y) * p3.z); }
float de(vec3 p) { // The "de" function calculates the signed distance from a 3D point to a scene with hexagonal shapes and transformations, // adjusting colors based on proximity. It's likely used in rendering or raymarching.
pt=vec3(p.xy-path(p.z).xy,p.z); float h=abs(hexagon(pt.xy,3.+fparam)); hexpos=hex(pt.yz); tcol=smoothstep(.0,.15,hexpos); h-=tcol*.1; vec3 pp=p-hpos; pp=lookat(point)*pp; pp.y-=abs(sin(iTime))*3.+(fparam-(2.-fparam)); pp.yz*=rot(-iTime); float bola=length(pp)-1.; bcol=smoothstep(0.,.5,hex(pp.xy*3.)); bola-=bcol*.1; vec3 pr=p; pr.z=mod(p.z,6.)-3.; float d=min(h,bola); if (d==bola) { tcol=1.; hitbol=1.; } else { hitbol=0.; bcol=1.; } return d*.5; }
vec3 normal(vec3 p) { // The "normal" function calculates the normal vector at a 3D point in a scene by taking finite differences in three directions and normalizing the result. vec2 e=vec2(0.,.005); return normalize(vec3(de(p+e.yxx),de(p+e.xyx),de(p+e.xxy))-de(p)); }
vec3 march(vec3 from, vec3 dir) { // This is not a calendar 2024 function! // Used for raymarching in a 3D scene. It calculates the color of a ray as it travels through the scene, // considering objects, shading, reflections, and other effects, such as hexagonal patterns. vec3 odir=dir; vec3 p=from,col=vec3(0.); float d,td=0.; vec3 g=vec3(0.); for (int i=0; i<200; i++) { d=de(p); if (d<.001||td>200.) break; p+=dir*d; td+=d; g+=.1/(.1+d)*hitbol*abs(normalize(point)); } float hp=hexpos*(1.-hitbol); p-=dir*.01; vec3 n=normal(p); if (d<.001) { col=pow(max(0.,dot(-dir,n)),2.)*vec3(.6,.7,.8)*tcol*bcol; } col+=float(hexid); vec3 pr=pt; dir=reflect(dir,n); td=0.; for (int i=0; i<200; i++) { d=de(p); if (d<.001||td>200.) break; p+=dir*d; td+=d; g+=.1/(.1+d)*abs(normalize(point)); } float zz=p.z; if (d<.001) { vec3 refcol=pow(max(0.,dot(-odir,n)),2.)*vec3(.6,.7,.8)*tcol*bcol; p=pr; p=abs(.5-fract(p*.1)); float m=100.; for (int i=0; i<10; i++) { p=abs(p)/dot(p,p)-.8; m=min(m,length(p)); } col=mix(col,refcol,m)-m*.3; col+=step(.3,hp)*step(.9,fract(pr.z*.05+iTime*.5+hp*.1))*.7; col+=step(.3,hexpos)*step(.9,fract(zz*.05+iTime+hexpos*.1))*.3; } col+=g*.03; col.rb*=rot(odir.y*.5); return col; }
void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
// Calculates the color of a pixel in a 3D scene using raymarching techniques, // dynamically adjusting the scene based on time and pixel position, // resulting in a continuously evolving visual artwork.
vec2 uv = fragCoord/iResolution.xy-.5; uv.x*=iResolution.x/iResolution.y; float t=iTime*2.; vec3 from=path(t); if (mod(iTime-10.,20.)>10.) { from=path(floor(t/20.)*20.+10.); from.x+=2.; } hpos=path(t+3.); vec3 adv=path(t+2.); vec3 dir=normalize(vec3(uv,.7)); vec3 dd=normalize(adv-from); point=normalize(adv-hpos); point.xz*=rot(sin(iTime)*.2); dir=lookat(dd)*dir; vec3 col = march(from, dir); col*=vec3(1.,.9,.8); fragColor = vec4(col,1.0); }
|
|
|
Post by scalion on Jan 23, 2024 20:46:21 GMT 1
Or maybe you launched the program while the default directory not changed, that's appear when file is opened and dont saved. In this case just insert "chdir app.path" before "ShadersLoading("vertexshader2D.txt", "fragmentshader2D.txt")").
PS : If you have also the VertexShader corresponding to your FragmentShader i can try to implement it. You found it on shadertoy ? EDIT : i can do do it, some change to make but taht's work :
|
|
|
Post by (X) on Jan 23, 2024 20:57:53 GMT 1
This is an instant classic!
|
|
|
Post by scalion on Jan 24, 2024 11:42:52 GMT 1
FR : Je ne suis pas encore très familier du langage GLSL, je viens de comprendre comment déclarer des variables de type double, il suffit de préciser #version 400 dans le shader. J'ai donc amélioré le programme pour qu'on puisse zoomer plus loin. J'en ai profité pour charger les shaders dans l'onglet ":Files" comma ça plus de problème.
US : I'm not yet very familiar with the GLSL language, I just understood how to declare double type variables, just specify #version 400 in the shader. So I improved the program so that we can zoom in further. I took the opportunity to load the shaders in the ":Files" tab so that there was no more problem.
|
|
|
Post by (X) on Jan 24, 2024 12:33:20 GMT 1
Mandelbot's TED TALK (13 years ago):
|
|
|
Post by (X) on Jan 24, 2024 15:12:26 GMT 1
FR : Je ne suis pas encore très familier du langage GLSL, je viens de comprendre comment déclarer des variables de type double, il suffit de préciser #version 400 dans le shader. J'ai donc amélioré le programme pour qu'on puisse zoomer plus loin. J'en ai profité pour charger les shaders dans l'onglet ":Files" comma ça plus de problème.
US : I'm not yet very familiar with the GLSL language, I just understood how to declare double type variables, just specify #version 400 in the shader. So I improved the program so that we can zoom in further. I took the opportunity to load the shaders in the ":Files" tab so that there was no more problem.
YT Clip...
|
|
|
Post by Roger Cabo on Jan 24, 2024 15:45:51 GMT 1
|
|
|
Post by Roger Cabo on Jan 24, 2024 16:27:02 GMT 1
Or maybe you launched the program while the default directory not changed, that's appear when file is opened and dont saved. In this case just insert "chdir app.path" before "ShadersLoading("vertexshader2D.txt", "fragmentshader2D.txt")").
PS : If you have also the VertexShader corresponding to your FragmentShader i can try to implement it. You found it on shadertoy ? EDIT : i can do do it, some change to make but taht's work : View Attachment
Hmm... I'm not sure if shadertoys require to use vertex shaders at all .. because they are use basically always the screen space edges 0,0,_X-1,_Y-1 The vertext shader are the screen based edges of all sides are you use for the Mandelbrot visualization. A) These are the variables that need to be transmitted from the outside to the GPU: B) Or those that result from the refresh rate (framerate) and should be sent back to the shader. However, they are not always used and are provided only to be available. --- A) Ce sont les variables qui doivent être transmises de l'extérieur au GPU : B) Ou celles qui découlent du taux de rafraîchissement (framerate) et qui devraient être renvoyées au shader. Cependant, elles ne sont pas toujours utilisées et sont fournies uniquement pour être disponibles. uniform vec3 iResolution; // résolution du viewport (en pixels) uniform float iTime; // temps de lecture du shader (en secondes) uniform float iTimeDelta; // temps de rendu (en secondes) uniform float iFrameRate; // taux de rafraîchissement du shader uniform int iFrame; // frame de lecture du shader uniform float iChannelTime[4]; // temps de lecture des canaux (en secondes) uniform vec3 iChannelResolution[4]; // résolution des canaux (en pixels) uniform vec4 iMouse; // coordonnées de la souris en pixels. xy : actuel (si bouton de la souris pressé), zw : au clic uniform samplerXX iChannel0..3; // canal d'entrée. XX = 2D/Cube uniform vec4 iDate; // (année, mois, jour, temps en secondes) uniform float iSampleRate; // taux d'échantillonnage sonore (par exemple, 44100)
In GLSL, iResolution is defined as vec3 to allow for the inclusion of additional information. The first two components represent the width and height in pixels, while the third component (z) can be used for internal or additional data, such as the pixel aspect ratio or other information relevant to the shader. The vertex shader is solely there to define the area of the screen on which to draw (quad). The vertex shader is always a 2D shader, as described by an image shader like on ShaderToy. The Vertex Shader in this environment primarily aims to define the area for rendering in the Fragment Shader. (you like to use) --- Dans GLSL, iResolution est défini comme vec3 pour permettre l'inclusion d'informations supplémentaires. Les deux premières composantes représentent la largeur et la hauteur en pixels, tandis que la troisième composante (z) peut être utilisée pour des données internes ou supplémentaires, comme le ratio de l'aspect des pixels ou d'autres informations pertinentes pour le shader. Le vertex shader est uniquement là pour définir la zone de l'écran sur laquelle on dessine (quad). Le vertex shader est alors toujours un shader 2D, qui est décrit par un shader d'image comme sur ShaderToy. Le Vertex Shader dans cet environnement a principalement pour but de définir la zone pour le rendu dans le Fragment Shader. #version 330 core
in vec2 p; in vec3 n; in vec2 t;
out vec2 pOut; out vec3 nOut; out vec2 tOut;
uniform float _X,_Y; uniform float tm;
void main(){ gl_Position = vec4(p.x/_X-1,1-p.y/_Y,0,1.0); pOut=p; nOut=n; tOut=t;
}
--------------------------------------------------------------------------------------------------------
shadertoy vertex shader internaly:
#version 330 core
in vec2 aPos; out vec2 TexCoords;
void main() { gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);
// Send Texture coordinates to the Fragment Shader (if required) TexCoords = aPos; }
|
|
|
Post by Roger Cabo on Jan 24, 2024 18:10:28 GMT 1
FR : Je ne suis pas encore très familier du langage GLSL, je viens de comprendre comment déclarer des variables de type double, il suffit de préciser #version 400 dans le shader. J'ai donc amélioré le programme pour qu'on puisse zoomer plus loin. J'en ai profité pour charger les shaders dans l'onglet ":Files" comma ça plus de problème.
US : I'm not yet very familiar with the GLSL language, I just understood how to declare double type variables, just specify #version 400 in the shader. So I improved the program so that we can zoom in further. I took the opportunity to load the shaders in the ":Files" tab so that there was no more problem.
YT Clip... This is a great info.. not sure if we generally can use internally 64bit calculations.
|
|
|
Post by Roger Cabo on Jan 24, 2024 19:21:59 GMT 1
To create large-scale landscapes in OpenGL using 64-bit precision, you can follow these steps for GLSL versions 4.60, 4.40, or 4.30. These versions support double precision, which is crucial for rendering large distances accurately. 1. Shader VersionStart with specifying the GLSL version at the top of your shader files: glsl #version 460 // or 440, or 4302. Using 64-Bit Types in Shaders Use double precision types in your shaders for positions and transformations: glsl uniform dmat4 modelMatrix; uniform dmat4 viewMatrix; uniform dmat4 projectionMatrix; in dvec3 position;3. Camera Movement and Matrix CalculationsPerform the calculation of the model, view, and projection matrices on the CPU side and pass them to the shaders. For camera movement and inversion translation, calculate these using double precision on the CPU and then upload the results to the GPU.
4. Sending 64-Bit Data to ShadersUse OpenGL functions to send double data to shaders. For matrices, use glUniformMatrix4dv: glUniformMatrix4dv(modelMatrixLocation, 1, GL_FALSE, &modelMatrix[0][0]); glUniformMatrix4dv(viewMatrixLocation, 1, GL_FALSE, &viewMatrix[0][0]); glUniformMatrix4dv(projectionMatrixLocation, 1, GL_FALSE, &projectionMatrix[0][0]);5. Rendering the SceneIn your rendering loop, ensure that the vertex data (using double precision) is correctly bound and draw your scene normally. The shaders will handle the vertex transformations with high precision. Concerning the Fixed-Function Pipeline Functions The fixed-function pipeline functions you mentioned (glRotated, glTranslated, glScaled, gluLookAtd, gluPerspectived, glVertex3d, etc.) are part of the older OpenGL functionality and are not typically used in modern OpenGL programming with shaders. These functions don't support double precision directly in the way shaders do. Modern practice is to calculate all necessary transformations and matrices on the CPU (using double precision as needed) and then pass these matrices to the shaders for rendering. Question: Interfacing with GFA-Basic32?In GFA-Basic32, if it supports calling OpenGL functions, you should be able to use functions like glUniform1dv through standard calls. For instance: ~StdCall(A_glUniform1dv)(location, 1, V:v1d)This would be the way to upload double values to the shaders. However, the specifics depend on how GFA-Basic32 interfaces with external libraries like $Library "OpenGL.inc" ?By using GLSL 4.30 or higher, you can leverage double precision for rendering large landscapes. The key is to handle all high-precision calculations (like transformations and camera movements) in double and pass these values to your shaders. Avoid relying on the older fixed-function pipeline for these tasks in modern OpenGL applications. I have none acknowledge about the "OpenGL.inc" file type and what it really does in terms ob 32 and 64bit calls. Would be great if someone explain some of this possible 64bit possibilities? Thanks a lot!
|
|
|
Post by scalion on Jan 24, 2024 21:32:04 GMT 1
Depuis la version 1.1 les nouvelles fonctions sont considérées comme des extensions et ne sont pas exportée par la DLL. Pour utiliser une nouvelle fonction il faut donc appeler wglGetProcAddress() qui renvoie l'adresse en mémoire.
Exemple : A_glUniform1dv = wglGetProcAddress("glUniform1dv")
Ensuite on peut utiliser ~StdCall(A_glUniform1dv)(location, 1, V:v1d)
La librarie "OpenGL.inc.lg32" ne fournit que les fonctions exportées, pas les extensions. Elle contient donc uniquement les déclarations classiques. Exemple : Declare Sub glVertex2d Lib "opengl32.dll" (ByVal x#, ByVal y#)
Ceci dit il est certainement possible de créer une bibliothèque GFA-Basic 32 d'importation (dans la même veine que GLEW qui fait cela). La bibliothèque Direct2D utilise ce principe avecl'api GetProcAddress() et cela fonctionne. Je vais me pencher la dessus.
En conclusion "OpenGL.inc" gère les fonctions 64 bits de bases telles que glVertex2d() par exemple. Mais tu peux aussi jeter un oeil dans le fichier source de cette bibliothèque que tu trouveras dans "C:\Program Files (x86)\GFABASIC32\Include".
US : Since version 1.1 new functions are considered extensions and are not exported by the DLL. To use a new function you must therefore call wglGetProcAddress() which returns the address in memory.
Example: A_glUniform1dv = wglGetProcAddress("glUniform1dv")
Then we can use ~StdCall(A_glUniform1dv)(location, 1, V:v1d)
The "OpenGL.inc.lg32" library only provides the exported functions, not the extensions. It therefore only contains the classic declarations. Example: Declare Sub glVertex2d Lib "opengl32.dll" (ByVal x#, ByVal y#)
That said it is certainly possible to create a GFA-Basic 32 import library (in the same vein as GLEW which does this). The Direct2D library uses this principle with the GetProcAddress() API and it works. I'm going to look into it.
In conclusion "OpenGL.inc" manages basic 64-bit functions such as glVertex2d() for example. But you can also take a look in the source file of this library which you will find in "C:\Program Files (x86)\GFABASIC32\Include".
|
|
|
Post by (X) on Jan 25, 2024 11:20:25 GMT 1
ENG
I asked BING where the 'new' functions are located? Which file? The answer is "In the video graphic card manufacturer's drivers" FR
J'ai demandé à BING où se trouvaient les "nouvelles" fonctions ? Dans quel fichier ? La réponse est "Dans les pilotes du fabricant de la carte graphique vidéo"
GER
Ich habe BING gefragt, wo die "neuen" Funktionen zu finden sind? In welcher Datei? Die Antwort lautet: "In den Treibern des Grafikkartenherstellers".
|
|