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

21

22.11.2010, 21:19

Ich meine, andere DX11-Apps laufen hier ja auch prima, ohne diese verrückten sub-nummerierten DX-DLLs

Die verwenden die auch. Nur das die meisten (praktisch alle komemrziellen) DX11-Apps nen Installer haben, der deren vorhandensein prüft, udn ggf. die DX-Redist ausführt.
Allerdings mit dem unterschied, das die in der regel auch nur von einer SDK-Version, also einer D3DX-DLL abhängen...

BlazeX

Alter Hase

  • »BlazeX« ist der Autor dieses Themas

Beiträge: 478

Wohnort: DD

Beruf: Maschinenbau-Student

  • Private Nachricht senden

22

23.11.2010, 15:09

Abgesehen von missgeborenen Abhängigkeiten, hab ich den Shader mitlerweile verbessert.
Langsam verstehe ich, wie er funktioniert.

Hier die neue jetzt besser funktionierende Version:

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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//////////////////////////////////////////////////////////////////
//POM Shader

//////////////////////////////////////////////////////////////////
//Includes
#include"Constants.fx"
#include"Sampler.fx"
#include"Textures.fx"
#include"Lighting.fx"


//////////////////////////////////////////////////////////////////
//Layout
struct VSInput
{
    uint IID                    : SV_InstanceID;  //ID der Model-Instanz
    float3 vPosition            : POSITION0;      //Vertexposition im ModelSpace
    float3 vNormal              : NORMAL0;        //Vertexnormale im ModelSpace
    float3 vTangent             : TANGENT0;       //Vertextangente im ModelSpace
    float2 vTextureCoord        : TEXCOORD0;      //Vertex-Texturkoordinaten
};

struct PSInput
{
    uint IID                    : INSTANCEID;     //ID der Model-Instanz
    float4 vPosition            : SV_Position;    //Fertig transformierte Pixelposition
    float3 vWorldPosition       : POSITION0;      //Position des Pixels im WorldSpace
    float3 vViewDir             : VIEWDIR0;       //Normalisierter Vektor von Kamera in Richtung des Pixels im WorldSpace
    float3 vNormal              : NORMAL0;        //Normale des Pixels im WorldSpace
    float3 vTangent             : TANGENT0;       //Tangente des Pixels im WorldSpace
    float3 vBinormal            : BINORMAL0;      //Binormale des Pixels im WorldSpace
    float2 vTextureCoord        : TEXCOORD0;      //Texturkoordinaten des Pixels

    //#
    float2 vParallaxOffsetTS    : PAROFFSETTS0;   //Parallaxe im TangentSpace
    float3 vViewDirTS           : VIEWDIRTS0;     //Normalisierter Vektor von Kamera in Richtung des Pixels im TangentSpace
    float3 vNormalTS            : NORMALTS0;      //Normale des Pixels im TangentSpace
    //#
};

struct PSOutput
{
    float4 Color                : SV_Target0;     //Fertig berechnete Farbe des Pixels
};

//VertexShader
PSInput VertexShaderProc(VSInput In)
{
    PSInput Out;
    
    Out.IID= In.IID;
    
    float4 vWorldPosition= mul(float4(In.vPosition, 1.0), Instance[In.IID].mWorld);
    Out.vPosition= mul(vWorldPosition, mViewProjection);
    
    Out.vWorldPosition= vWorldPosition.xyz;
    Out.vViewDir= normalize(Out.vWorldPosition - vCameraPosition);
    float3 vNormal= mul(In.vNormal, (float3x3)Instance[In.IID].mWorld);
    Out.vNormal= vNormal;
    
    Out.vTangent= mul(In.vTangent, (float3x3)Instance[In.IID].mWorld);
    Out.vBinormal= cross(Out.vNormal, Out.vTangent);
    
    Out.vTextureCoord= In.vTextureCoord;

    //#
    row_major float3x3 mTBN= {Out.vTangent, Out.vBinormal, Out.vNormal};
    Out.vViewDirTS= mul(mTBN, -Out.vViewDir);
    Out.vNormalTS= mul(mTBN, Out.vNormal);

    float fParallaxLimit= length(Out.vViewDirTS.xy) / Out.vViewDirTS.z;
    const float fHeightMapScale= 0.2;
    fParallaxLimit*= fHeightMapScale;

    Out.vParallaxOffsetTS= normalize(-Out.vViewDirTS.xy) * fParallaxLimit;
    //#
    
    return(Out);
}

//PixelShader
PSOutput PixelShaderProc(PSInput In)
{
    PSOutput Out;

    //#
    //Parallax Occlusion Mapping
    //Samples berechnen
    const uint nMinSamples= 16;
    const uint nMaxSamples= 128;
    uint nNumPOMSamples = (uint)lerp(nMinSamples, nMaxSamples, normalize(In.vViewDirTS).z);

    //Steps berechnen und Offset
    float fStepSize    = 1.0 / (float)nNumPOMSamples;
    float2 vOffsetStep = fStepSize * In.vParallaxOffsetTS;
    float2 vCurrOffset = float2(0, 0);
    float2 vLastOffset = float2(0, 0);
    float2 vFinalOffset= float2(0, 0);

    float4 vCurrSample;
    float4 vLastSample;
    float stepHeight = 1.0;
    float Ua= 0.0F;

    //Anstieg vorberechnen
    float2 dx= ddx(In.vTextureCoord);
    float2 dy= ddy(In.vTextureCoord);

    //Sampeln, um den Durchstoßpunkt zu finden
    for(uint nCurrSample= 0; nCurrSample < nNumPOMSamples; nCurrSample++)
    {
        vCurrSample = TexNormalHeight.SampleGrad( TextureSamplerWrap, In.vTextureCoord + vCurrOffset, dx, dy );
        if ( vCurrSample.a > stepHeight )
        {
            //Gefunden!
            //Noch schnell den Schnittpunkt der 2 Geraden (HöheAlt-HöheNeu) x (StepAlt-StepNeu) finden
            // HöheNeu    StepAlt
            //         \/
            // StepNeu /\ HöheAlt
            //Damit sieht das glatter aus.
            Ua= (vLastSample.a - (stepHeight+fStepSize)) / ( fStepSize + (vCurrSample.a - vLastSample.a));
            vFinalOffset = vLastOffset - Ua * vOffsetStep ;

            vCurrSample = TexNormalHeight.SampleGrad( TextureSamplerWrap, In.vTextureCoord + vFinalOffset, dx, dy );
            nCurrSample = nNumPOMSamples;
        }
        else
        {
            //Beim nächsten mal klappta bestimmt!
            stepHeight -= fStepSize;
            vLastOffset = vCurrOffset;
            vCurrOffset += vOffsetStep;
            vLastSample = vCurrSample;
        }
    }

    In.vTextureCoord+= vFinalOffset;
    //#
    
    //NormalMapping
    row_major float3x3 mTBN= {In.vTangent, In.vBinormal, In.vNormal};
    float3 vNormal= normalize(mul(TexNormalHeight.Sample(TextureSamplerWrap, In.vTextureCoord).rgb * 2.0 - 1.0, mTBN));
    
    //Illumination
    float3 DiffuseLight= float3(0, 0, 0);
    float3 SpecularLight= float3(0, 0, 0);
    LightSource Light;
    uint LightIndex;

    //Light #0 (Directional)
    LightIndex= Instance[In.IID].aLightIndices[0].LID;
    if(LightIndex != 0xFFFFFFFF)
    {
        Light= aLights[LightIndex];
        DiffuseLight+= DirectionalLightDiffuse(Light, vNormal);
        SpecularLight+= DirectionalLightSpecular(Light, vNormal, MatSpecularColorPower.a, In.vViewDir);
    }
    //Color-Sources
    float4 ColorAlpha= MatColorAlpha;
    float4 SpecularColorPower= MatSpecularColorPower;
    float4 EmissiveAmbient= MatEmissiveAmbient;
    float4 MirrorColorSaturation= MatMirrorColorSaturation;
    
    ColorAlpha*= TexColorAlpha.Sample(TextureSamplerWrap, In.vTextureCoord);
    
    Out.Color= float4(0, 0, 0, 1);
    Out.Color.rgb+= AmbientLight.rgb * EmissiveAmbient.a * ColorAlpha.rgb;
    Out.Color.rgb+= DiffuseLight * ColorAlpha.rgb;
    Out.Color.rgb+= SpecularLight * SpecularColorPower.rgb;

    return(Out);
}