/////////////////////////////////////////////////////////////////////////// // // vertex program used to render the particles. // sets the particle position reading from the position texture // and stretches the particle onscreen. // /////////////////////////////////////////////////////////////////////////// struct entree { float4 position : POSITION; float4 texCoords0 : TEXCOORD0; }; struct sortie { float4 position : POSITION; float2 texCoords0 : TEXCOORD0; float2 texCoords1 : TEXCOORD1; float4 posworld : TEXCOORD2; float4 normale : TEXCOORD3; float3 eyetovert : TEXCOORD4; }; #define SCREEN_RATIO (1280.0/1024.0) sortie mainNoStreaks(entree IN, uniform float3 viewPos, uniform float3 viewDir, uniform float3 boxMin, uniform float3 boxMax, uniform float rainBbSide, uniform float4x4 worldviewproj, uniform float4x4 worldview, uniform sampler2D texPos : TEXUNIT1) { sortie OUT; //we get the position of the vertex from the texture float4 posFromTexture = tex2D(texPos, IN.texCoords0.zw); float4 thePos; thePos.x = viewPos.x + posFromTexture.x * (boxMax.x - boxMin.x) + boxMin.x - viewDir.x * ((boxMax.x - boxMin.x) / 2.0); thePos.y = viewPos.y + posFromTexture.y * (boxMax.y - boxMin.y) + boxMin.y; thePos.z = viewPos.z + posFromTexture.z * (boxMax.z - boxMin.z) + boxMin.z - viewDir.z * ((boxMax.z - boxMin.z) / 2.0); thePos.w = 1.0; // USE FOLLOWING LINE TO AVOID READING POSITION FROM TEXTURE //float4 thePos = IN.position + 0.000000001 * (viewPos.x + boxMax.x + boxMin.x + viewDir.x); // transform it to screen space OUT.position = mul(worldviewproj, thePos); // shape it as a quad (oriented on camera plane) OUT.position.x += rainBbSide * (IN.texCoords0.x - 0.5f); OUT.position.y -= rainBbSide * SCREEN_RATIO * (IN.texCoords0.y - 0.5f); // don't change the fist texture coordinates OUT.texCoords0 = IN.texCoords0.xy; // second texture coordinates receive the position of the drop, in screen space float4 VposEye = mul(worldviewproj, thePos); VposEye.xyz /= VposEye.w; OUT.texCoords1 = (1.0 + VposEye.xy).xy / 2.0; OUT.texCoords1.y = 1.0 - OUT.texCoords1.y; OUT.normale.x = (IN.texCoords0.x - 0.5) * 2.0; OUT.normale.y = -(IN.texCoords0.y - 0.5) * 2.0; OUT.normale.zw = 1.0; OUT.posworld = thePos; // unprojected vertex coordinate OUT.eyetovert = mul(worldview, thePos).xyz; return OUT; } sortie mainStreaks(entree IN, uniform float3 viewPos, uniform float3 viewDir, uniform float3 boxMin, uniform float3 boxMax, uniform float3 fallVect, uniform float rainBbSide, uniform float streaksHeight, uniform float4x4 worldviewproj, uniform float4x4 worldview, uniform sampler2D texPos : TEXUNIT1) { sortie OUT; //we get the position of the vertex from the texture float4 posFromTexture = tex2D(texPos, IN.texCoords0.zw); float4 thePos; thePos.x = viewPos.x + posFromTexture.x * (boxMax.x - boxMin.x) + boxMin.x - viewDir.x * ((boxMax.x - boxMin.x) / 2.0); thePos.y = viewPos.y + posFromTexture.y * (boxMax.y - boxMin.y) + boxMin.y; thePos.z = viewPos.z + posFromTexture.z * (boxMax.z - boxMin.z) + boxMin.z - viewDir.z * ((boxMax.z - boxMin.z) / 2.0); thePos.w = 1.0; // USE FOLLOWING LINE TO AVOID READING POSITION FROM TEXTURE //float4 thePos = IN.position + 0.000000001 * (viewPos.x + boxMax.x + boxMin.x + viewDir.x); // stetch the streak vertically thePos.y += (1.0 - IN.texCoords0.y) * streaksHeight; // make it follow the wind direction thePos.xz += (IN.texCoords0.y * 2.0 - 1.0) * fallVect.xz; // transform its coordinate to screen space OUT.position = mul(worldviewproj, thePos); // shape it as a quad (oriented on camera plane) OUT.position.x += rainBbSide * (IN.texCoords0.x - 0.5f); // don't change the first texture coordinates OUT.texCoords0 = IN.texCoords0.xy; float4 VposEye = OUT.position; VposEye.xyz /= VposEye.w; OUT.texCoords1 = (1.0 + VposEye.xy).xy / 2.0; OUT.texCoords1.y = 1.0 - OUT.texCoords1.y; OUT.normale.x = (IN.texCoords0.x - 0.5) * 2.0; OUT.normale.y = -(IN.texCoords0.y - 0.5) * 2.0; OUT.normale.zw = 1.0; OUT.posworld = thePos; OUT.eyetovert = mul(worldview, thePos).xyz; return OUT; }