Hello there, panda-ers! I’ve been on IRC from time to time, but this problem made me to finally register.
So, this is my goal: http.developer.nvidia.com/GPUGem … _ch27.html
That’s all nice and clear, but panda doesn’t seem to have an easy way to get this view projection matrix. I’ve found quite a few topics around here, but none of them give a working answer. Rdb’s solution here works quite well only when you change the camera’s heading (H rotation component). Other than that, it’s unusable - the ghost images pop waay far from where they should. Either it’s a bug on my part or rdb has incredibly low standards to call that “jittering”. I figured out that conversion matrix (convmat in my source) is an identity matrix (convertMat(0, 1))… So that line makes no effect.
Might be a bug on my part though… here are the sources:
shader:
//Cg
//
//Cg profile arbvp1 arbfp1
// http://http.developer.nvidia.com/GPUGems3/gpugems3_ch27.html
const int SAMPLES = 4;
void vshader(
in float4 vtx_position : POSITION,
out float4 l_position : POSITION,
out float2 l_texcoord0 : TEXCOORD0,
uniform float4 texpad_frame,
uniform float4x4 mat_modelproj
)
{
l_position = mul(mat_modelproj, vtx_position);
l_texcoord0 = vtx_position.xz * texpad_frame.xy + texpad_frame.xy;
}
void fshader(
in float2 l_texcoord0 : TEXCOORD0,
out float4 o_color : COLOR,
uniform sampler2D k_frame,
uniform sampler2D k_depth,
uniform float4x4 k_cur_inv_projection,
uniform float4x4 k_prev_projection
)
{
float depth = tex2D(k_depth, l_texcoord0);
float4 currentPos = float4(l_texcoord0.x * 2 - 1, (1 - l_texcoord0.y) * 2 - 1, depth, 1);
float4 worldPos = mul(currentPos, k_cur_inv_projection);
worldPos /= worldPos.w;
float4 previousPos = mul(worldPos, k_prev_projection);
previousPos /= previousPos.w;
float2 velocity = (currentPos - previousPos) / 2.0;
float4 colorbin = tex2D(k_frame, l_texcoord0); // current frame
for (int i = 1; i < SAMPLES; ++i)
{
l_texcoord0 += velocity;
colorbin += tex2D(k_frame, l_texcoord0);
}
o_color = colorbin / float(SAMPLES);
}
relevant part of the script:
def _getProj():
projmat = panda.NodePath('proj_matrix')
convmat = panda.Mat4.convertMat(self.base.camLens.getCoordinateSystem(),
self.base.win.getGsg().getCoordinateSystem())
projmat = self.base.camLens.getProjectionMat() * convmat * self.base.cam.getMat(self.base.render)
return projmat
self._prev_mat = _getProj()
frame = panda.Texture()
depth = panda.Texture()
quad = self.fmanager.renderSceneInto(colortex = frame, depthtex = depth)
quad.setShader(resource.shaders.motion_blur)
quad.setShaderInput('frame', frame)
quad.setShaderInput('depth', depth)
quad.setShaderInput('prev_projection', panda.Mat4())
quad.setShaderInput('cur_inv_projection', self._prev_mat)
def _update_transform(task):
if not self.mblur:
return task.done
else:
quad.setShaderInput('prev_projection', self._prev_mat)
self._prev_mat = _getProj()
inverse = panda.Mat4()
inverse.invertFrom(self._prev_mat)
quad.setShaderInput('cur_inv_projection', inverse)
return task.cont
self.base.taskMgr.add(_update_transform, 'prev_transform_catcher')
Thanks for any and all help! Dolkar