Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Di Jul 15, 2025 21:01

Foren-Übersicht » Programmierung » Shader
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 4 Beiträge ] 
Autor Nachricht
BeitragVerfasst: Mo Apr 06, 2009 11:14 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
Hello,

My shader knowledge is bit rusty to say at least. So i could use some help.

I have an triangulated 2d shape. I can apply (angled) gradient fills on that as long as it is evenly triangulated. If not thing go look strange.
E.g. take a look at the circle in my glvg project: http://thuis.vanderhoning.net/svn_glvg/trunk/
So either i tesselate that in a better way (giving way more tringles). Still circular gradients will be hard (maybe even impossible) to apply.

Or:

Could i use shaders to apply gradient fills. Vertex shaders would not do as the same as above aplies to them i think.
So it should be fragment shaders. (most graphics card should handle these by now i hope).

1) What kind of shader should i use glsl or some low level arb fp1.0 shader?
But more importantly how does color calculation work in a fragment shader do i have x,y and are these relative to the screen? How would i relate that the 2d shape being rendered?
2) Also how do i pass the both colors to the fragment shader?

Thanks for your answers in advance.

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Apr 06, 2009 11:56 
Offline
DGL Member
Benutzeravatar

Registriert: Do Sep 02, 2004 19:42
Beiträge: 4158
Programmiersprache: FreePascal, C++
Since you are able to understand written german, I would at first recommend to take a look at Tutorial_glsl. There you find a (nearly) complete reference about the commands and syntax of a glsl shader.

Now... To the coordinates: In the fragment shader you can get both Viewport-relative and "3d-space" coordinates. The first ones are always available via gl_FragCoord (see wiki article).
For "3d-space" coords you have to declare a variant and fill it in the vertex shader:
Code:
  1.  
  2. varying vec4 pos;
  3. void main(void)
  4. {
  5.   // tell opengl the transformed position of the vertex
  6.   // gl_Vertex is the vector you set using glVertexXx
  7.   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  8.   // hand the position over to the fragment shader via a varying variable
  9.   pos = gl_Vertex;
  10.   // dont know about this line, I think this declares the color value you
  11.   // get in the fragment shader, just as if you handed it over to it
  12.   // via a varying variable
  13.   // gl_Color is the color you set using glColorXx
  14.   gl_FrontColor = gl_Color;
  15. }
  16.  

And you can use this now in the fragment shader like this:
Code:
  1.  
  2. varying vec4 pos;
  3. void main(void)
  4. {
  5.   // since varyings are interpolated for the fragments based on
  6.   // what you assigned to them in the vertex shader, you get the
  7.   // 3d-space fragment position here in pos.
  8.   // now you could use this for anything you want...
  9. }
  10.  

If you need the translated vertex position (i.e. with matrix operations applied to it, you just have to write a multiplication with gl_ModelViewProjectionMatrix or just gl_ModelViewMatrix (depending on what you need) in front of the gl_Vertex when assigning the value to pos in the vertex shader.

I hope this helped, if not, just ask again :)

greetings
Lord Horazont

_________________
If you find any deadlinks, please send me a notification – Wenn du tote Links findest, sende mir eine Benachrichtigung.
current projects: ManiacLab; aioxmpp
zombofant networkmy photostream
„Writing code is like writing poetry“ - source unknown


„Give a man a fish, and you feed him for a day. Teach a man to fish and you feed him for a lifetime. “ ~ A Chinese Proverb


Zuletzt geändert von Lord Horazont am Mo Apr 06, 2009 12:04, insgesamt 1-mal geändert.

Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Apr 06, 2009 11:59 
Offline
DGL Member
Benutzeravatar

Registriert: Do Dez 29, 2005 12:28
Beiträge: 2249
Wohnort: Düsseldorf
Programmiersprache: C++, C#, Java
Zitat:
1) What kind of shader should i use glsl or some low level arb fp1.0 shader?
But more importantly how does color calculation work in a fragment shader do i have x,y and are these relative to the screen? How would i relate that the 2d shape being rendered?

You should use GLSL. Even my old ATI Radeon 9800Pro was able to handle that.

I think the GLSL tutorial is a good start. The fragmentshader is executed for each fragment (pixel) you render. Colors work simply be assigning a color to gl_FragColor.
In fragment shader you can access window coords of the current fragment using gl_FragCoord.xy. In case you need the window size, you will need to use an uniform variable for that. If you require world coordinates for your computation, you can use a varying from the vertexshader.

Zitat:
2) Also how do i pass the both colors to the fragment shader?

You could either use vertex attributes (simply store colors in texture coords) or use uniform variables. The third way would be a texture. You can do arbitrary texture accesses in shaders, so you can use an texture as array.

Edit:
@Lord Horazont: variant => varying ??

_________________
Yeah! :mrgreen:


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Apr 06, 2009 12:04 
Offline
DGL Member
Benutzeravatar

Registriert: Do Sep 02, 2004 19:42
Beiträge: 4158
Programmiersprache: FreePascal, C++
@Coolcat: Oh ja, das hab ich wohl falsch in erinnerung gehabt, ich habs mal schnell korrigiert. Danke für den Hinweis.

Gruß Lord Horazont

_________________
If you find any deadlinks, please send me a notification – Wenn du tote Links findest, sende mir eine Benachrichtigung.
current projects: ManiacLab; aioxmpp
zombofant networkmy photostream
„Writing code is like writing poetry“ - source unknown


„Give a man a fish, and you feed him for a day. Teach a man to fish and you feed him for a lifetime. “ ~ A Chinese Proverb


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 4 Beiträge ] 
Foren-Übersicht » Programmierung » Shader


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 4 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.008s | 16 Queries | GZIP : On ]