forked from amethyst/amethyst
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify structure of shaders to allow for includes and Makefile respec…
…tively The new structure allows for includes to reuse as much shader code as possible.
- Loading branch information
Showing
7 changed files
with
129 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Environment shader definition. | ||
// Set 0. | ||
// Keep in sync with amethyst_rendy/src/submodules/environment.rs | ||
|
||
struct PointLight { | ||
vec3 position; | ||
vec3 color; | ||
float intensity; | ||
}; | ||
|
||
struct DirectionalLight { | ||
vec3 color; | ||
float intensity; | ||
vec3 direction; | ||
}; | ||
|
||
struct SpotLight { | ||
vec3 position; | ||
vec3 color; | ||
vec3 direction; | ||
float angle; | ||
float intensity; | ||
float range; | ||
float smoothness; | ||
}; | ||
|
||
layout(std140, set = 0, binding = 1) uniform Environment { | ||
vec3 ambient_color; | ||
vec3 camera_position; | ||
int point_light_count; | ||
int directional_light_count; | ||
int spot_light_count; | ||
}; | ||
|
||
layout(std140, set = 0, binding = 2) uniform PointLights { | ||
PointLight plight[128]; | ||
}; | ||
|
||
layout(std140, set = 0, binding = 3) uniform DirectionalLights { | ||
DirectionalLight dlight[16]; | ||
}; | ||
|
||
layout(std140, set = 0, binding = 4) uniform SpotLights { | ||
SpotLight slight[128]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#ifndef MATH_FRAG | ||
#define MATH_FRAG | ||
|
||
const float PI = 3.14159265359; | ||
|
||
struct UvOffset { | ||
vec2 u_offset; | ||
vec2 v_offset; | ||
}; | ||
|
||
float tex_coord(float coord, vec2 offset) { | ||
return offset.x + coord * (offset.y - offset.x); | ||
} | ||
|
||
vec2 tex_coords(vec2 coord, UvOffset offset) { | ||
return vec2(tex_coord(coord.x, offset.u_offset), tex_coord(coord.y, offset.v_offset)); | ||
} | ||
|
||
vec3 schlick_fresnel(float HdotV, vec3 fresnel_base) { | ||
return fresnel_base + (1.0 - fresnel_base) * pow(1.0 - HdotV, 5.0); | ||
} | ||
|
||
float ggx_normal_distribution(vec3 N, vec3 H, float a) { | ||
float a2 = a * a; | ||
float NdotH = max(dot(N, H), 0.0); | ||
float NdotH2 = NdotH*NdotH; | ||
|
||
float denom = (NdotH2 * (a2 - 1.0) + 1.0); | ||
denom = PI * denom * denom; | ||
|
||
return (a2 + 0.0000001) / denom; | ||
} | ||
|
||
float ggx_geometry(float NdotV, float NdotL, float r2) { | ||
float a1 = r2 + 1.0; | ||
float k = a1 * a1 / 8.0; | ||
float denom = NdotV * (1.0 - k) + k; | ||
float ggx1 = NdotV / denom; | ||
denom = NdotL * (1.0 - k) + k; | ||
float ggx2 = NdotL / denom; | ||
return ggx1 * ggx2; | ||
} | ||
|
||
float s_curve (float x) { | ||
x = x * 2.0 - 1.0; | ||
return -x * abs(x) * 0.5 + x + 0.5; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef | ||
SKINNING_LOC_VERTEX | ||
#error "not defined" | ||
#endif | ||
|
||
#ifndef SKINNING_LOC_INSTANCE | ||
#define SKINNING_LOC_INSTANCE SKINNING_LOC_VERTEX + 1 | ||
#endif | ||
|
||
layout(location = SKINNING_LOC_INSTANCE) in uint joints_offset; // instance rate |