• Content count

  • Joined

  • Last visited

Community Reputation

138 Neutral

About Mythar

  • Rank
  1. Alphablend in DX9

    Yup, that did the trick, thx alot :)
  2. Hi all, seems i have been working with shaders too long, and forgot how to set the pipeline for alpha blend .. doh! How do i set the pipeline for "standart" alpha blend ? That is, using a D3DFMT_A8R8G8B8 texture where the alpha channel is how transparent the texture is. Goes something like this: SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, True); SetRenderState(D3DRS_ALPHABLENDENABLE, True); SetRenderState(D3DRS_SRCBLENDALPHA, D3DBLEND_SRCALPHA); SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_INVSRCALPHA); SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); But it's not correct, hope you guys remeber how to do this :)
  3. Sun + ShadowMap

    Thanks for all the help, seems to be working now :)
  4. Sun + ShadowMap

    Ok tryed out your way MJP. ( Tryed it you way as well Augi ) Where did I go wrong ? (still getting a blank texture) // Get Center Center = FCamera.Position + (FCamera.Direction * (FCamera.FarPlane * 0.5)); // Eye Eye = Center - (sunDirection * (FCamera.FarPlane * 0.5)); // ViewMatrix D3DXMatrixLookAtLH( &mView, Eye, Center, FCamera.Up ); // Get the GetFrustumCoordinates ( as done in your SetProjectionPerspective ) frustumCoordsVS = GetFrustumCoordinates(FCamera.Aspect, FCamera.Fov, FCamera.NearPlane, FCamera.FarPlane); // Transform to world space ( &worldMatrix = Translate Camera's Position ? ) D3DXVec3TransformCoordArray(frustumCoordsWS, sizeof(D3DXVECTOR3), frustumCoordsVS, sizeof(D3DXVECTOR3), &worldMatrix, 8 ); // Find min/max of frustumCoordsWS then zf = Max.z; zn = Min.z * 0.5; w = Max.x - Min.x; h = Max.y - Min.y; // ProjectionMatrix D3DXMatrixOrthoLH( &mProj, w, h, zn, zf ); // ShadowMatrix mShadow = mView * mProj; // For eatch object rendered via the shader mLightViewProj = (object's)worldMatrix * mShadow; ... o.Pos = mul(float4(,1), mLightViewProj); o.depth = o.Pos.z; ...
  5. Sun + ShadowMap

    Thanks Augi :) Question : When you set the Unit Cube, why do you use z (0 and 1), should it not be (-1 and +1) ? Also : When you set the Unit Cube, dose it matter what the WorldUp is, as you find the min and max anyways ? And what about the GetFrustumCentroid() ? -> (0,0,0) * (ViewMatrix*ProjectionMatrix) = Center ? [Edited by - Mythar on December 27, 2007 7:34:52 AM]
  6. Sun + ShadowMap

    Thanks MJP :) This helped alot. Any chance you could post the "camera->GetFrustumCoordinates();" function, please ?
  7. Sun + ShadowMap

    Anyone know how to get the OrthoOffCenter matrix based on the frustum and the View matrix based on the Sun's direction vector ? Have tryed all the stuff I could find on the web, but still no luck :(
  8. D3DTS_WORLD is a const value (DWORD) you are setting a matrix = a DWORD value... If you want the world matrix call : GetTransform(D3DTS_WORLD, copiedworld);
  9. Just "move" the ray into "objectspace" (for eatch object you want to test), be4 doing the D3DXIntersect. D3DXMatrixInverse( invMatrix, null, ObjectWorldMatrix ); rayOrigin = D3DVec3TransformCoord(rayOrigin, invMatrix ); rayDir = D3DVec3TransformCoord(rayDir, invMatrix ); rayDir = DirectionVector(rayDir, rayOrigin );
  10. You can do 3 lights in one pass. (why would you want to do more than one pass?) Have a look at the BasicHLSL in the DX SDK. File: BasicHLSL.fx
  11. Depends, if you don't need to update the "GDITexture" (D3DFMT_X8R8G8B8) - sure convert it to an alpha texture. However if you need to update the GDI Texture, you don't want to do convertions to an alpha texture. Insted (if you dont want to use clip()) you can "cheat" like this: sampler sTexture = sampler_state { Texture = <someTexture>; MipFilter = NONE; // Set Min/MagFilter to POINT for PixelPerfect transparency MinFilter = POINT; MagFilter = POINT; AddressU = WRAP; AddressV = WRAP; }; float4 PShader(VS_OUTPUT i) : COLOR { float4 o; o = tex2D(sTexture, i.uv); // Assumes transparent color is 0(Zero) if ((o.r + o.g + o.b) > 0.0) o.a = 1.0; else o.a = 0.0; return o; } technique FakeAlpha { pass P0 { AlphaBlendEnable = true; SrcBlend = SrcAlpha; DestBlend = InvSrcAlpha; pixelshader = compile ps_1_4 PShader(); vertexshader = compile vs_1_1 VShader(); } }
  12. If you want to use the GDI to Draw on your texture, use D3DFMT_X8R8G8B8. Create aTexture using : D3DUSAGE_DYNAMIC and D3DFMT_X8R8G8B8 Get aSurface : aTexture.GetSurfaceLevel(0, aSurface) Get aDC : aSurface.GetDC(aDC) Using this aDC you can create a GDI Canvas to Draw on. Remember to release the aDC : aSurface.ReleaseDC(aDC) Now use a shader to clip() then transparent pixels.
  13. Hi, Im trying to do directional Sun lighting to a ShadowMap. I have been looking at most Google results on "Sun ShadowMap" etc. This is what I have come up with, problem is, it dose not work... Just getting a 0 (Zero) ShadowMapTexture (nothing was rendered). I know my shader works and the "input" frustum planes are correct. I must have overlooked something. procedure NormalizeFrustumPlane(Var p : TFrustumPlane); Var denom : single; Begin denom := 1 / sqrt((p.normal.x*p.normal.x) + (p.normal.y*p.normal.y) + (p.normal.z*p.normal.z)); p.normal.x := p.normal.x * denom; p.normal.y := p.normal.y * denom; p.normal.z := p.normal.z * denom; p.distance := p.distance * denom; End; function Intersect3plane(p1, p2, p3 : TFrustumPlane) : TD3DVector; Var v : array[0..3] of TD3DVector; f : single; Begin NormalizeFrustumPlane(p1); NormalizeFrustumPlane(p2); NormalizeFrustumPlane(p3); v[0] := D3DVec3Scale(VectorCrossProduct(p2.normal, p3.normal), p1.distance); v[1] := D3DVec3Scale(VectorCrossProduct(p3.normal, p1.normal), p2.distance); v[2] := D3DVec3Scale(VectorCrossProduct(p1.normal, p2.normal), p3.distance); v[3] := VectorAdd(VectorAdd(v[0], v[1]), v[2]); f := VectorDotProduct(p1.normal, VectorCrossProduct(p2.normal, p3.normal)); result := D3DVec3Div(v[3], f); End; function FrustumToAABB(Frustum : TFrustum) : TAABB; Var v : array[0..7] of TD3DVector; i : integer; Begin // Planes: 0=Left, 1=Right, 2=Top, 3=Bottom, 4=Near, 5=Far // Bottom v[0] := Intersect3plane(Frustum.Plane[4], Frustum.Plane[3], Frustum.Plane[0]); v[1] := Intersect3plane(Frustum.Plane[4], Frustum.Plane[3], Frustum.Plane[1]); v[2] := Intersect3plane(Frustum.Plane[5], Frustum.Plane[3], Frustum.Plane[0]); v[3] := Intersect3plane(Frustum.Plane[5], Frustum.Plane[3], Frustum.Plane[1]); // Top v[4] := Intersect3plane(Frustum.Plane[4], Frustum.Plane[2], Frustum.Plane[0]); v[5] := Intersect3plane(Frustum.Plane[4], Frustum.Plane[2], Frustum.Plane[1]); v[6] := Intersect3plane(Frustum.Plane[5], Frustum.Plane[2], Frustum.Plane[0]); v[7] := Intersect3plane(Frustum.Plane[5], Frustum.Plane[2], Frustum.Plane[1]); Result.Min := v[0]; Result.Max := v[0]; for i:=0 to 7 do Begin // Max if v[i].x > Result.Max.x then Result.Max.x := v[i].x; if v[i].y > Result.Max.y then Result.Max.x := v[i].y; if v[i].z > Result.Max.z then Result.Max.x := v[i].z; // Min if v[i].x < Result.Min.x then Result.Min.x := v[i].x; if v[i].y < Result.Min.y then Result.Min.y := v[i].y; if v[i].z < Result.Min.z then Result.Min.z := v[i].z; End; End; function GetShadowMatrix(Dir : TD3DVector; AABB : TAABB) : TD3DMatrix; Var v,p : TD3DMatrix; Begin Case FCamera.Orientation of coLeftHand : Begin D3DXMatrixLookAtLH(v, Dir, D3DVector3Zero, FCamera.Up); D3DXMatrixOrthoOffCenterLH(p, AABB.Min.x, AABB.Max.x, AABB.Min.y, AABB.Max.y, AABB.Min.z, AABB.Max.z); End; coRightHand : Begin D3DXMatrixLookAtRH(v, Dir, D3DVector3Zero, FCamera.Up); D3DXMatrixOrthoOffCenterRH(p, AABB.Min.x, AABB.Max.x, AABB.Min.y, AABB.Max.y, AABB.Min.z, AABB.Max.z); End; End; Result := MatrixMultiply(v, p); End;
  14. AABB vs Triangle test ?

    Thx for all the help Vorpy ! Transposing did the trick, its working now :)
  15. AABB vs Triangle test ?

    Sample screenshoot. An object rendered in the actual scene. The white triangle is the one being tested against. The white line is the AABB (min to max) As you can see they do not intersect. Same scene rendered in unit cube space. The white box is the unit cube. The white "line" going through it is the transformed triangle you can see in the above image. As you can see they do intersect, using your transform, even tho they shoud not. Not sure what the bug is...