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 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 |
////////////////////////////////////////////////////////////////// //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 //# 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; //# //Blickrichtung und Normale im TangentSpace benötigt row_major float3x3 mTBN= {Out.vTangent, Out.vBinormal, Out.vNormal}; Out.vViewDirTS= mul(mTBN, -Out.vViewDir); Out.vNormalTS= mul(mTBN, Out.vNormal); //# return(Out); } //PixelShader PSOutput PixelShaderProc(PSInput In) { PSOutput Out; //# //Parallax Occlusion Mapping float fParallaxLimit= length(In.vViewDirTS.xy) / In.vViewDirTS.z; const float fHeightMapScale= 0.1; fParallaxLimit*= fHeightMapScale; float2 vOffset = normalize( -In.vViewDirTS.xy ); vOffset = vOffset * fParallaxLimit; float3 E = normalize( In.vViewDirTS ); float3 N = normalize( In.vNormalTS ); const int nMinSamples= 16; const int nMaxSamples= 128; int nNumSamples = (int)lerp( nMinSamples, nMaxSamples, dot( E, N ) ); float fStepSize = 1.0 / (float)nNumSamples; float2 dx, dy; dx = ddx( In.vTextureCoord ); dy = ddy( In.vTextureCoord ); float2 vOffsetStep = fStepSize * vOffset; float2 vCurrOffset = float2( 0, 0 ); float2 vLastOffset = float2( 0, 0 ); float2 vFinalOffset = float2( 0, 0 ); float4 vCurrSample; float4 vLastSample; float stepHeight = 1.0; int nCurrSample = 0; while ( nCurrSample < nNumSamples ) { vCurrSample = TexNormalHeight.SampleGrad( TextureSamplerWrap, In.vTextureCoord + vCurrOffset, dx, dy ); if ( vCurrSample.a > stepHeight ) { float Ua = (vLastSample.a - (stepHeight+fStepSize)) / ( fStepSize + (vCurrSample.a - vLastSample.a)); vFinalOffset = vLastOffset + Ua * vOffsetStep; vCurrSample = TexNormalHeight.SampleGrad( TextureSamplerWrap, In.vTextureCoord + vFinalOffset, dx, dy ); nCurrSample = nNumSamples + 1; } else { nCurrSample++; 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); } |
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »BlazeX« (24.11.2010, 14:37) aus folgendem Grund: Erledigt
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Werbeanzeige