DGL
https://delphigl.com/forum/

Functionen - Rückgabewert
https://delphigl.com/forum/viewtopic.php?f=20&t=11104
Seite 1 von 1

Autor:  mathias [ Mi Jan 22, 2014 17:20 ]
Betreff des Beitrags:  Functionen - Rückgabewert

Wieso funktioniert die unterste Zeile nicht ?

Die Function diffuse gibt einen float zurück, bei den auskommentierten Zeilen ist diffuse auch ein float und hier funktioniert es.
Code:
  1. #version 330
  2.  
  3. in vec2 UV;
  4.  
  5. in vec3 Pos;
  6. in vec3 Normal;
  7.  
  8. out vec4 FragColor;
  9.  
  10. uniform sampler2D myTextureSampler;
  11.  
  12. vec3 LightPosition = vec3(-1.0, 0.4, -1.1);
  13. float UmgebungsLicht = 0.3;
  14.  
  15. float diffuse()
  16. {
  17.   LightPosition = (LightPosition * -1.0) - Pos ;
  18.   float distance = length(LightPosition);
  19.   float dif = max(dot(Normal, LightPosition), UmgebungsLicht);
  20.   return dif * (1.0 / (1.0 + (0.25 * distance * distance)));
  21. }
  22.  
  23. void main()
  24. {
  25. //  LightPosition = (LightPosition * -1.0) - Pos ;
  26. //  float distance = length(LightPosition);
  27. //  float diffuse = max(dot(Normal, LightPosition), UmgebungsLicht);
  28. //  diffuse = diffuse * (1.0 / (1.0 + (0.25 * distance * distance)));
  29.  
  30.   FragColor = texture( myTextureSampler, UV ) * diffuse;
  31. }


Fehlermeldung:
Code:
  1. ERROR: 0:33: '*' :  wrong operand types  no operation '*' exists that takes a left-hand operand of type '4-component vector of float' and a right operand of type 'void' (or there is no acceptable conversion)

Autor:  glAwesome [ Mi Jan 22, 2014 17:30 ]
Betreff des Beitrags:  Re: Functionen - Rückgabewert

Weil du bei einem Funktionsaufruf immer Klammern setzen musst - auch wenn keine Parameter drin stehen. GLSL ist ja an C angelehnt und nicht an Pascal. :)

Autor:  mathias [ Mi Jan 22, 2014 17:54 ]
Betreff des Beitrags:  Re: Functionen - Rückgabewert

Stimmt, C braucht Klammern. Nur bei der Fehlermeldung stand nirgends was von Klammern.

Danke!

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/