Default shaders use lovrmain;

This commit is contained in:
bjorn 2022-07-31 11:18:15 -07:00
parent 2414f5f269
commit 50f596bd34
9 changed files with 48 additions and 45 deletions

View File

@ -5,8 +5,7 @@
#include "lovr.glsl" #include "lovr.glsl"
layout(set = 1, binding = 1) uniform textureCube SkyboxTexture; layout(set = 1, binding = 1) uniform textureCube SkyboxTexture;
layout(location = 0) in vec3 Direction;
void main() { vec4 lovrmain() {
PixelColors[0] = Color * getPixel(SkyboxTexture, Direction); return Color * getPixel(SkyboxTexture, Normal);
} }

View File

@ -4,11 +4,7 @@
#include "lovr.glsl" #include "lovr.glsl"
layout(location = 0) out vec3 Direction; vec4 lovrmain() {
void main() {
Color = PassColor * VertexColor;
const vec2 uvs[6] = vec2[6]( const vec2 uvs[6] = vec2[6](
vec2(-1, -1), vec2(-1, -1),
vec2(-1, +1), vec2(-1, +1),
@ -21,6 +17,6 @@ void main() {
vec2 uv = uvs[VertexIndex % 6]; vec2 uv = uvs[VertexIndex % 6];
vec3 ray = vec3(uv, -1.); vec3 ray = vec3(uv, -1.);
mat3 inverseViewOrientation = transpose(mat3(View)); mat3 inverseViewOrientation = transpose(mat3(View));
Direction = normalize(inverseViewOrientation * (InverseProjection * vec4(ray, 1.)).xyz); Normal = normalize(inverseViewOrientation * (InverseProjection * vec4(ray, 1.)).xyz);
Position = vec4(uv, 0, 1); return vec4(uv, 0, 1);
} }

View File

@ -2,16 +2,16 @@
#extension GL_EXT_multiview : require #extension GL_EXT_multiview : require
#extension GL_GOOGLE_include_directive : require #extension GL_GOOGLE_include_directive : require
#define PI 3.141592653589793238462643383
#include "lovr.glsl" #include "lovr.glsl"
#define PI 3.141592653589793238462643383
layout(location = 0) in vec3 Direction; layout(location = 0) in vec3 Direction;
void main() { vec4 lovrmain() {
vec3 dir = normalize(Direction); vec3 dir = normalize(Direction);
float phi = acos(dir.y); float phi = acos(dir.y);
float theta = atan(dir.x, -dir.z); float theta = atan(dir.x, -dir.z);
vec2 uv = vec2(.5 + theta / (2 * PI), phi / PI); vec2 uv = vec2(.5 + theta / (2 * PI), phi / PI);
PixelColors[0] = Color * getPixel(ColorTexture, uv); return Color * getPixel(ColorTexture, uv);
} }

View File

@ -4,11 +4,9 @@
#include "lovr.glsl" #include "lovr.glsl"
void main() { vec4 lovrmain() {
Color = PassColor * VertexColor;
float x = -1 + float((VertexIndex & 1) << 2); float x = -1 + float((VertexIndex & 1) << 2);
float y = -1 + float((VertexIndex & 2) << 1); float y = -1 + float((VertexIndex & 2) << 1);
UV = vec2(x, y) * .5 + .5; UV = vec2(x, y) * .5 + .5;
Position = vec4(x, y, 1., 1.); return vec4(x, y, 1., 1.);
PointSize = 1.f;
} }

View File

@ -14,11 +14,11 @@ float median(float r, float g, float b) {
return max(min(r, g), min(max(r, g), b)); return max(min(r, g), min(max(r, g), b));
} }
void main() { vec4 lovrmain() {
vec3 msdf = getPixel(ColorTexture).rgb; vec3 msdf = getPixel(ColorTexture).rgb;
float sdf = median(msdf.r, msdf.g, msdf.b); float sdf = median(msdf.r, msdf.g, msdf.b);
float screenPxDistance = screenPxRange() * (sdf - .5); float screenPxDistance = screenPxRange() * (sdf - .5);
float alpha = clamp(screenPxDistance + .5, 0., 1.); float alpha = clamp(screenPxDistance + .5, 0., 1.);
if (alpha <= 0.) discard; if (alpha <= 0.) discard;
PixelColors[0] = vec4(Color.rgb, Color.a * alpha); return vec4(Color.rgb, Color.a * alpha);
} }

View File

@ -111,7 +111,7 @@ layout(location = 12) in vec2 UV;
#define WorldFromLocal (Transform) #define WorldFromLocal (Transform)
#define DefaultPosition (ClipFromLocal * VertexPosition) #define DefaultPosition (ClipFromLocal * VertexPosition)
#define DefaultColor (Color * MaterialColor * getPixel(ColorTexture)) #define DefaultColor (Color * getPixel(ColorTexture))
#endif #endif
#ifdef GL_FRAGMENT_SHADER #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(textureCube t, vec3 dir) { return texture(samplerCube(t, Sampler), dir); }
vec4 getPixel(texture2DArray t, vec3 uvw) { return texture(sampler2DArray(t, Sampler), uvw); } vec4 getPixel(texture2DArray t, vec3 uvw) { return texture(sampler2DArray(t, Sampler), uvw); }
#endif #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

View File

@ -4,6 +4,6 @@
#include "lovr.glsl" #include "lovr.glsl"
void main() { vec4 lovrmain() {
PixelColors[0] = Color * MaterialColor * getPixel(ColorTexture, UV); return DefaultColor;
} }

View File

@ -4,10 +4,6 @@
#include "lovr.glsl" #include "lovr.glsl"
void main() { vec4 lovrmain() {
Color = PassColor * VertexColor; return DefaultPosition;
Normal = normalize(NormalMatrix * VertexNormal);
UV = VertexUV;
Position = DefaultPosition;
PointSize = 1.f;
} }

View File

@ -1333,32 +1333,18 @@ ShaderSource lovrGraphicsCompileShader(ShaderStage stage, ShaderSource* source)
"#extension GL_EXT_multiview : require\n" "#extension GL_EXT_multiview : require\n"
"#extension GL_GOOGLE_include_directive : 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[] = { const char* strings[] = {
prefix, prefix,
(const char*) etc_shaders_lovr_glsl, (const char*) etc_shaders_lovr_glsl,
"#line 1\n", "#line 1\n",
source->code, source->code
suffixes[stage]
}; };
int lengths[] = { int lengths[] = {
-1, -1,
etc_shaders_lovr_glsl_len, etc_shaders_lovr_glsl_len,
-1, -1,
source->size, source->size
-1
}; };
const glslang_resource_t* resource = glslang_default_resource(); const glslang_resource_t* resource = glslang_default_resource();