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
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
D3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE , TRUE); D3DDevice->SetRenderState(D3DRS_ZWRITEENABLE , FALSE); D3DDevice->SetRenderState(D3DRS_ZENABLE , FALSE); D3DDevice->SetRenderState( D3DRS_LIGHTING , FALSE ); D3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_INVSRCCOLOR); D3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_SRCCOLOR); D3DDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_REVSUBTRACT); |
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 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 |
//-------------------------------------------------------------------------------------- // File: MeshFromOBJ.fx // // The effect file for the MeshFromOBJ sample. // // Copyright (c) Microsoft Corporation. All rights reserved. //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- // Global variables //-------------------------------------------------------------------------------------- float3 g_vMaterialAmbient : Ambient = float3( 0.2f, 0.2f, 0.2f ); // Material's ambient color float3 g_vMaterialDiffuse : Diffuse = float3( 0.8f, 0.8f, 0.8f ); // Material's diffuse color float3 g_vMaterialSpecular : Specular = float3( 1.0f, 1.0f, 1.0f ); // Material's specular color float g_fMaterialAlpha : Opacity = 1.0f; int g_nMaterialShininess : SpecularPower = 32; float3 g_vLightColor : LightColor = float3( 1.0f, 1.0f, 1.0f ); // Light color float3 g_vLightPosition : LightPosition = float3( 50.0f, 10.0f, 0.0f ); // Light position float3 g_vCameraPosition : CameraPosition; texture g_MeshTexture : Texture; // Color texture for mesh float g_fTime : Time; // App's time in seconds float4x4 g_mWorld : World; // World matrix float4x4 g_mWorldViewProjection : WorldViewProjection; // World * View * Projection matrix //-------------------------------------------------------------------------------------- // Texture samplers //-------------------------------------------------------------------------------------- sampler MeshTextureSampler = sampler_state { Texture = <g_MeshTexture>; MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; }; //-------------------------------------------------------------------------------------- // Name: Projection // Type: Vertex Shader Fragment // Desc: Projection transform //-------------------------------------------------------------------------------------- void Projection( float4 vPosObject: POSITION, float3 vNormalObject: NORMAL, float2 vTexCoordIn: TEXCOORD0, out float4 vPosProj: POSITION, out float2 vTexCoordOut: TEXCOORD0, out float4 vColorOut: COLOR0, uniform bool bSpecular ) { // Transform the position into world space for lighting, and projected space // for display float4 vPosWorld = mul( vPosObject, g_mWorld ); vPosProj = mul( vPosObject, g_mWorldViewProjection ); // Transform the normal into world space for lighting float3 vNormalWorld = mul( vNormalObject, (float3x3)g_mWorld ); // Pass the texture coordinate vTexCoordOut = vTexCoordIn; // Compute the light vector float3 vLight = normalize( g_vLightPosition - vPosWorld.xyz ); // Compute the ambient and diffuse components of illumination vColorOut.rgb = g_vLightColor * g_vMaterialAmbient; vColorOut.rgb += g_vLightColor * g_vMaterialDiffuse * saturate( dot( vLight, vNormalWorld ) ); // If enabled, calculate the specular term if( bSpecular ) { float3 vCamera = normalize(vPosWorld.xyz - g_vCameraPosition); float3 vReflection = reflect( vLight, vNormalWorld ); float fPhongValue = saturate( dot( vReflection, vCamera ) ); vColorOut.rgb += g_vMaterialSpecular * pow(fPhongValue, g_nMaterialShininess); } vColorOut.a = g_fMaterialAlpha; } //-------------------------------------------------------------------------------------- // Name: Lighting // Type: Pixel Shader // Desc: Compute lighting and modulate the texture //-------------------------------------------------------------------------------------- void Lighting( float2 vTexCoord: TEXCOORD0, float4 vColorIn: COLOR0, out float4 vColorOut: COLOR0, uniform bool bTexture ) { vColorOut = vColorIn; // Sample and modulate the texture if( bTexture ) vColorOut.rgb *= tex2D( MeshTextureSampler, vTexCoord ); } //-------------------------------------------------------------------------------------- // Techniques //-------------------------------------------------------------------------------------- technique Specular { pass P0 { VertexShader = compile vs_2_0 Projection(true); PixelShader = compile ps_2_0 Lighting(false); } } technique NoSpecular { pass P0 { VertexShader = compile vs_2_0 Projection(false); PixelShader = compile ps_2_0 Lighting(false); } } technique TexturedSpecular { pass P0 { VertexShader = compile vs_2_0 Projection(true); PixelShader = compile ps_2_0 Lighting(true); } } technique TexturedNoSpecular { pass P0 { VertexShader = compile vs_2_0 Projection(false); PixelShader = compile ps_2_0 Lighting(true); } } |
Werbeanzeige