DGL
https://delphigl.com/forum/

Grafikfehler mit Parallax
https://delphigl.com/forum/viewtopic.php?f=20&t=5746
Seite 1 von 1

Autor:  Finalspace [ So Jul 30, 2006 01:49 ]
Betreff des Beitrags:  Grafikfehler mit Parallax

Tach,

habe hier ein problem mit Parallax mapping und Specular bumpmapping.
Der GLSL shader sieht vom code her sauber aus, aber bringt mir mit eingeschaltetem Parallax ein komisches ergebnis:

Mit eingeschalteten Parallax mapping sieht das so aus, mit so komischen umrissen: (umrisse sind markiert)
Bild

ohne mit normalem Specular bumpmapping einwandfrei wie man sieht:
Bild



Ich denke es hängt an meiner Heightmap bzw normalmap.
Für mich sieht die aber ok aus, diese 3 texturen hab ich benutzt:

Heightmap:
Bild

Normalmap:
Bild

Diffusemap:
Bild

Die normalmap und die Heigthmap sind in einer 32Bit RGBA Bitmap gespeichert und werden über SDL_Surface via BGRA geladen.



und hier ist der Fragment Shader: (aus der humus gameengine2 demo)

Code:
  1.  
  2. // Parallax Bumpmapping shader
  3.  
  4. uniform sampler2D tex0;
  5. uniform sampler2D tex1;
  6.  
  7. uniform vec4 lightColor;
  8. uniform vec2 plxCoeffs;
  9.  
  10. uniform bool hasParallax;
  11.  
  12. varying vec2 texCoord;
  13. varying vec3 lVec;
  14. varying vec3 vVec;
  15.  
  16. float saturate( float inValue)
  17. {
  18.    return clamp(inValue, 0.0, 1.0);
  19. }
  20.  
  21. void main(){
  22.    // Calculate light intensity
  23.    float atten = saturate(1.0 - dot(lVec, lVec));
  24.  
  25.    vec3 lightVec = normalize(lVec);
  26.    vec3 viewVec = normalize(vVec);
  27.  
  28.    // Calculate parallax texcoords
  29.    vec2 plxTexCoord = texCoord;
  30.    if (hasParallax) {
  31.       float height = texture2D(tex1, texCoord).w;
  32.       float offset = height * plxCoeffs.x + plxCoeffs.y;
  33.       plxTexCoord += offset * viewVec.xy;
  34.    }
  35.  
  36.    vec4 base = texture2D(tex0, plxTexCoord);
  37.    vec3 bump = texture2D(tex1, plxTexCoord).xyz * 2.0 - 1.0;
  38.    bump = normalize(bump);
  39.  
  40.    float diffuse = saturate(dot(lightVec, bump));
  41.  
  42.    vec4 lighting = diffuse * base;  
  43.  
  44.    float specular = saturate(4.0 * dot(reflect(-viewVec, bump), lightVec) - 3.0);
  45.    specular *= specular;
  46.  
  47.    lighting += 0.6 * specular;
  48.  
  49.    gl_FragColor = lightColor * lighting * atten;
  50. }
  51.  


Wenn wer ne idee hätte was da faul ist, wärs echt super wenn mir jemand erklärt was da faul ist.
Danke,

Final

Autor:  AL [ Mo Jul 31, 2006 14:21 ]
Betreff des Beitrags: 

N bisschen mehr Code wäre ganz gut, also auch aus dem aufrufenden Prog, wie du die Geometrie machst, was du dem Shader für Parameter übergibst, ...

z.B. bei der Zeile:

Code:
  1. float offset = height * plxCoeffs.x + plxCoeffs.y;


Was für Werte verwendest du da für plxCoeffs? Es müsste sowas wie plxCoeffs.x = 0.002 und plxCoeffs.y = -0.001 sein, schätze ich.


Ansonsten Poste mal einen Screenshot ohne Bump+Specular, nur Parallax mit der Textur, dann sieht man vllt mehr.

Autor:  Finalspace [ Mo Jul 31, 2006 15:31 ]
Betreff des Beitrags: 

Und es werde Parallax ;)

Bild


Es lag an der 32Bit Texture wo aus meiner Normalmap und der Heigthmap entstand.
Habe mir nämlich nen tool gebastelt, welches Normalmaps und Heigthmaps erstellen und speichern kann, welches ich auch poste, sobald ich den bug gefunden habe :p

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