Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
HLSL-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#version 330 in vec3 positionAttribute; smooth out vec2 passUV; // Ray trough the scene from the camera // to compute view space position out of the linear depth // see http://mynameismjp.wordpress.com/2009/03/10/reconstructing-position-from-depth/ noperspective out vec3 viewRay; // 45 Degrees float tangens = tan(0.7853981625/2.0); float aspect = 1280.0 / 768.0; void main() { gl_Position = vec4(positionAttribute.xy, 0, 1); passUV = (positionAttribute.xy + 1) / 2; int index = int(positionAttribute.z); // Gets interpolated through the fragment shader // Represents a ray from the camera to the end of the scene viewRay = vec3(positionAttribute.x * tangens * aspect, positionAttribute.y * tangens, 1.0); } |
HLSL-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
#version 330 smooth in vec2 passUV; noperspective in vec3 viewRay; // Normal Map uniform sampler2D normalMap; // Linear Depth map uniform sampler2D linDepthMap; // little texture with random values uniform sampler2D noiseTex; // Projection matrix uniform mat4 projectionMatrix; uniform int kernelSize; const int MAX_KERNEL = 256; uniform vec3 kernel[MAX_KERNEL]; uniform float radius; out vec4 fragmentColor; void main() { // View space position // Computed from the depth and the view ray vec3 vs_Position = viewRay * texture(linDepthMap, passUV).r; vec3 normal = texture(normalMap, passUV).xyz; // Get texture coordinates for the noise texture // Necessary to get the texture tiled vec2 noiseTexCoords = vec2(textureSize(linDepthMap,0)) / vec2(textureSize(noiseTex,0)); noiseTexCoords *= passUV; // random rotation vector for the kernel vec3 randomVec = texture(noiseTex, noiseTexCoords).rgb * 2.0 - 1.0; // Compute orthogonal basis using the gram-schmidt process vec3 tangent = normalize(randomVec - normal * dot(randomVec, normal)); vec3 bitangent = cross(tangent,normal); mat3 rotMat = mat3(tangent, bitangent, normal); // SSAO Computation float occlusion = 0.0; for(int i=0; i<kernelSize; ++i){ // compute sample position vec3 vs_Sample = rotMat * kernel[i]; vs_Sample = vs_Sample * radius + vs_Position; // Project the sample point to screen space vec4 ss_Sample = projectionMatrix * vec4(vs_Sample, 1.0); // Divide by the homogen coord ss_Sample.xy /= ss_Sample.w; // Scale for texture access (same optimized procedure as in Deferred Shading/screenFill.vert) ss_Sample.xy = ss_Sample.xy * 0.5 + 0.5; // Get linear depth of this sample float sampleDepth = texture(linDepthMap, ss_Sample.xy).r; // Range check float rangeCheck = smoothstep(0.0, 1.0, radius / abs(vs_Position.z - sampleDepth)); // Accumulate occlusion occlusion += rangeCheck * step(sampleDepth, vs_Sample.z); } occlusion = 1.0 - (occlusion / kernelSize); fragmentColor = vec4(occlusion); } |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Die Grafikkarte von einem Kumpel hat mal die Hufe hoch gemacht, da sahen alle Spiele bei ihm so aus wie dieser Depth Buffer da
Sieht für mich aus, als hättest Du einfach ein Minuszeichen in Deinen Texturkoordinaten drin. Also sowohl horizontal als auch vertikal gespiegelt.
Werbeanzeige