Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/shaders/common_view_lib.glsl
| /* WORKAROUND: to guard against double include in EEVEE. */ | /* WORKAROUND: to guard against double include in EEVEE. */ | ||||
| #ifndef COMMON_VIEW_LIB_GLSL | #ifndef COMMON_VIEW_LIB_GLSL | ||||
| #define COMMON_VIEW_LIB_GLSL | #define COMMON_VIEW_LIB_GLSL | ||||
| /* Temporary until we fully make the switch. */ | /* Temporary until we fully make the switch. */ | ||||
| #if !defined(USE_GPU_SHADER_CREATE_INFO) | #if !defined(USE_GPU_SHADER_CREATE_INFO) | ||||
| # define DRW_RESOURCE_CHUNK_LEN 512 | # define DRW_RESOURCE_CHUNK_LEN 512 | ||||
| /* keep in sync with DRWManager.view_data */ | /* keep in sync with DRWManager.view_data */ | ||||
| layout(std140) uniform viewBlock | layout(std140) uniform viewBlock | ||||
| { | { | ||||
| /* Same order as DRWViewportMatrixType */ | |||||
| mat4 ViewProjectionMatrix; | |||||
| mat4 ViewProjectionMatrixInverse; | |||||
| mat4 ViewMatrix; | mat4 ViewMatrix; | ||||
| mat4 ViewMatrixInverse; | mat4 ViewMatrixInverse; | ||||
| mat4 ProjectionMatrix; | mat4 ProjectionMatrix; | ||||
| mat4 ProjectionMatrixInverse; | mat4 ProjectionMatrixInverse; | ||||
| vec4 clipPlanes[6]; | vec4 clipPlanes[6]; | ||||
| /* View frustum corners [NDC(-1.0, -1.0, -1.0) & NDC(1.0, 1.0, 1.0)]. | /* View frustum corners [NDC(-1.0, -1.0, -1.0) & NDC(1.0, 1.0, 1.0)]. | ||||
| Show All 31 Lines | |||||
| # define world_clip_planes_calc_clip_distance(p) \ | # define world_clip_planes_calc_clip_distance(p) \ | ||||
| _world_clip_planes_calc_clip_distance(p, clipPlanes) | _world_clip_planes_calc_clip_distance(p, clipPlanes) | ||||
| #endif | #endif | ||||
| #ifdef COMMON_GLOBALS_LIB | #ifdef COMMON_GLOBALS_LIB | ||||
| /* TODO move to overlay engine. */ | /* TODO move to overlay engine. */ | ||||
| float mul_project_m4_v3_zfac(in vec3 co) | float mul_project_m4_v3_zfac(in vec3 co) | ||||
| { | { | ||||
| return pixelFac * ((ViewProjectionMatrix[0][3] * co.x) + (ViewProjectionMatrix[1][3] * co.y) + | vec3 vP = (ViewMatrix * vec4(co, 1.0)).xyz; | ||||
| (ViewProjectionMatrix[2][3] * co.z) + ViewProjectionMatrix[3][3]); | return pixelFac * ((ProjectionMatrix[0][3] * vP.x) + (ProjectionMatrix[1][3] * vP.y) + | ||||
| (ProjectionMatrix[2][3] * vP.z) + ProjectionMatrix[3][3]); | |||||
| } | } | ||||
| #endif | #endif | ||||
| /* Not the right place but need to be common to all overlay's. | /* Not the right place but need to be common to all overlay's. | ||||
| * TODO: Split to an overlay lib. */ | * TODO: Split to an overlay lib. */ | ||||
| mat4 extract_matrix_packed_data(mat4 mat, out vec4 dataA, out vec4 dataB) | mat4 extract_matrix_packed_data(mat4 mat, out vec4 dataA, out vec4 dataB) | ||||
| { | { | ||||
| const float div = 1.0 / 255.0; | const float div = 1.0 / 255.0; | ||||
| ▲ Show 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | |||||
| #define NormalMatrixInverse transpose(mat3(ModelMatrix)) | #define NormalMatrixInverse transpose(mat3(ModelMatrix)) | ||||
| #define normal_object_to_view(n) (mat3(ViewMatrix) * (NormalMatrix * n)) | #define normal_object_to_view(n) (mat3(ViewMatrix) * (NormalMatrix * n)) | ||||
| #define normal_object_to_world(n) (NormalMatrix * n) | #define normal_object_to_world(n) (NormalMatrix * n) | ||||
| #define normal_world_to_object(n) (NormalMatrixInverse * n) | #define normal_world_to_object(n) (NormalMatrixInverse * n) | ||||
| #define normal_world_to_view(n) (mat3(ViewMatrix) * n) | #define normal_world_to_view(n) (mat3(ViewMatrix) * n) | ||||
| #define normal_view_to_world(n) (mat3(ViewMatrixInverse) * n) | #define normal_view_to_world(n) (mat3(ViewMatrixInverse) * n) | ||||
| #define point_object_to_ndc(p) (ViewProjectionMatrix * vec4((ModelMatrix * vec4(p, 1.0)).xyz, 1.0)) | #define point_object_to_ndc(p) \ | ||||
| (ProjectionMatrix * (ViewMatrix * vec4((ModelMatrix * vec4(p, 1.0)).xyz, 1.0))) | |||||
| #define point_object_to_view(p) ((ViewMatrix * vec4((ModelMatrix * vec4(p, 1.0)).xyz, 1.0)).xyz) | #define point_object_to_view(p) ((ViewMatrix * vec4((ModelMatrix * vec4(p, 1.0)).xyz, 1.0)).xyz) | ||||
| #define point_object_to_world(p) ((ModelMatrix * vec4(p, 1.0)).xyz) | #define point_object_to_world(p) ((ModelMatrix * vec4(p, 1.0)).xyz) | ||||
| #define point_view_to_ndc(p) (ProjectionMatrix * vec4(p, 1.0)) | #define point_view_to_ndc(p) (ProjectionMatrix * vec4(p, 1.0)) | ||||
| #define point_view_to_object(p) ((ModelMatrixInverse * (ViewMatrixInverse * vec4(p, 1.0))).xyz) | #define point_view_to_object(p) ((ModelMatrixInverse * (ViewMatrixInverse * vec4(p, 1.0))).xyz) | ||||
| #define point_view_to_world(p) ((ViewMatrixInverse * vec4(p, 1.0)).xyz) | #define point_view_to_world(p) ((ViewMatrixInverse * vec4(p, 1.0)).xyz) | ||||
| #define point_world_to_ndc(p) (ViewProjectionMatrix * vec4(p, 1.0)) | #define point_world_to_ndc(p) (ProjectionMatrix * (ViewMatrix * vec4(p, 1.0))) | ||||
| #define point_world_to_object(p) ((ModelMatrixInverse * vec4(p, 1.0)).xyz) | #define point_world_to_object(p) ((ModelMatrixInverse * vec4(p, 1.0)).xyz) | ||||
| #define point_world_to_view(p) ((ViewMatrix * vec4(p, 1.0)).xyz) | #define point_world_to_view(p) ((ViewMatrix * vec4(p, 1.0)).xyz) | ||||
| /* Due to some shader compiler bug, we somewhat need to access gl_VertexID | /* Due to some shader compiler bug, we somewhat need to access gl_VertexID | ||||
| * to make vertex shaders work. even if it's actually dead code. */ | * to make vertex shaders work. even if it's actually dead code. */ | ||||
| #if defined(GPU_INTEL) && defined(GPU_OPENGL) | #if defined(GPU_INTEL) && defined(GPU_OPENGL) | ||||
| # define GPU_INTEL_VERTEX_SHADER_WORKAROUND gl_Position.x = float(gl_VertexID); | # define GPU_INTEL_VERTEX_SHADER_WORKAROUND gl_Position.x = float(gl_VertexID); | ||||
| #else | #else | ||||
| ▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines | |||||