mirror of https://github.com/bjornbytes/lovr.git
Default shaders use lovrmain;
This commit is contained in:
parent
2414f5f269
commit
50f596bd34
|
@ -5,8 +5,7 @@
|
|||
#include "lovr.glsl"
|
||||
|
||||
layout(set = 1, binding = 1) uniform textureCube SkyboxTexture;
|
||||
layout(location = 0) in vec3 Direction;
|
||||
|
||||
void main() {
|
||||
PixelColors[0] = Color * getPixel(SkyboxTexture, Direction);
|
||||
vec4 lovrmain() {
|
||||
return Color * getPixel(SkyboxTexture, Normal);
|
||||
}
|
||||
|
|
|
@ -4,11 +4,7 @@
|
|||
|
||||
#include "lovr.glsl"
|
||||
|
||||
layout(location = 0) out vec3 Direction;
|
||||
|
||||
void main() {
|
||||
Color = PassColor * VertexColor;
|
||||
|
||||
vec4 lovrmain() {
|
||||
const vec2 uvs[6] = vec2[6](
|
||||
vec2(-1, -1),
|
||||
vec2(-1, +1),
|
||||
|
@ -21,6 +17,6 @@ void main() {
|
|||
vec2 uv = uvs[VertexIndex % 6];
|
||||
vec3 ray = vec3(uv, -1.);
|
||||
mat3 inverseViewOrientation = transpose(mat3(View));
|
||||
Direction = normalize(inverseViewOrientation * (InverseProjection * vec4(ray, 1.)).xyz);
|
||||
Position = vec4(uv, 0, 1);
|
||||
Normal = normalize(inverseViewOrientation * (InverseProjection * vec4(ray, 1.)).xyz);
|
||||
return vec4(uv, 0, 1);
|
||||
}
|
||||
|
|
|
@ -2,16 +2,16 @@
|
|||
#extension GL_EXT_multiview : require
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
#define PI 3.141592653589793238462643383
|
||||
|
||||
#include "lovr.glsl"
|
||||
|
||||
#define PI 3.141592653589793238462643383
|
||||
|
||||
layout(location = 0) in vec3 Direction;
|
||||
|
||||
void main() {
|
||||
vec4 lovrmain() {
|
||||
vec3 dir = normalize(Direction);
|
||||
float phi = acos(dir.y);
|
||||
float theta = atan(dir.x, -dir.z);
|
||||
vec2 uv = vec2(.5 + theta / (2 * PI), phi / PI);
|
||||
PixelColors[0] = Color * getPixel(ColorTexture, uv);
|
||||
return Color * getPixel(ColorTexture, uv);
|
||||
}
|
||||
|
|
|
@ -4,11 +4,9 @@
|
|||
|
||||
#include "lovr.glsl"
|
||||
|
||||
void main() {
|
||||
Color = PassColor * VertexColor;
|
||||
vec4 lovrmain() {
|
||||
float x = -1 + float((VertexIndex & 1) << 2);
|
||||
float y = -1 + float((VertexIndex & 2) << 1);
|
||||
UV = vec2(x, y) * .5 + .5;
|
||||
Position = vec4(x, y, 1., 1.);
|
||||
PointSize = 1.f;
|
||||
return vec4(x, y, 1., 1.);
|
||||
}
|
||||
|
|
|
@ -14,11 +14,11 @@ float median(float r, float g, float b) {
|
|||
return max(min(r, g), min(max(r, g), b));
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 lovrmain() {
|
||||
vec3 msdf = getPixel(ColorTexture).rgb;
|
||||
float sdf = median(msdf.r, msdf.g, msdf.b);
|
||||
float screenPxDistance = screenPxRange() * (sdf - .5);
|
||||
float alpha = clamp(screenPxDistance + .5, 0., 1.);
|
||||
if (alpha <= 0.) discard;
|
||||
PixelColors[0] = vec4(Color.rgb, Color.a * alpha);
|
||||
return vec4(Color.rgb, Color.a * alpha);
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ layout(location = 12) in vec2 UV;
|
|||
#define WorldFromLocal (Transform)
|
||||
|
||||
#define DefaultPosition (ClipFromLocal * VertexPosition)
|
||||
#define DefaultColor (Color * MaterialColor * getPixel(ColorTexture))
|
||||
#define DefaultColor (Color * getPixel(ColorTexture))
|
||||
#endif
|
||||
|
||||
#ifdef GL_FRAGMENT_SHADER
|
||||
|
@ -121,3 +121,31 @@ vec4 getPixel(texture3D t, vec3 uvw) { return texture(sampler3D(t, Sampler), uvw
|
|||
vec4 getPixel(textureCube t, vec3 dir) { return texture(samplerCube(t, Sampler), dir); }
|
||||
vec4 getPixel(texture2DArray t, vec3 uvw) { return texture(sampler2DArray(t, Sampler), uvw); }
|
||||
#endif
|
||||
|
||||
// Entrypoints
|
||||
#ifndef NO_DEFAULT_MAIN
|
||||
#ifdef GL_VERTEX_SHADER
|
||||
vec4 lovrmain();
|
||||
void main() {
|
||||
Color = VertexColor * MaterialColor * PassColor;
|
||||
Normal = NormalMatrix * VertexNormal;
|
||||
UV = VertexUV;
|
||||
PointSize = 1.f;
|
||||
Position = lovrmain();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef GL_FRAGMENT_SHADER
|
||||
vec4 lovrmain();
|
||||
void main() {
|
||||
PixelColors[0] = lovrmain();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef GL_COMPUTE_SHADER
|
||||
vec4 lovrmain();
|
||||
void main() {
|
||||
lovrmain();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
|
||||
#include "lovr.glsl"
|
||||
|
||||
void main() {
|
||||
PixelColors[0] = Color * MaterialColor * getPixel(ColorTexture, UV);
|
||||
vec4 lovrmain() {
|
||||
return DefaultColor;
|
||||
}
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
|
||||
#include "lovr.glsl"
|
||||
|
||||
void main() {
|
||||
Color = PassColor * VertexColor;
|
||||
Normal = normalize(NormalMatrix * VertexNormal);
|
||||
UV = VertexUV;
|
||||
Position = DefaultPosition;
|
||||
PointSize = 1.f;
|
||||
vec4 lovrmain() {
|
||||
return DefaultPosition;
|
||||
}
|
||||
|
|
|
@ -1333,32 +1333,18 @@ ShaderSource lovrGraphicsCompileShader(ShaderStage stage, ShaderSource* source)
|
|||
"#extension GL_EXT_multiview : require\n"
|
||||
"#extension GL_GOOGLE_include_directive : require\n";
|
||||
|
||||
const char* suffixes[] = {
|
||||
[STAGE_VERTEX] = ""
|
||||
"void main() {"
|
||||
"Color = PassColor * VertexColor;"
|
||||
"Normal = NormalMatrix * VertexNormal;"
|
||||
"UV = VertexUV;"
|
||||
"Position = lovrmain();"
|
||||
"}",
|
||||
[STAGE_FRAGMENT] = "void main() { PixelColors[0] = lovrmain(); }",
|
||||
[STAGE_COMPUTE] = "void main() { lovrmain(); }"
|
||||
};
|
||||
|
||||
const char* strings[] = {
|
||||
prefix,
|
||||
(const char*) etc_shaders_lovr_glsl,
|
||||
"#line 1\n",
|
||||
source->code,
|
||||
suffixes[stage]
|
||||
source->code
|
||||
};
|
||||
|
||||
int lengths[] = {
|
||||
-1,
|
||||
etc_shaders_lovr_glsl_len,
|
||||
-1,
|
||||
source->size,
|
||||
-1
|
||||
source->size
|
||||
};
|
||||
|
||||
const glslang_resource_t* resource = glslang_default_resource();
|
||||
|
|
Loading…
Reference in New Issue