filter: Fix CommonFilters with non-default coordinate system

Fixes #1289
This commit is contained in:
rdb 2022-04-04 10:28:18 +02:00
parent 646611bfa6
commit e7dd93d0d4
8 changed files with 36 additions and 21 deletions

View File

@ -29,6 +29,7 @@ from panda3d.core import Filename
from panda3d.core import AuxBitplaneAttrib
from panda3d.core import Texture, Shader, ATSNone
from panda3d.core import FrameBufferProperties
from panda3d.core import getDefaultCoordinateSystem, CS_zup_right, CS_zup_left
import os
CARTOON_BODY="""
@ -51,6 +52,7 @@ o_color = lerp(o_color, k_cartooncolor, cartoon_thresh);
SSAO_BODY="""//Cg
void vshader(float4 vtx_position : POSITION,
float2 vtx_texcoord : TEXCOORD0,
out float4 l_position : POSITION,
out float2 l_texcoord : TEXCOORD0,
out float2 l_texcoordD : TEXCOORD1,
@ -60,9 +62,9 @@ void vshader(float4 vtx_position : POSITION,
uniform float4x4 mat_modelproj)
{
l_position = mul(mat_modelproj, vtx_position);
l_texcoord = vtx_position.xz;
l_texcoordD = (vtx_position.xz * texpad_depth.xy) + texpad_depth.xy;
l_texcoordN = (vtx_position.xz * texpad_normal.xy) + texpad_normal.xy;
l_texcoord = vtx_texcoord;
l_texcoordD = vtx_texcoord * texpad_depth.xy * 2;
l_texcoordN = vtx_texcoord * texpad_normal.xy * 2;
}
float3 sphere[16] = float3[](float3(0.53812504, 0.18565957, -0.43192),float3(0.13790712, 0.24864247, 0.44301823),float3(0.33715037, 0.56794053, -0.005789503),float3(-0.6999805, -0.04511441, -0.0019965635),float3(0.06896307, -0.15983082, -0.85477847),float3(0.056099437, 0.006954967, -0.1843352),float3(-0.014653638, 0.14027752, 0.0762037),float3(0.010019933, -0.1924225, -0.034443386),float3(-0.35775623, -0.5301969, -0.43581226),float3(-0.3169221, 0.106360726, 0.015860917),float3(0.010350345, -0.58698344, 0.0046293875),float3(-0.08972908, -0.49408212, 0.3287904),float3(0.7119986, -0.0154690035, -0.09183723),float3(-0.053382345, 0.059675813, -0.5411899),float3(0.035267662, -0.063188605, 0.54602677),float3(-0.47761092, 0.2847911, -0.0271716));
@ -292,11 +294,19 @@ class CommonFilters:
text += "{\n"
text += " l_position = mul(mat_modelproj, vtx_position);\n"
# The card is oriented differently depending on our chosen
# coordinate system. We could just use vtx_texcoord, but this
# saves on an additional variable.
if getDefaultCoordinateSystem() in (CS_zup_right, CS_zup_left):
pos = "vtx_position.xz"
else:
pos = "vtx_position.xy"
for texcoord, padTex in texcoordPadding.items():
if padTex is None:
text += " %s = vtx_position.xz * float2(0.5, 0.5) + float2(0.5, 0.5);\n" % (texcoord)
text += " %s = %s * float2(0.5, 0.5) + float2(0.5, 0.5);\n" % (texcoord, pos)
else:
text += " %s = (vtx_position.xz * texpad_tx%s.xy) + texpad_tx%s.xy;\n" % (texcoord, padTex, padTex)
text += " %s = (%s * texpad_tx%s.xy) + texpad_tx%s.xy;\n" % (texcoord, pos, padTex, padTex)
if ("HalfPixelShift" in configuration):
text += " %s += texpix_tx%s.xy * 0.5;\n" % (texcoord, padTex)

View File

@ -32,6 +32,7 @@ BLOOM_I = """
void vshader(float4 vtx_position : POSITION,
float2 vtx_texcoord : TEXCOORD0,
out float4 l_position : POSITION,
out float2 l_texcoordNW : TEXCOORD0,
out float2 l_texcoordNE : TEXCOORD1,
@ -42,7 +43,7 @@ void vshader(float4 vtx_position : POSITION,
uniform float4x4 mat_modelproj)
{
l_position=mul(mat_modelproj, vtx_position);
float2 c=(vtx_position.xz * texpad_src.xy) + texpad_src.xy;
float2 c = vtx_texcoord * texpad_src.xy * 2;
float4 offs = texpix_src * 0.5;
l_texcoordNW = c + float2( offs.x, -offs.y);
l_texcoordNE = c + float2( offs.x, offs.y);

View File

@ -2,6 +2,7 @@ BLOOM_X = """
//Cg
void vshader(float4 vtx_position : POSITION,
float2 vtx_texcoord : TEXCOORD0,
out float4 l_position : POSITION,
out float4 l_texcoord0 : TEXCOORD0,
out float4 l_texcoord1 : TEXCOORD1,
@ -10,8 +11,8 @@ void vshader(float4 vtx_position : POSITION,
uniform float4 texpix_src,
uniform float4x4 mat_modelproj)
{
l_position=mul(mat_modelproj, vtx_position);
float2 c=(vtx_position.xz * texpad_src.xy) + texpad_src.xy;
l_position = mul(mat_modelproj, vtx_position);
float2 c = vtx_texcoord * texpad_src.xy * 2;
float offset = texpix_src.x;
float pad = texpad_src.x * 2;
l_texcoord0 = float4(min(c.x-offset* -4, pad), min(c.x-offset* -3, pad), min(c.x-offset* -2, pad), c.y);

View File

@ -2,6 +2,7 @@ BLOOM_Y = """
//Cg
void vshader(float4 vtx_position : POSITION,
float2 vtx_texcoord : TEXCOORD0,
out float4 l_position : POSITION,
out float4 l_texcoord0 : TEXCOORD0,
out float4 l_texcoord1 : TEXCOORD1,
@ -11,7 +12,7 @@ void vshader(float4 vtx_position : POSITION,
uniform float4x4 mat_modelproj)
{
l_position=mul(mat_modelproj, vtx_position);
float2 c=(vtx_position.xz * texpad_src.xy) + texpad_src.xy;
float2 c = vtx_texcoord * texpad_src.xy * 2;
float offset = texpix_src.y;
float pad = texpad_src.y * 2;
l_texcoord0 = float4(min(c.y-offset* -4, pad), min(c.y-offset* -3, pad), min(c.y-offset* -2, pad), c.x);

View File

@ -4,14 +4,14 @@ BLUR_X = """
//Cg profile arbvp1 arbfp1
void vshader(float4 vtx_position : POSITION,
float2 vtx_texcoord0 : TEXCOORD0,
float2 vtx_texcoord : TEXCOORD0,
out float4 l_position : POSITION,
out float2 l_texcoord0 : TEXCOORD0,
out float2 l_texcoord0 : TEXCOORD0,
uniform float4 texpad_src,
uniform float4x4 mat_modelproj)
{
l_position=mul(mat_modelproj, vtx_position);
l_texcoord0 = (vtx_position.xz * texpad_src.xy) + texpad_src.xy;
l_position = mul(mat_modelproj, vtx_position);
l_texcoord0 = vtx_texcoord * texpad_src.xy * 2;
}

View File

@ -4,14 +4,14 @@ BLUR_Y = """
//Cg profile arbvp1 arbfp1
void vshader(float4 vtx_position : POSITION,
float2 vtx_texcoord0 : TEXCOORD0,
float2 vtx_texcoord : TEXCOORD0,
out float4 l_position : POSITION,
out float2 l_texcoord0 : TEXCOORD0,
out float2 l_texcoord0 : TEXCOORD0,
uniform float4 texpad_src,
uniform float4x4 mat_modelproj)
{
l_position=mul(mat_modelproj, vtx_position);
l_texcoord0 = (vtx_position.xz * texpad_src.xy) + texpad_src.xy;
l_position = mul(mat_modelproj, vtx_position);
l_texcoord0 = vtx_texcoord * texpad_src.xy * 2;
}

View File

@ -3,13 +3,14 @@ COPY = """
void vshader(float4 vtx_position : POSITION,
float2 vtx_texcoord : TEXCOORD0,
out float4 l_position : POSITION,
out float2 l_texcoord : TEXCOORD0,
uniform float4 texpad_src,
uniform float4x4 mat_modelproj)
{
l_position=mul(mat_modelproj, vtx_position);
l_texcoord = (vtx_position.xz * texpad_src.xy) + texpad_src.xy;
l_position = mul(mat_modelproj, vtx_position);
l_texcoord = vtx_texcoord * texpad_src.xy * 2;
}
void fshader(float2 l_texcoord : TEXCOORD0,

View File

@ -2,6 +2,7 @@ DOWN_4 = """
//Cg
void vshader(float4 vtx_position : POSITION,
float2 vtx_texcoord : TEXCOORD0,
out float4 l_position : POSITION,
out float2 l_texcoordNW : TEXCOORD0,
out float2 l_texcoordNE : TEXCOORD1,
@ -11,8 +12,8 @@ void vshader(float4 vtx_position : POSITION,
uniform float4 texpix_src,
uniform float4x4 mat_modelproj)
{
l_position=mul(mat_modelproj, vtx_position);
float2 c=(vtx_position.xz * texpad_src.xy) + texpad_src.xy;
l_position = mul(mat_modelproj, vtx_position);
float2 c = vtx_texcoord * texpad_src.xy * 2;
l_texcoordNW = c + float2( texpix_src.x, -texpix_src.y);
l_texcoordNE = c + float2( texpix_src.x, texpix_src.y);
l_texcoordSW = c + float2(-texpix_src.x, -texpix_src.y);