Du bist nicht angemeldet.

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

FSA

Community-Fossil

  • »FSA« ist der Autor dieses Themas
  • Private Nachricht senden

1

13.07.2013, 00:44

SSAO Problem

Entschuldigt den Doppelpost...

Ich habe ein Problem mit meinem SSAO Shader. Ich rendere folgendermaßen:
In einem Renderpass rendere ich Normalen und Position im Viewsapce mit MRT.
Als nächstes rendere ich die SSAO Map
Dann rendere ich die Szene ganz normal in den BackBuffer
Mit StretchRect kopiere ich den BackBuffer in eine Textur, welche ich auf ein Fullscreenquad rendere und mit der SSAO Map kombiniere.

Das Ergebnis seht ihr im Anhang (unten rechts Normalen und Position in ViewSpace).

Das Problem ist jetzt, dass ich in der SSAO Map vier schwarze Rechtecke habe, beziehungsweise ein weißes Kreuz in der Mitte, welches ungefähr auf die Positions Map passt. Ich weiß nicht woher sie kommen / es kommt. Der SSAO Shader:

C-/C++-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
77
78
79
80
81
82
83
84
85
86
87
88
89
float random_size = 64.0f;
float g_sample_rad = 1.0f/10.0f;
float g_intensity = 3.0f;
float g_scale = 1.0f;
float g_bias = 0.1f;
float2 g_screen_size = float2(800.0f,600.0f);

float3 getPosition(in float2 uv)
{
    return tex2D(posMap,uv).xyz;
}

float3 getNormal(in float2 uv)
{
    return tex2D(normalMap, uv).xyz;
}

float2 getRandom(in float2 uv)
{
    return normalize(tex2D(RandomVecSampler, g_screen_size * uv / random_size).xy * 2.0f - 1.0f);
}

float doAmbientOcclusion(in float2 tcoord,in float2 uv, in float3 p, in float3 cnorm)
{
    float3 diff = getPosition(tcoord + uv) - p;
    const float3 v = normalize(diff);
    const float d = length(diff)*g_scale;
    return max(0.0,dot(cnorm,v)-g_bias)*(1.0/(1.0+d))*g_intensity;
}

float4 PS_SSAO(in float2 texCoord : TEXCOORD0) : COLOR0
{
    const float2 vec[4] = 
        {float2(1,0),
        float2(-1,0),
        float2(0,1),
        float2(0,-1)};

    float3 p = getPosition(texCoord);
    float3 n = getNormal(texCoord);
    float2 rand = getRandom(texCoord);

    float ao = 0.0f;
    float rad = g_sample_rad/p.z;

    //**SSAO Calculation**//
    int iterations = 4;
    for (int j = 0; j < iterations; j++)
    {
        float2 coord1 = reflect(vec[j],rand)*rad;
        float2 coord2 = float2(coord1.x*0.707 - coord1.y*0.707,
        coord1.x*0.707 + coord1.y*0.707);
  
        ao += doAmbientOcclusion(texCoord,coord1*0.25, p, n);
        ao += doAmbientOcclusion(texCoord,coord2*0.5, p, n);
        ao += doAmbientOcclusion(texCoord,coord1*0.75, p, n);
        ao += doAmbientOcclusion(texCoord,coord2, p, n);
    }
    ao/=(float)iterations*4.0;
    //**END**//

    return ao;
}

VS_OUTPUT VS_Model(VS_INPUT IN)
{
    VS_OUTPUT OUT;

    OUT.position = mul(float4(IN.position.xyz, 1.0f), g_WorldViewProjectionMatrix);
    OUT.texCoord = IN.texCoord;

    return OUT;
}

float4 PS_Model(VS_OUTPUT IN) : COLOR0
{
    float4 color;
    color = tex2D(colorMap, IN.texCoord);

    return color;
}

float4 PS_PostProcess(in float2 texCoord : TEXCOORD0) : COLOR0
{
    float4 color;
    color = tex2D(PPMap, texCoord) * (tex2D(SSAOMap, texCoord));

    return color;
}

Natürlich setze ich auch die Normalen Map und Positions Map als Textur.

Hier der Shader, um die zwei oben genannten Maps zu rendern:

C-/C++-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
struct PS_OUT
{
    float4 pos : COLOR0;
    float4 norm: COLOR1;
};

VS_OUTPUT_ND VS_PosNorm(VS_INPUT IN)
{
    VS_OUTPUT_ND OUT;

    OUT.position = mul(float4(IN.position.xyz, 1.0f), g_WorldViewProjectionMatrix);
    OUT.posv = mul(float4(IN.position.xyz, 1.0f), g_WorldViewMatrix).xyz;
    OUT.normv = mul(IN.normal.xyz, (float3x3)g_WorldViewMatrix).xyz;

    return OUT;
}

PS_OUT PS_PosNorm(VS_OUTPUT_ND IN)
{
    PS_OUT o;
    o.pos = float4(IN.posv.x, IN.posv.y, IN.posv.z, 1.0f);

    float3 n = 0.5f * normalize(IN.normv) + 0.5f;
    //float3 n = normalize(IN.normv);

    o.norm = float4(n.x, n.y, n.z, 1.0f);

    return o;
}


Ich habe mittlerweile alles probiert und komme nicht weiter. Vielen danke im Voraus. :)
»FSA« hat folgendes Bild angehängt:
  • Screen.JPG

Zitat

Der RCCSWU (RandomCamelCaseSomtimesWithUndersquare) Stil bricht auch mal mit den veraltet strukturierten Denkmustern und erlaubt dem Entwickler seine Kreativität zu entfalten.

David_pb

Community-Fossil

Beiträge: 3 886

Beruf: 3D Graphics Programmer

  • Private Nachricht senden

2

14.07.2013, 11:49

Ist es eigentlich Absicht/gewollt, dass du die Normale nicht mehr entpackst?
@D13_Dreinig

FSA

Community-Fossil

  • »FSA« ist der Autor dieses Themas
  • Private Nachricht senden

3

14.07.2013, 22:15

Nein das ist nicht Absicht. Das war ein Fehler. Der andere war, dass Normalen und Position im Viewspace vorliegen. Ich habe sie nun im Worldspace transformiert. Jetzt funktioniert es. :)
Danke.

Zitat

Der RCCSWU (RandomCamelCaseSomtimesWithUndersquare) Stil bricht auch mal mit den veraltet strukturierten Denkmustern und erlaubt dem Entwickler seine Kreativität zu entfalten.

Werbeanzeige