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
"...Das gibts in d3d11 nichtmehr.
EDIT: Siehe Fireballs Posting wie es richtig geht.
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 173 |
Texture2D g_Textur0; Texture2D g_Textur1; Texture2D g_Textur2; Texture2D g_Textur3; float4x4 g_ViewInv : ViewInverse; float4x4 g_View : View; float4x4 g_Projection : Projection; //-------------------------------------------------------------------------------------- // Texture samplers //-------------------------------------------------------------------------------------- sampler Textur0 = sampler_state{ Texture = <g_Textur0>; Filter = MIN_MAG_MIP_LINEAR; AddressU = mirror; AddressV = mirror;}; sampler Textur1 = sampler_state{ Texture = <g_Textur1>; Filter = MIN_MAG_MIP_LINEAR; AddressU = mirror; AddressV = mirror;}; sampler Textur2 = sampler_state{ Texture = <g_Textur2>; Filter = MIN_MAG_MIP_LINEAR; AddressU = mirror; AddressV = mirror;}; sampler Textur3 = sampler_state{ Texture = <g_Textur3>; Filter = MIN_MAG_MIP_LINEAR; AddressU = mirror; AddressV = mirror;}; //-------------------------------------------------------------------------------------- // Vertex shader output structure //-------------------------------------------------------------------------------------- struct VS_OUTPUT { float4 Position : POSITION; float4 Color : Color0; // vertex texture coords float2 TexCoords : TEXCOORD0; // vertex texture coords float TexID: TEXCOORD1; }; //-------------------------------------------------------------------------------------- // Pixel shader output structure //-------------------------------------------------------------------------------------- struct PS_OUTPUT { float4 RGBColor : SV_TARGET0; // Pixel color }; //-------------------------------------------------------------------------------------- // 2D Part //-------------------------------------------------------------------------------------- VS_OUTPUT Render2DVS( float4 Position : POSITION, float4 Color: Color0, float2 TexCoords : TEXCOORD0, float TexID : TEXCOORD1) { VS_OUTPUT Output; Output.Position = Position; Output.Color = Color; Output.TexCoords = TexCoords; Output.TexID = TexID; return Output; } PS_OUTPUT Render2DPS( VS_OUTPUT In ) { PS_OUTPUT Output; if(In.TexID > 2.5) Output.RGBColor = g_Textur3.Sample(Textur3 ,In.TexCoords) * In.Color; else if(In.TexID > 1.5) Output.RGBColor = g_Textur2.Sample(Textur2 ,In.TexCoords) * In.Color; else if(In.TexID > 0.5) Output.RGBColor = g_Textur1.Sample(Textur1 ,In.TexCoords) * In.Color; else Output.RGBColor = g_Textur0.Sample(Textur0 ,In.TexCoords) * In.Color; return Output; } //-------------------------------------------------------------------------------------- // 3D Part //-------------------------------------------------------------------------------------- VS_OUTPUT Render3DVS( float4 Position : POSITION, float4 Color: Color0, float2 TexCoords : TEXCOORD0, float TexID : TEXCOORD1, float4 Center : TEXCOORD2) { VS_OUTPUT Output; float4 pos = mul(Position - Center,g_ViewInv) + Center; Output.Position = mul(mul(pos,g_View),g_Projection);; //Output.Position = mul(mul(Position,g_View),g_Projection);; Output.Color = Color; Output.TexCoords = TexCoords; Output.TexID = TexID; return Output; } PS_OUTPUT Render3DPS( VS_OUTPUT In ) { PS_OUTPUT Output; if(In.TexID > 2.5) Output.RGBColor = g_Textur3.Sample(Textur3 ,In.TexCoords);// * In.Color; else if(In.TexID > 1.5) Output.RGBColor = g_Textur2.Sample(Textur2 ,In.TexCoords);// * In.Color; else if(In.TexID > 0.5) Output.RGBColor = g_Textur1.Sample(Textur1 ,In.TexCoords);// * In.Color; else Output.RGBColor = g_Textur0.Sample(Textur0 ,In.TexCoords);// * In.Color; return Output; } PS_OUTPUT Render3DPS_ATest( VS_OUTPUT In ) { PS_OUTPUT Output; if(In.TexID > 2.5) Output.RGBColor = g_Textur3.Sample(Textur3 ,In.TexCoords);// * In.Color; else if(In.TexID > 1.5) Output.RGBColor = g_Textur2.Sample(Textur2 ,In.TexCoords);// * In.Color; else if(In.TexID > 0.5) Output.RGBColor = g_Textur1.Sample(Textur1 ,In.TexCoords);// * In.Color; else Output.RGBColor = g_Textur0.Sample(Textur0 ,In.TexCoords);// * In.Color; return Output;; if(Output.RGBColor.a <= 0.0) discard; return Output; } //-------------------------------------------------------------------------------------- // Techniques //-------------------------------------------------------------------------------------- technique11 Render2DAlpha { pass P0 { SetVertexShader( CompileShader( vs_4_1, Render2DVS() ) ); SetPixelShader( CompileShader( ps_4_1, Render2DPS() ) ); //CullMode = none; //ZEnable = false; //AlphaBlendEnable = true; //SrcBlend = SRCALPHA; //DestBlend = INVSRCALPHA; } } technique11 Render2D { pass P0 { SetVertexShader( CompileShader( vs_4_1, Render2DVS() ) ); SetPixelShader( CompileShader( ps_4_1, Render2DPS() ) ); //CullMode = none; } } technique11 Render3DAlphaTest { pass P0 { SetVertexShader( CompileShader( vs_4_1, Render2DVS() ) ); SetPixelShader( CompileShader( ps_4_1, Render3DPS_ATest() ) ); //CullMode = none; //ZEnable = false; //AlphaBlendEnable = true; //SrcBlend = SRCALPHA; //DestBlend = INVSRCALPHA; } } technique11 Render3DAlpha { pass P0 { SetVertexShader( CompileShader( vs_4_1, Render2DVS() ) ); SetPixelShader( CompileShader( ps_4_1, Render2DPS() ) ); //CullMode = none; //ZEnable = false; //AlphaBlendEnable = true; //SrcBlend = SRCALPHA; //DestBlend = INVSRCALPHA; } } technique11 Render3D { pass P0 { SetVertexShader( CompileShader( vs_4_1, Render2DVS() ) ); SetPixelShader( CompileShader( ps_4_1, Render2DPS() ) ); //CullMode = none; } } |
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 |
DXGI_SWAP_CHAIN_DESC scd; ZeroMemory(&scd, sizeof(scd)); scd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; scd.BufferCount = 1; scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; scd.BufferDesc.Width = wish.Width; scd.BufferDesc.Height = wish.Height; scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; scd.SampleDesc.Count = 4 scd.Windowed = m_bFullscreen; scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; ... this->createDisplayModeList(); D3D_DRIVER_TYPE driverTypes[] = { D3D_DRIVER_TYPE_HARDWARE, D3D_DRIVER_TYPE_WARP, D3D_DRIVER_TYPE_REFERENCE, }; D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, }; m_params.OutputWindow = glob->getInstance()->m_hWnd; UINT numDriverTypes = ARRAYSIZE( driverTypes ); UINT numFeatureLevels = ARRAYSIZE( featureLevels ); D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0; for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ ) { g_driverType = driverTypes[driverTypeIndex]; result = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, D3D11_CREATE_DEVICE_BGRA_SUPPORT, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &m_params, &swapchain, &ddev, &g_featureLevel, &devcon ); if( SUCCEEDED( result ) ) break; } if( FAILED( result ) ) return result; if( result == S_OK ) { ID3D11Texture2D *pBackBuffer = NULL; swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); ddev->CreateRenderTargetView(pBackBuffer, NULL, &backbuffer); pBackBuffer->Release(); devcon->OMSetRenderTargets(1, &backbuffer, NULL); D3D11_VIEWPORT viewport; ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT)); viewport.TopLeftX = 0; viewport.TopLeftY = 0; viewport.Width = m_Width; viewport.Height = m_Height; devcon->RSSetViewports(1, &viewport); |
Werbeanzeige