Skip to content

Conversation

@tkpmonke
Copy link

Adds affine texture mapping to BaseMaterial3D.

This effect is useful for retro graphics, such as recreating the visual style of the original Playstation. I personally made this to prevent having to do several different StandardMaterial3D -> ShaderMaterial conversions due to code repetition.

This is an effect with very little use case outside of PSX style games, but I see many PSX games being made in Godot so I believe it may benefit by having this option be something out of the box.

This effect works by reversing the perspective correction that the GPU does. This is usually done via a noperspective keyword in the shader language, but I could not find documentation saying that there was such keyword in glslang.

affine3 affine2 affine1

@tkpmonke tkpmonke requested a review from a team as a code owner December 14, 2025 18:35
@tkpmonke tkpmonke changed the title Add Affine texture mapping to StandardMaterial3D Add Affine texture mapping to BaseMaterial3D Dec 14, 2025
@fire
Copy link
Member

fire commented Dec 14, 2025

Similar to reasoning to avoiding palettes colors in images, I would think that adding a mode that makes quality worse for a PBR engine would be weird.

@tkpmonke
Copy link
Author

that's a fair point, however i could say the same thing about per-vertex or lambert lighting. unless i am mistaken and there are real uses for these, they would both result in worse quality than standard pbr.

@LunaCapra
Copy link
Contributor

that's a fair point, however i could say the same thing about per-vertex or lambert lighting. unless i am mistaken and there are real uses for these, they would both result in worse quality than standard pbr.

In my experience per-vertex shading and lambert diffuse are commonly used "good enough" modes that are cheaper to compute, especially for particles/alpha materials that fill the screen
I haven't seen a reason to use affine texture mapping other than emulating an old aesthetic

@JekSun97
Copy link
Contributor

Similar to reasoning to avoiding palettes colors in images, I would think that adding a mode that makes quality worse for a PBR engine would be weird.

Adding vertex lighting is also considered a rendering degradation, but this did not prevent it from becoming part of Godot.

@fire
Copy link
Member

fire commented Dec 15, 2025

I think vertex lighting was resisted for several godot 4 versions and was not in 4.0

@clayjohn
Copy link
Member

See the discussion here: #78104

My preference would be to add the noperspective mode to varyings in the Godot Shader Language so users can use it in custom shaders. My sense is that most people doing PSX shaders go for the full aesthetic (crunchy textures, vertex snapping, affine texture mapping, dithering, etc.). So just adding affine texture mapping won't be enough. If we add noperspective, then anyone can easily use it and the code in BaseMaterial would become extremely simple

@tkpmonke
Copy link
Author

See the discussion here: #78104

My preference would be to add the noperspective mode to varyings in the Godot Shader Language so users can use it in custom shaders. My sense is that most people doing PSX shaders go for the full aesthetic (crunchy textures, vertex snapping, affine texture mapping, dithering, etc.). So just adding affine texture mapping won't be enough. If we add noperspective, then anyone can easily use it and the code in BaseMaterial would become extremely simple

I do agree that this would be a good change and one I'm willing to make, however would it even be possible to modify the shader compiler to do such a thing on low end hardware? I'm not familiar with how the shader compiler works so I can't say. I will try to get something working, and come back when I do.

@tkpmonke
Copy link
Author

tkpmonke commented Dec 16, 2025

After a few hours of work, I was able to hack in support for noperspective on all rendering targets. The gl_compatibility renderer uses a similar technique to what this PR does to BaseMaterial3D, however it modifies the GLSL output instead of doing it in glslang. mobile and forward_plus use the noperspective keyword inside of GLSL. I'm unsure if I should commit this change to this PR or make another one, as this changes the fundamental purpose of the PR.

Guidance would be appreciated, for now I'll keep the changes local and await further instructions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants