Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/shaders/common_view_lib.glsl
| Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | if (len > 0.0) { | ||||
| return vec4(perp * 0.5 + 0.5, dist * 0.25 + 0.5 + 0.1, 1.0); | return vec4(perp * 0.5 + 0.5, dist * 0.25 + 0.5 + 0.1, 1.0); | ||||
| } | } | ||||
| else { | else { | ||||
| /* Default line if the origin is perfectly aligned with a pixel. */ | /* Default line if the origin is perfectly aligned with a pixel. */ | ||||
| return vec4(1.0, 0.0, 0.5 + 0.1, 1.0); | return vec4(1.0, 0.0, 0.5 + 0.1, 1.0); | ||||
| } | } | ||||
| } | } | ||||
| uniform int resourceChunk; | /* Temporary until we fully make the switch. */ | ||||
| #ifndef DRW_SHADER_SHARED_H | |||||
| uniform int drw_resourceChunk; | |||||
| #endif /* DRW_SHADER_SHARED_H */ | |||||
| #ifdef GPU_VERTEX_SHADER | #ifdef GPU_VERTEX_SHADER | ||||
| # ifdef GPU_ARB_shader_draw_parameters | |||||
| # define baseInstance gl_BaseInstanceARB | |||||
| # else /* no ARB_shader_draw_parameters */ | |||||
| uniform int baseInstance; | |||||
| # endif | |||||
| # if defined(IN_PLACE_INSTANCES) || defined(INSTANCED_ATTR) | /* Temporary until we fully make the switch. */ | ||||
| # ifndef DRW_SHADER_SHARED_H | |||||
| /* clang-format off */ | |||||
| # if defined(IN_PLACE_INSTANCES) || defined(INSTANCED_ATTR) || defined(DRW_LEGACY_MODEL_MATRIX) || defined(GPU_DEPRECATED_AMD_DRIVER) | |||||
| /* clang-format on */ | |||||
| /* When drawing instances of an object at the same position. */ | /* When drawing instances of an object at the same position. */ | ||||
| # define instanceId 0 | # define instanceId 0 | ||||
| # elif defined(GPU_DEPRECATED_AMD_DRIVER) | |||||
| /* A driver bug make it so that when using an attribute with GL_INT_2_10_10_10_REV as format, | |||||
| * the gl_InstanceID is incremented by the 2 bit component of the attribute. | |||||
| * Ignore gl_InstanceID then. */ | |||||
| # define instanceId 0 | |||||
| # else | # else | ||||
| # define instanceId gl_InstanceID | # define instanceId gl_InstanceID | ||||
| # endif | # endif | ||||
| # ifdef UNIFORM_RESOURCE_ID | # if defined(UNIFORM_RESOURCE_ID) | ||||
| /* This is in the case we want to do a special instance drawcall but still want to have the | /* This is in the case we want to do a special instance drawcall for one object but still want to | ||||
| * right resourceId and all the correct ubo datas. */ | * have the right resourceId and all the correct ubo datas. */ | ||||
| uniform int resourceId; | uniform int drw_resourceId; | ||||
| # define resource_id resourceId | # define resource_id drw_resourceId | ||||
| # else | # else | ||||
| # define resource_id (baseInstance + instanceId) | # define resource_id (gpu_BaseInstance + instanceId) | ||||
| # endif | # endif | ||||
| /* Use this to declare and pass the value if | /* Use this to declare and pass the value if | ||||
| * the fragment shader uses the resource_id. */ | * the fragment shader uses the resource_id. */ | ||||
| # ifdef USE_GEOMETRY_SHADER | # ifdef USE_GEOMETRY_SHADER | ||||
| # define RESOURCE_ID_VARYING flat out int resourceIDGeom; | # define RESOURCE_ID_VARYING flat out int resourceIDGeom; | ||||
| # define PASS_RESOURCE_ID resourceIDGeom = resource_id; | # define PASS_RESOURCE_ID resourceIDGeom = resource_id; | ||||
| # else | # else | ||||
| # define RESOURCE_ID_VARYING flat out int resourceIDFrag; | # define RESOURCE_ID_VARYING flat out int resourceIDFrag; | ||||
| # define PASS_RESOURCE_ID resourceIDFrag = resource_id; | # define PASS_RESOURCE_ID resourceIDFrag = resource_id; | ||||
| # endif | # endif | ||||
| # endif /* DRW_SHADER_SHARED_H */ | |||||
| #endif /* GPU_VERTEX_SHADER */ | |||||
| /* Temporary until we fully make the switch. */ | |||||
| #ifdef DRW_SHADER_SHARED_H | |||||
| /* TODO(fclem): Rename PASS_RESOURCE_ID to DRW_RESOURCE_ID_VARYING_SET */ | |||||
| # if defined(UNIFORM_RESOURCE_ID) | |||||
| # define resource_id drw_ResourceID | |||||
| # define PASS_RESOURCE_ID | |||||
| # elif defined(GPU_VERTEX_SHADER) | |||||
| # define resource_id gpu_InstanceIndex | |||||
| # define PASS_RESOURCE_ID drw_ResourceID_iface.resource_index = resource_id; | |||||
| # elif defined(GPU_GEOMETRY_SHADER) | |||||
| # define resource_id drw_ResourceID_iface_in[0].index | |||||
| # define PASS_RESOURCE_ID drw_ResourceID_iface_out.resource_index = resource_id; | |||||
| # elif defined(GPU_FRAGMENT_SHADER) | |||||
| # define resource_id drw_ResourceID_iface.resource_index | |||||
| #endif | # endif | ||||
| /* TODO(fclem): Remove. */ | |||||
| # define RESOURCE_ID_VARYING | |||||
| #else | |||||
| /* If used in a fragment / geometry shader, we pass | /* If used in a fragment / geometry shader, we pass | ||||
| * resource_id as varying. */ | * resource_id as varying. */ | ||||
| #ifdef GPU_GEOMETRY_SHADER | # ifdef GPU_GEOMETRY_SHADER | ||||
| # define RESOURCE_ID_VARYING \ | # define RESOURCE_ID_VARYING \ | ||||
| flat out int resourceIDFrag; \ | flat out int resourceIDFrag; \ | ||||
| flat in int resourceIDGeom[]; | flat in int resourceIDGeom[]; | ||||
| # define resource_id resourceIDGeom | # define resource_id resourceIDGeom | ||||
| # define PASS_RESOURCE_ID resourceIDFrag = resource_id[0]; | # define PASS_RESOURCE_ID resourceIDFrag = resource_id[0]; | ||||
| #endif | # endif | ||||
| #ifdef GPU_FRAGMENT_SHADER | # ifdef GPU_FRAGMENT_SHADER | ||||
| flat in int resourceIDFrag; | flat in int resourceIDFrag; | ||||
| # define resource_id resourceIDFrag | # define resource_id resourceIDFrag | ||||
| #endif | # endif | ||||
| #endif | |||||
| /* Breaking this across multiple lines causes issues for some older GLSL compilers. */ | /* Breaking this across multiple lines causes issues for some older GLSL compilers. */ | ||||
| /* clang-format off */ | /* clang-format off */ | ||||
| #if !defined(GPU_INTEL) && !defined(GPU_DEPRECATED_AMD_DRIVER) && !defined(OS_MAC) && !defined(INSTANCED_ATTR) | #if !defined(GPU_INTEL) && !defined(GPU_DEPRECATED_AMD_DRIVER) && !defined(OS_MAC) && !defined(INSTANCED_ATTR) && !defined(DRW_LEGACY_MODEL_MATRIX) | ||||
| /* clang-format on */ | /* clang-format on */ | ||||
| /* Temporary until we fully make the switch. */ | /* Temporary until we fully make the switch. */ | ||||
| # ifndef DRW_SHADER_SHARED_H | # ifndef DRW_SHADER_SHARED_H | ||||
| struct ObjectMatrices { | struct ObjectMatrices { | ||||
| mat4 drw_modelMatrix; | mat4 drw_modelMatrix; | ||||
| mat4 drw_modelMatrixInverse; | mat4 drw_modelMatrixInverse; | ||||
| }; | }; | ||||
| layout(std140) uniform modelBlock | layout(std140) uniform modelBlock | ||||
| { | { | ||||
| ObjectMatrices drw_matrices[DRW_RESOURCE_CHUNK_LEN]; | ObjectMatrices drw_matrices[DRW_RESOURCE_CHUNK_LEN]; | ||||
| }; | }; | ||||
| # endif /* DRW_SHADER_SHARED_H */ | |||||
| # define ModelMatrix (drw_matrices[resource_id].drw_modelMatrix) | # define ModelMatrix (drw_matrices[resource_id].drw_modelMatrix) | ||||
| # define ModelMatrixInverse (drw_matrices[resource_id].drw_modelMatrixInverse) | # define ModelMatrixInverse (drw_matrices[resource_id].drw_modelMatrixInverse) | ||||
| # endif /* DRW_SHADER_SHARED_H */ | |||||
| #else /* GPU_INTEL */ | #else /* GPU_INTEL */ | ||||
| /* Temporary until we fully make the switch. */ | /* Temporary until we fully make the switch. */ | ||||
| # ifndef DRW_SHADER_SHARED_H | # ifndef DRW_SHADER_SHARED_H | ||||
| /* Intel GPU seems to suffer performance impact when the model matrix is in UBO storage. | /* Intel GPU seems to suffer performance impact when the model matrix is in UBO storage. | ||||
| * So for now we just force using the legacy path. */ | * So for now we just force using the legacy path. */ | ||||
| /* Note that this is also a workaround of a problem on osx (amd or nvidia) | /* Note that this is also a workaround of a problem on osx (amd or nvidia) | ||||
| * and older amd driver on windows. */ | * and older amd driver on windows. */ | ||||
| uniform mat4 ModelMatrix; | uniform mat4 ModelMatrix; | ||||
| uniform mat4 ModelMatrixInverse; | uniform mat4 ModelMatrixInverse; | ||||
| # endif /* DRW_SHADER_SHARED_H */ | # endif /* DRW_SHADER_SHARED_H */ | ||||
| #endif | #endif | ||||
| #define resource_handle (resourceChunk * DRW_RESOURCE_CHUNK_LEN + resource_id) | /* Temporary until we fully make the switch. */ | ||||
| #ifndef DRW_SHADER_SHARED_H | |||||
| # define resource_handle (drw_resourceChunk * DRW_RESOURCE_CHUNK_LEN + resource_id) | |||||
| #endif | |||||
| /** Transform shortcuts. */ | /** Transform shortcuts. */ | ||||
| /* Rule of thumb: Try to reuse world positions and normals because converting through viewspace | /* Rule of thumb: Try to reuse world positions and normals because converting through viewspace | ||||
| * will always be decomposed in at least 2 matrix operation. */ | * will always be decomposed in at least 2 matrix operation. */ | ||||
| /** | /** | ||||
| * Some clarification: | * Some clarification: | ||||
| * Usually Normal matrix is transpose(inverse(ViewMatrix * ModelMatrix)) | * Usually Normal matrix is transpose(inverse(ViewMatrix * ModelMatrix)) | ||||
| ▲ Show 20 Lines • Show All 116 Lines • Show Last 20 Lines | |||||