Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/shaders/surface_lib.glsl
| /** This describe the entire interface of the shader. */ | /** This describe the entire interface of the shader. */ | ||||
| #pragma BLENDER_REQUIRE(common_math_lib.glsl) | #pragma BLENDER_REQUIRE(common_math_lib.glsl) | ||||
| #pragma BLENDER_REQUIRE(common_math_lib.glsl) | #pragma BLENDER_REQUIRE(common_math_lib.glsl) | ||||
| /* Global interface for SSR. | |||||
| * SSR will set these global variables itself. | |||||
| * Also make false positive compiler warnings disappear by setting values. */ | |||||
| #define SSR_INTERFACE \ | |||||
| vec3 worldPosition = vec3(0); \ | |||||
| vec3 viewPosition = vec3(0); \ | |||||
| vec3 worldNormal = vec3(0); \ | |||||
| vec3 viewNormal = vec3(0); | |||||
| /* Skip interface declaration when using create-info. */ | |||||
| #ifndef USE_GPU_SHADER_CREATE_INFO | |||||
| #define SURFACE_INTERFACE \ | # define SURFACE_INTERFACE \ | ||||
| vec3 worldPosition; \ | vec3 worldPosition; \ | ||||
| vec3 viewPosition; \ | vec3 viewPosition; \ | ||||
| vec3 worldNormal; \ | vec3 worldNormal; \ | ||||
| vec3 viewNormal; | vec3 viewNormal; | ||||
| #ifndef IN_OUT | # ifndef IN_OUT | ||||
| # if defined(GPU_VERTEX_SHADER) | # if defined(GPU_VERTEX_SHADER) | ||||
| # define IN_OUT out | # define IN_OUT out | ||||
| # elif defined(GPU_FRAGMENT_SHADER) | # elif defined(GPU_FRAGMENT_SHADER) | ||||
| # define IN_OUT in | # define IN_OUT in | ||||
| # endif | # endif | ||||
| #endif | # endif | ||||
| #ifndef EEVEE_GENERATED_INTERFACE | # ifndef EEVEE_GENERATED_INTERFACE | ||||
| # if defined(STEP_RESOLVE) || defined(STEP_RAYTRACE) | # if defined(STEP_RESOLVE) || defined(STEP_RAYTRACE) | ||||
| /* SSR will set these global variables itself. | |||||
| * Also make false positive compiler warnings disappear by setting values. */ | SSR_INTERFACE | ||||
| vec3 worldPosition = vec3(0); | |||||
| vec3 viewPosition = vec3(0); | |||||
| vec3 worldNormal = vec3(0); | |||||
| vec3 viewNormal = vec3(0); | |||||
| # elif defined(GPU_GEOMETRY_SHADER) | # elif defined(GPU_GEOMETRY_SHADER) | ||||
| in ShaderStageInterface{SURFACE_INTERFACE} dataIn[]; | in ShaderStageInterface{SURFACE_INTERFACE} dataIn[]; | ||||
| out ShaderStageInterface{SURFACE_INTERFACE} dataOut; | out ShaderStageInterface{SURFACE_INTERFACE} dataOut; | ||||
| # define PASS_SURFACE_INTERFACE(vert) \ | # define PASS_SURFACE_INTERFACE(vert) \ | ||||
| dataOut.worldPosition = dataIn[vert].worldPosition; \ | dataOut.worldPosition = dataIn[vert].worldPosition; \ | ||||
| dataOut.viewPosition = dataIn[vert].viewPosition; \ | dataOut.viewPosition = dataIn[vert].viewPosition; \ | ||||
| dataOut.worldNormal = dataIn[vert].worldNormal; \ | dataOut.worldNormal = dataIn[vert].worldNormal; \ | ||||
| dataOut.viewNormal = dataIn[vert].viewNormal; | dataOut.viewNormal = dataIn[vert].viewNormal; | ||||
| # else /* GPU_VERTEX_SHADER || GPU_FRAGMENT_SHADER*/ | # else /* GPU_VERTEX_SHADER || GPU_FRAGMENT_SHADER*/ | ||||
| IN_OUT ShaderStageInterface{SURFACE_INTERFACE}; | IN_OUT ShaderStageInterface{SURFACE_INTERFACE}; | ||||
| # endif | # endif | ||||
| #endif /* EEVEE_GENERATED_INTERFACE */ | # endif /* EEVEE_GENERATED_INTERFACE */ | ||||
| #ifdef HAIR_SHADER | # ifdef HAIR_SHADER | ||||
| IN_OUT ShaderHairInterface | IN_OUT ShaderHairInterface | ||||
| { | { | ||||
| /* world space */ | /* world space */ | ||||
| vec3 hairTangent; | vec3 hairTangent; | ||||
| float hairThickTime; | float hairThickTime; | ||||
| float hairThickness; | float hairThickness; | ||||
| float hairTime; | float hairTime; | ||||
| flat int hairStrandID; | flat int hairStrandID; | ||||
| vec2 hairBary; | vec2 hairBary; | ||||
| }; | }; | ||||
| #endif | # endif | ||||
| #ifdef POINTCLOUD_SHADER | # ifdef POINTCLOUD_SHADER | ||||
| IN_OUT ShaderPointCloudInterface | IN_OUT ShaderPointCloudInterface | ||||
| { | { | ||||
| /* world space */ | /* world space */ | ||||
| float pointRadius; | float pointRadius; | ||||
| float pointPosition; | float pointPosition; | ||||
| flat int pointID; | flat int pointID; | ||||
| }; | }; | ||||
| #endif | # endif | ||||
| #else | |||||
| /** Checks to ensure create-info is setup correctly. **/ | |||||
| # ifdef HAIR_SHADER | |||||
| # ifndef USE_SURFACE_LIB_HAIR | |||||
| #error Ensure CreateInfo eevee_legacy_surface_lib_hair is included if using surface library with a hair shader. | |||||
| # endif | |||||
| # endif | |||||
| # ifdef POINTCLOUD_SHADER | |||||
| # ifndef USE_SURFACE_LIB_POINTCLOUD | |||||
| #error Ensure CreateInfo eevee_legacy_surface_lib_pointcloud is included if using surface library with a hair shader. | |||||
| # endif | |||||
| # endif | |||||
| /* SSR Global Interface. */ | |||||
| # if defined(STEP_RESOLVE) || defined(STEP_RAYTRACE) | |||||
| SSR_INTERFACE | |||||
| # endif | |||||
| #endif /* USE_GPU_SHADER_CREATE_INFO */ | |||||
| #if defined(GPU_FRAGMENT_SHADER) && defined(CODEGEN_LIB) | #if defined(GPU_FRAGMENT_SHADER) && defined(CODEGEN_LIB) | ||||
| # if defined(USE_BARYCENTRICS) && !defined(HAIR_SHADER) | # if defined(USE_BARYCENTRICS) && !defined(HAIR_SHADER) | ||||
| vec3 barycentric_distances_get() | vec3 barycentric_distances_get() | ||||
| { | { | ||||
| /* NOTE: No need to undo perspective divide since it is not applied yet. */ | /* NOTE: No need to undo perspective divide since it is not applied yet. */ | ||||
| vec3 pos0 = (ProjectionMatrixInverse * gpu_position_at_vertex(0)).xyz; | vec3 pos0 = (ProjectionMatrixInverse * gpu_position_at_vertex(0)).xyz; | ||||
| vec3 pos1 = (ProjectionMatrixInverse * gpu_position_at_vertex(1)).xyz; | vec3 pos1 = (ProjectionMatrixInverse * gpu_position_at_vertex(1)).xyz; | ||||
| ▲ Show 20 Lines • Show All 130 Lines • Show Last 20 Lines | |||||