Jump to content

  • Log In with Google      Sign In   
  • Create Account

Martin Perry

Member Since 23 Feb 2012
Offline Last Active Nov 23 2015 02:11 AM

Topics I've Started

Tangent space - Lengyel vs ShaderX5 - difference ?

08 October 2015 - 10:07 AM

I have been studiing tangent space calculations and came across two solutions


E. Lengyel - http://www.terathon.com/code/tangent.html

ShaderX5 solution - (solution is also desribed here http://www.thetenthplanet.de/archives/1180)


What is the difference between tangent computed one or another way? Lengyel solution seems "easier" but I am no quite sure of its orthogonality to the normal vector of the tangent plane.

Reconstruct position from depth - screen space triangulation - precission

24 May 2015 - 02:44 AM

I have stored depth (R32F) and normal (RGBA32F) in two textures. In my postprocess shader I reconstruct position from depth. For every pixel, I create 8-neighborhood (+/-1 pixel), calculate position and normal differences from center pixel. Later, I used this values to create "screen space triangles" with reconstructed positions and normals in its vertices. 


Something like this (http://www.jshopf.net/?p=47):




but I dont create actual triangles, just virtual ones inside my pixel shader.


I want to use this as 2D height field and look at this as a 2,5D function problem to calculate some values. Problem is, that result is very noisy. Plus noise is moving, when I move camera - but that is acceptable, since I am in screen space and that is not really a problem. Another problem is that noise is changing from frame to frame even if I dont move camera at all. Most likely a precision issue, but can it be dealt with?



EDIT: I have been digging and I have found another problem. If I reconstruct triangle and move camera "behind" object, reconstructed triangles have changed orientation (or at least it appears so, because my result are on this side negative values and should be positive). How to repair this? I have tried to mul my result by dot of camera position - triangle / triangleNormal vector, but that is not correct.

WinAPI - Raw input and mouse acceleration

06 March 2015 - 01:22 AM

I am using RAW input. All is working correctly, if I disable mouse acceleration. But that is not really a user-friendly solution. How can I use raw input with mouse acceleration? I mean, how to multilply retrieved values to get the same effect as windows primary do?


Second approach would be to disable acceleration only for my application. I kind of already tried that, but I dont like this solution. When app crash, default values are not set back and acceleration stays turned off.

Drag object with mouse - lock axis

01 January 2015 - 05:20 AM

I have created object draging by mouse. I am using this code to calculate dx, dy in screen space


pos = object position in world space

    float objDistCam = pos.Distance(this->camera->GetPosition());

    MyMath::Vector4 P = MyMath::Vector4(0, 0, objDistCam, 1.0f);
    MyMath::Vector4 S = MyMath::Vector4::Transform(P, this->camera->GetCameraMatrices()->projectionMatrix);
    S *= 1.0f / S.W;

    MyMath::Vector4  S2 = S;
    S2.X = S2.X + (((float)-pointBasedControl->GetChangeX()) / (this->camera->GetViewport()->Width * 0.5f));
    S2.Y = S2.Y + (((float)pointBasedControl->GetChangeY()) / (this->camera->GetViewport()->Height * 0.5f));

    MyMath::Matrix4x4 inv = MyMath::Matrix4x4::Invert(this->camera->GetCameraMatrices()->projectionMatrix);
    MyMath::Vector4 P2 = MyMath::Vector4::Transform(S2, inv);
    P2 *= 1.0f / P2.W;

    dx = P.X - P2.X;
    dy = P.Y - P2.Y;

Final object position is calculated like this

pos += camera_right * dx + camera_up * dy;

Now, this works.


If I lock single axis, lets say X (pos.X += camera_right.X * dx + camera_up.X * dy), it wors as well. Problem is, if axis system is not aligned with world axis and object is rotated. Then this leads to object moving in "world" X axis, not in "object" one. How to correct this?

Bezier triangle partial second-order derivatives

27 December 2014 - 11:30 AM

I am using this article: http://www.gamasutra.com/view/feature/131389/b%C3%A9zier_triangles_and_npatches.php?print=1 and this topic: http://www.gamedev.net/topic/624397-bezier-triangle-partial-derivatives/


So far, I have first-order derivates of bezier triangle patch. But hot to calculate second one?


In some article, I have found this:


Attached File  Clipboard02.png   50.81KB   7 downloads


But I am not sure, if it is correct - for example, third sum in Fuu seems incorrect with (i - 1).