Jump to content

  • Log In with Google      Sign In   
  • Create Account

Tunisia hawker

Member Since 16 Nov 2011
Offline Last Active Jul 24 2013 01:23 AM

Topics I've Started

How to orthogonalize to non-orthogonal matrix using HLSL

24 January 2013 - 10:11 PM

Hi,I'm just wondering whether this can be done in ps shader.I have an non-orthogonal matrix and need to orthogonalize it and using inverse-​transpose result.I turned to matlab for help,only found their instructions a bit of complicated for shaders.It might influence the performance.So is there a solution yet?Thanks for any reply:)

 

PS:Image below shows the result of using origin matrix and do lighting in world space.

Attached File  Right.png   45.24KB   21 downloads

And this is the wrong result of orthogonalize the origin matrix and then using the inverse-transpose one and do lighting in tangent space.

Attached File  wrong.jpg   27.32KB   21 downloads

And here is my Orthogonalization code.

float3x3 Orthogonalization_Schmidt(float3x3 OrginMatrix)
{
	float3 a1 = OrginMatrix[0];
	float3 a2 = OrginMatrix[1];
	float3 a3 = OrginMatrix[2];

	float3 b1 = a1;
	float3 b2 = a2 - dot(a2,b1)/dot(b1,b1)*b1;
	float3 b3 = a3 - dot(a3,b1)/dot(b1,b1)*b1 - dot(a3,b2)/dot(b2,b2)*b2;

	return float3x3(normalize(b1),normalize(b2),normalize(b3));
}

 

 


Could Parallax Mapping be done at World Space?

08 December 2012 - 11:25 AM

Hello,I am trying normal map and I calculate TBN matrix in pixel shader.Problem is the technique I use give a TBN matrix which is not a orthogonal matrix.It can only translate vectors from tangent space to local space,not the opposite way.So I just do lighting in world space.
I just wonder can I do parallax mapping in world space or view space?If I can't,is there a way to calculate a orthogonal TBN matrix in ps?And what else technique must have tangent space?
Thanks for reply.

UV mirror issues with normalmap , using nonprecomputed tangent space calculating

05 November 2012 - 06:24 AM

Hi,I'm trying to do normalmap using directx9.After reading 2.6 Normal Mapping without Pre-Computed Tangents by Christian Schueler ,I deside to use this.
[source lang="cpp"]float3x3 ComputeTangentFrame(float3 N,float3 p,float2 uv){ float3 dp1 = ddx(p); float3 dp2 = ddy(p); float2 duv1 = ddx(uv); float2 duv2 = ddy(uv); float3x3 M = float3x3(dp1,dp2,cross(dp1,dp2)); float2x3 inversetransposeM = float2x3(cross(M[1],M[2]),cross(M[2],M[0])); float3 T = mul(float2(duv1.x,duv2.x),inversetransposeM); float3 B = mul(float2(duv1.y,duv2.y),inversetransposeM); return float3x3(normalize(T),normalize(B),N);}[/source]
It seems good and simple,but soon I get punished at little seams with UV mirrors.The whole model looks right under light,but at those seams,normal gets wrong and light reflect in unproper way,so a sudden change or miss lighting on surface appears.I think this is because when current pixel is shared by different triangles with different directions of UV,the ddx and ddy instruction will get wrong answers.
So,I use
[source lang="cpp"]float r = (dot(cross(T,B),N)<0.0f) ? -1.0f : 1.0f;[/source]
to judge whether UV was mirrored.Then I realized I can't change tangent or binormal or normal,for most part of the mesh already seems right.On the other hand,I cannot know whether it's U mirror or V mirror.It's hard to tell the right direction of two axes(tangent and binormal) when you only know one axes(Normal).The author do not give futher information.
Btw,because I'm using dx9,so I can't split vertexes in shader.
So I want to know is there a possible way to solve this problem?Thanks for any reply :)

How to switch Perspective to Orthogonal projection while keeping things in almost same...

18 September 2012 - 02:11 AM

Hi,I want to change my projection matrix from Persective to Orthogonal way.I use the same width,height and other properties,so I get bigger things showing on the screen.My question is how to modify the projection matrix so I can get simillar size as Perspective Projection?

How to modify the surface data using LockRect

03 September 2012 - 12:50 AM

I'm trying to save render sth. to texture and modify the data before saving it to file.But I found the data incorrect when I modify them.
[source lang="cpp"] LPDIRECT3DSURFACE9 pBackBuffer,pRenderSurface=NULL; g_pd3dDevice->CreateRenderTarget(width,height,D3DFMT_A8R8G8B8,D3DMULTISAMPLE_NONE,0,TRUE,&pRenderSurface,NULL); hResult = g_pd3dDevice->GetRenderTarget(0,&pBackBuffer); g_pd3dDevice->SetRenderTarget(0,pRenderSurface); g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DXCOLOR(0,0,0,0), 1.f, 0); Render(); g_pd3dDevice->SetRenderTarget(0,pBackBuffer); D3DLOCKED_RECT rect; if(S_OK == pRenderSurface->LockRect(&rect,NULL,D3DLOCK_NOSYSLOCK)) { DWORD* pColor = (DWORD*)rect.pBits; for( UINT y = 0 ; y < height ; y++ ) { for(UINT x = 0 ; x < width ; x++ ) { DWORD color = pColor[y*rect.Pitch/4+x]; D3DCOLOR dwcolor = color; D3DXCOLOR fColor = Color2Value(dwcolor); if(fColor.a > 0) { fColor.r /= fColor.a; fColor.g /= fColor.a; fColor.b /= fColor.a; } dwcolor = Value2Color(fColor); pColor[y*rect.Pitch/4+x] = dwcolor; } } pRenderSurface->UnlockRect(); } D3DXSaveSurfaceToFile(pTexPathName,texFormat,pRenderSurface,NULL,NULL);[/source]
Here is the code.I tried every D3DLOCK flags but none of them work. I also try CreateOffscreenPlainSurface and GetRenderTargetData to copy the surface data to system memory before LockRect.Also Failed.Did I miss Something?

PARTNERS