DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

interaction.vertex (4896B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code.  If not, please request a copy in writing from id Software at the address below.
     23 
     24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
     25 
     26 ===========================================================================
     27 */
     28 
     29 #include "global.inc"
     30 
     31 struct VS_IN {
     32 	float4 position : POSITION;
     33 	float2 texcoord : TEXCOORD0;
     34 	float4 normal : NORMAL;
     35 	float4 tangent : TANGENT;
     36 	float4 color : COLOR0;
     37 };
     38 
     39 struct VS_OUT {
     40 	float4 position		: POSITION;
     41 	float4 texcoord0	: TEXCOORD0;
     42 	float4 texcoord1	: TEXCOORD1;
     43 	float4 texcoord2	: TEXCOORD2;
     44 	float4 texcoord3	: TEXCOORD3;
     45 	float4 texcoord4	: TEXCOORD4;
     46 	float4 texcoord5	: TEXCOORD5;
     47 	float4 texcoord6	: TEXCOORD6;
     48 	float4 color		: COLOR0;
     49 };
     50 
     51 void main( VS_IN vertex, out VS_OUT result ) {
     52 
     53 	float3 vNormal = vertex.normal.xyz * 2.0 - 1.0;
     54 	float4 vTangent = vertex.tangent * 2.0 - 1.0;
     55 	float3 vBinormal = cross( vNormal.xyz, vTangent.xyz ) * vTangent.w;
     56 
     57 	result.position.x = dot4( vertex.position, rpMVPmatrixX );
     58 	result.position.y = dot4( vertex.position, rpMVPmatrixY );
     59 	result.position.z = dot4( vertex.position, rpMVPmatrixZ );
     60 	result.position.w = dot4( vertex.position, rpMVPmatrixW );
     61 
     62 	float4 defaultTexCoord = float4( 0.0f, 0.5f, 0.0f, 1.0f );
     63 
     64 	//calculate vector to light in R0
     65 	float4 toLight = rpLocalLightOrigin - vertex.position;
     66 
     67 	//result.texcoord0
     68 	result.texcoord0.x = dot3( vTangent.xyz, toLight );
     69 	result.texcoord0.y = dot3( vBinormal, toLight );
     70 	result.texcoord0.z = dot3( vNormal, toLight );
     71 	result.texcoord0.w = 1.0f;
     72 
     73 	//textures 1 takes the base coordinates by the texture matrix
     74 	result.texcoord1 = defaultTexCoord;
     75 	result.texcoord1.x = dot4( vertex.texcoord.xy, rpBumpMatrixS );
     76 	result.texcoord1.y = dot4( vertex.texcoord.xy, rpBumpMatrixT );
     77 
     78 	//# texture 2 has one texgen
     79 	result.texcoord2 = defaultTexCoord;
     80 	result.texcoord2.x = dot4( vertex.position, rpLightFalloffS );
     81 
     82 	//# texture 3 has three texgens
     83 	result.texcoord3.x = dot4( vertex.position, rpLightProjectionS );
     84 	result.texcoord3.y = dot4( vertex.position, rpLightProjectionT );
     85 	result.texcoord3.z = 0.0f;
     86 	result.texcoord3.w = dot4( vertex.position, rpLightProjectionQ );
     87 
     88 	//# textures 4 takes the base coordinates by the texture matrix
     89 	result.texcoord4 = defaultTexCoord;
     90 	result.texcoord4.x = dot4( vertex.texcoord.xy, rpDiffuseMatrixS );
     91 	result.texcoord4.y = dot4( vertex.texcoord.xy, rpDiffuseMatrixT );
     92 
     93 	//# textures 5 takes the base coordinates by the texture matrix
     94 	result.texcoord5 = defaultTexCoord;
     95 	result.texcoord5.x = dot4( vertex.texcoord.xy, rpSpecularMatrixS );
     96 	result.texcoord5.y = dot4( vertex.texcoord.xy, rpSpecularMatrixT );
     97 
     98 	//# texture 6's texcoords will be the halfangle in texture space
     99 
    100 	//# calculate normalized vector to light in R0
    101 	toLight = normalize( toLight );
    102 
    103 	//# calculate normalized vector to viewer in R1
    104 	float4 toView = normalize( rpLocalViewOrigin - vertex.position );
    105 	
    106 	//# add together to become the half angle vector in object space (non-normalized)
    107 	float4 halfAngleVector = toLight + toView;
    108 
    109 	//# put into texture space
    110 	result.texcoord6.x = dot3( vTangent.xyz, halfAngleVector );
    111 	result.texcoord6.y = dot3( vBinormal, halfAngleVector );
    112 	result.texcoord6.z = dot3( vNormal, halfAngleVector );
    113 	result.texcoord6.w = 1.0f;
    114 
    115 	//# generate the vertex color, which can be 1.0, color, or 1.0 - color
    116 	//# for 1.0 : env[16] = 0, env[17] = 1
    117 	//# for color : env[16] = 1, env[17] = 0
    118 	//# for 1.0-color : env[16] = -1, env[17] = 1	
    119 	result.color = ( swizzleColor( vertex.color ) * rpVertexColorModulate ) + rpVertexColorAdd;
    120 }