Refactor: GLSL: Cleanup Clip Space vs. NDC Space naming #105423

Closed
Prakhar-Singh-Chouhan wants to merge 15 commits from (deleted):fix#105070 into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Contributor

The list of things done:

  • AlL variable names that contain ndc_ are changed to hs_ (short for homogeneous space) if they are coming from a projection matrix multiplication without division.
  • Check all function names that contain ndc and change them to homogenous if they are working with the homogeneous space.
  • Renamed point_view_to_ndc to point_view_to_homogenous.
  • Renamed point_world_to_ndc to point_world_to_homogenous.
  • Renamed point_object_to_ndc to point_object_to_homogenous.

gl_Location is kept in homogeneous space.

Resolves #105070

The list of things done: * AlL variable names that contain `ndc_` are changed to `hs_` (short for homogeneous space) if they are coming from a projection matrix multiplication without division. * Check all function names that contain `ndc` and change them to `homogenous` if they are working with the homogeneous space. * Renamed `point_view_to_ndc` to `point_view_to_homogenous`. * Renamed `point_world_to_ndc` to `point_world_to_homogenous`. * Renamed `point_object_to_ndc` to `point_object_to_homogenous`. `gl_Location` is kept in homogeneous space. Resolves #105070
Prakhar-Singh-Chouhan added 6 commits 2023-03-03 23:40:48 +01:00
Prakhar-Singh-Chouhan requested review from Clément Foucault 2023-03-03 23:41:55 +01:00
Clément Foucault requested changes 2023-03-04 07:03:01 +01:00
Clément Foucault left a comment
Member

Thanks for tackling this task! Seems all good.
There is just a few minor issues and some suggestions about better renaming.

Thanks for tackling this task! Seems all good. There is just a few minor issues and some suggestions about better renaming.
@ -84,4 +84,4 @@
vec2 stippleStart1 = stipplePos1;
/* Geometry shader equivalent calculations. */
vec2 ss_pos[2];

This should become ndc_pos since it is the position after the division.

This should become `ndc_pos` since it is the position after the division.
fclem marked this conversation as resolved
@ -46,3 +46,3 @@
if (hairThicknessRes > 1) {
/* Calculate the thickness, thicktime, worldpos taken into account the outline. */
float outline_width = point_world_to_ndc(center_wpos).w * 1.25 * sizeViewportInv.y *
float outline_width = point_world_to_homogenous (center_wpos).w * 1.25 * sizeViewportInv.y *

Did you run make format? there is an extra blank space here that should have been fixed by clang format.

Did you run `make format`? there is an extra blank space here that should have been fixed by clang format.
fclem marked this conversation as resolved
@ -34,3 +34,2 @@
vec3 isect = ray_plane_intersection(ray_ori, ray_dir, gpDepthPlane);
vec4 ndc = point_world_to_ndc(isect);
gl_FragDepth = (ndc.z / ndc.w) * 0.5 + 0.5;
vec4 hs = point_world_to_homogenous(isect);

Rename to hs_isect.

Rename to `hs_isect`.
fclem marked this conversation as resolved
@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
f#pragma BLENDER_REQUIRE(common_view_lib.glsl)

An extra "f" is present at the beginning of the line. Seems like it was committed by mistake.

An extra "f" is present at the beginning of the line. Seems like it was committed by mistake.
@ -223,3 +223,1 @@
vec4 ndc_adj = point_world_to_ndc(wpos_adj);
vec4 ndc1 = point_world_to_ndc(wpos1);
vec4 ndc2 = point_world_to_ndc(wpos2);
vec4 hs_adj = point_world_to_hs(wpos_adj);

Rename to hs_pos_adj.

Rename to `hs_pos_adj`.
fclem marked this conversation as resolved
@ -224,2 +223,2 @@
vec4 ndc1 = point_world_to_ndc(wpos1);
vec4 ndc2 = point_world_to_ndc(wpos2);
vec4 hs_adj = point_world_to_hs(wpos_adj);
vec4 hs1 = point_world_to_homogenous(wpos1);

Rename to hs_pos1 and hs_pos2.

Rename to `hs_pos1` and `hs_pos2`.
fclem marked this conversation as resolved
Prakhar-Singh-Chouhan added 1 commit 2023-03-04 08:13:23 +01:00
Author
Contributor

@fclem I did the changes asked, could you review it once ?

@fclem I did the changes asked, could you review it once ?
Prakhar-Singh-Chouhan requested review from Clément Foucault 2023-03-04 08:15:48 +01:00
Clément Foucault approved these changes 2023-03-04 18:48:52 +01:00

The patch looks good. But there are some merge conflicts on two files. You need to merge main to your branch git merge main and then push your updates.

The patch looks good. But there are some merge conflicts on two files. You need to merge main to your branch `git merge main` and then push your updates.
Prakhar-Singh-Chouhan added 1 commit 2023-03-04 20:18:39 +01:00
Author
Contributor

@fclem merge conflict resolved

@fclem merge conflict resolved
Clément Foucault requested changes 2023-03-04 21:08:03 +01:00
Clément Foucault left a comment
Member

The PR still contain the conflicts. You need to manually edit these to keep both your changes and the incoming changes. Also try to build with WITH_GPU_SHADER_BUILDER to test all shaders compile (see this and this).

The PR still contain the conflicts. You need to manually edit these to keep both your changes and the incoming changes. Also try to build with `WITH_GPU_SHADER_BUILDER` to test all shaders compile (see [this](https://wiki.blender.org/wiki/Building_Blender/Options#Editing_CMake_Options) and [this](https://wiki.blender.org/wiki/EEVEE_%26_Viewport/GPU_Module/GLSL_Cross_Compilation#ShaderBuilder)).
@ -29,11 +29,15 @@ void main()
GPU_INTEL_VERTEX_SHADER_WORKAROUND
vec3 world_pos = point_object_to_world(pos);
<<<<<<< HEAD

Here.

Here.
fclem marked this conversation as resolved
@ -82,6 +82,10 @@ void main()
vec3 world_pos0 = point_object_to_world(in_pos0);
vec3 world_pos1 = point_object_to_world(in_pos1);
<<<<<<< HEAD

Here

Here
fclem marked this conversation as resolved
Prakhar-Singh-Chouhan added 1 commit 2023-03-05 08:39:33 +01:00
Prakhar-Singh-Chouhan requested review from Clément Foucault 2023-03-05 08:40:53 +01:00
Clément Foucault requested review from Jeroen Bakker 2023-03-06 15:56:37 +01:00
Clément Foucault refused to review 2023-03-06 15:56:41 +01:00
Jeroen Bakker requested changes 2023-03-06 17:58:36 +01:00
@ -0,0 +1,56 @@
# This is the CMakeCache file.
Member

This file should not be part of the PR.
I believe you used ccmake . from within the source folder. This generates some files that should not be committed.

This file should not be part of the PR. I believe you used `ccmake .` from within the source folder. This generates some files that should not be committed.
@ -0,0 +1 @@
# This file is generated by cmake for dependency checking of the CMakeCache.txt file
Member

Same here. this file should not be part of this PR.

Same here. this file should not be part of this PR.
Author
Contributor

ohhh i'll remove them manually then

ohhh i'll remove them manually then
Prakhar-Singh-Chouhan added 1 commit 2023-03-06 18:20:47 +01:00
Prakhar-Singh-Chouhan added 1 commit 2023-03-06 18:23:46 +01:00
Prakhar-Singh-Chouhan requested review from Jeroen Bakker 2023-03-06 18:24:28 +01:00
Clément Foucault requested changes 2023-03-06 18:34:28 +01:00
@ -31,3 +31,4 @@
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_homogenous(world_pos);
vec3 view_pos = point_world_to_view(world_pos);
gl_Position = point_view_to_ndc(view_pos);

You still need to fix the merge errors. This will not compile as point_view_to_ndc does not exist anymore.
You only removed the merge tags, but you need to remove what was below the <<<<<<< HEAD and do the renaming of what was above >>>>>>> main.

You still need to fix the merge errors. This will not compile as `point_view_to_ndc` does not exist anymore. You only removed the merge tags, but you need to remove what was below the `<<<<<<< HEAD` and do the renaming of what was above `>>>>>>> main`.
fclem marked this conversation as resolved
@ -84,2 +84,4 @@
vec3 world_pos1 = point_object_to_world(in_pos1);
vec4 out_pos0 = point_world_to_homogenous(world_pos0);
vec4 out_pos1 = point_world_to_homogenous(world_pos1);
vec3 view_pos0 = point_world_to_view(world_pos0);

Same thing here.

Same thing here.
fclem marked this conversation as resolved
Prakhar-Singh-Chouhan added 1 commit 2023-03-07 06:44:49 +01:00
Prakhar-Singh-Chouhan added 1 commit 2023-03-07 06:46:23 +01:00
Prakhar-Singh-Chouhan added 1 commit 2023-03-07 06:49:25 +01:00
Prakhar-Singh-Chouhan requested review from Clément Foucault 2023-03-07 06:50:24 +01:00
Author
Contributor

@fclem @Jeroen-Bakker done the changes you asked for...

@fclem @Jeroen-Bakker done the changes you asked for...
Clément Foucault approved these changes 2023-03-07 15:18:29 +01:00
Clément Foucault added 1 commit 2023-03-07 15:53:34 +01:00
Member

Most shaders don't compile anymore. on Mesa/AMD

Shader Test compilation result: 218 / 764 passed (skipped 10 for compatibility reasons)
Shader compilation failed for OpenGL backend

ERROR (gpu.shader): workbench_next_prepass_mesh_opaque_flat_vertex_no_clip VertShader: 
      | 
  876 | vec3 point_view_to_homogenous(vec3 p)
      |       ^
      | common_view_lib.glsl:245:7: Error: function `point_view_to_homogenous' return type doesn't match prototype
      | common_view_lib.glsl:245:7: Error: function `point_view_to_homogenous' redefined
      | 
  878 |   return (ViewMatrixInverse * vec4(p, 1.0)).xyz;
      |   ^
      | common_view_lib.glsl:247:3: Error: could not implicitly convert return value to vec4, in function `point_view_to_homogenous'

ERROR (gpu.shader): workbench_next_prepass_mesh_opaque_flat_vertex_no_clip FragShader: 
      | 
  876 | vec3 point_view_to_homogenous(vec3 p)
      |       ^
      | common_view_lib.glsl:245:7: Error: function `point_view_to_homogenous' return type doesn't match prototype
      | common_view_lib.glsl:245:7: Error: function `point_view_to_homogenous' redefined
      | 
  878 |   return (ViewMatrixInverse * vec4(p, 1.0)).xyz;
      |   ^
      | common_view_lib.glsl:247:3: Error: could not implicitly convert return value to vec4, in function `point_view_to_homogenous'
Most shaders don't compile anymore. on Mesa/AMD ``` Shader Test compilation result: 218 / 764 passed (skipped 10 for compatibility reasons) Shader compilation failed for OpenGL backend ``` ``` ERROR (gpu.shader): workbench_next_prepass_mesh_opaque_flat_vertex_no_clip VertShader: | 876 | vec3 point_view_to_homogenous(vec3 p) | ^ | common_view_lib.glsl:245:7: Error: function `point_view_to_homogenous' return type doesn't match prototype | common_view_lib.glsl:245:7: Error: function `point_view_to_homogenous' redefined | 878 | return (ViewMatrixInverse * vec4(p, 1.0)).xyz; | ^ | common_view_lib.glsl:247:3: Error: could not implicitly convert return value to vec4, in function `point_view_to_homogenous' ERROR (gpu.shader): workbench_next_prepass_mesh_opaque_flat_vertex_no_clip FragShader: | 876 | vec3 point_view_to_homogenous(vec3 p) | ^ | common_view_lib.glsl:245:7: Error: function `point_view_to_homogenous' return type doesn't match prototype | common_view_lib.glsl:245:7: Error: function `point_view_to_homogenous' redefined | 878 | return (ViewMatrixInverse * vec4(p, 1.0)).xyz; | ^ | common_view_lib.glsl:247:3: Error: could not implicitly convert return value to vec4, in function `point_view_to_homogenous'
Jeroen Bakker requested changes 2023-03-08 13:53:53 +01:00
Jeroen Bakker left a comment
Member

Most shaders don't compile due to a redefinition.
You can enable WITH_GPU_BUILDTIME_SHADER_BUILDER to check them during compilation.

Most shaders don't compile due to a redefinition. You can enable `WITH_GPU_BUILDTIME_SHADER_BUILDER` to check them during compilation.
Brecht Van Lommel changed title from Fix#105070 GLSL: Cleanup Clip Space vs. NDC Space naming to Refactor: GLSL: Cleanup Clip Space vs. NDC Space naming 2023-03-10 13:56:07 +01:00

Pull request closed

Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#105423
No description provided.