mirror of https://github.com/bjornbytes/lovr.git
Pass:skybox;
This commit is contained in:
parent
8aa14ba42b
commit
b934fac1df
|
@ -2,6 +2,9 @@
|
||||||
#include "shaders/unlit.frag.h"
|
#include "shaders/unlit.frag.h"
|
||||||
#include "shaders/font.frag.h"
|
#include "shaders/font.frag.h"
|
||||||
#include "shaders/fill.vert.h"
|
#include "shaders/fill.vert.h"
|
||||||
|
#include "shaders/cubemap.vert.h"
|
||||||
|
#include "shaders/cubemap.frag.h"
|
||||||
|
#include "shaders/equirect.frag.h"
|
||||||
#include "shaders/animator.comp.h"
|
#include "shaders/animator.comp.h"
|
||||||
#include "shaders/timewizard.comp.h"
|
#include "shaders/timewizard.comp.h"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
#version 460
|
||||||
|
#extension GL_EXT_multiview : require
|
||||||
|
#extension GL_GOOGLE_include_directive : require
|
||||||
|
|
||||||
|
#include "lovr.glsl"
|
||||||
|
|
||||||
|
layout(set = 1, binding = 1) uniform textureCube SkyboxTexture;
|
||||||
|
|
||||||
|
layout(location = 2) in vec3 FragDirection;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
PixelColors[0] = FragColor * texture(samplerCube(SkyboxTexture, Sampler), FragDirection);
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
#version 460
|
||||||
|
#extension GL_EXT_multiview : require
|
||||||
|
#extension GL_GOOGLE_include_directive : require
|
||||||
|
|
||||||
|
#include "lovr.glsl"
|
||||||
|
|
||||||
|
layout(location = 2) out vec3 FragDirection;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
FragColor = VertexColor * Color;
|
||||||
|
|
||||||
|
const vec2 uvs[6] = vec2[6](
|
||||||
|
vec2(-1, -1),
|
||||||
|
vec2(-1, +1),
|
||||||
|
vec2(+1, -1),
|
||||||
|
vec2(+1, -1),
|
||||||
|
vec2(-1, +1),
|
||||||
|
vec2(+1, +1)
|
||||||
|
);
|
||||||
|
|
||||||
|
vec2 uv = uvs[VertexIndex % 6];
|
||||||
|
vec3 ray = vec3(uv, -1.);
|
||||||
|
mat3 inverseViewOrientation = transpose(mat3(View));
|
||||||
|
FragDirection = normalize(inverseViewOrientation * (InverseProjection * vec4(ray, 1.)).xyz);
|
||||||
|
Position = vec4(uv, 1, 1);
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
#version 460
|
||||||
|
#extension GL_EXT_multiview : require
|
||||||
|
#extension GL_GOOGLE_include_directive : require
|
||||||
|
|
||||||
|
#define PI 3.141592653589793238462643383
|
||||||
|
|
||||||
|
#include "lovr.glsl"
|
||||||
|
|
||||||
|
layout(location = 2) in vec3 FragDirection;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec3 dir = normalize(FragDirection);
|
||||||
|
float phi = acos(dir.y);
|
||||||
|
float theta = atan(dir.x, -dir.z);
|
||||||
|
vec2 uv = vec2(.5 + theta / (2 * PI), phi / PI);
|
||||||
|
PixelColors[0] = FragColor * texture(sampler2D(Texture, Sampler), uv);
|
||||||
|
}
|
|
@ -60,11 +60,13 @@ layout(location = 0) out vec4 PixelColors[1];
|
||||||
|
|
||||||
// Varyings
|
// Varyings
|
||||||
#ifdef GL_VERTEX_SHADER
|
#ifdef GL_VERTEX_SHADER
|
||||||
layout(location = 10) out vec4 FragColor;
|
layout(location = 10) out vec3 FragNormal;
|
||||||
layout(location = 11) out vec2 FragUV;
|
layout(location = 11) out vec4 FragColor;
|
||||||
|
layout(location = 12) out vec2 FragUV;
|
||||||
#else
|
#else
|
||||||
layout(location = 10) in vec4 FragColor;
|
layout(location = 10) in vec3 FragNormal;
|
||||||
layout(location = 11) in vec2 FragUV;
|
layout(location = 11) in vec4 FragColor;
|
||||||
|
layout(location = 12) in vec2 FragUV;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Macros
|
// Macros
|
||||||
|
@ -97,7 +99,7 @@ layout(location = 11) in vec2 FragUV;
|
||||||
#define ViewProjection cameras[ViewIndex].viewProjection
|
#define ViewProjection cameras[ViewIndex].viewProjection
|
||||||
#define InverseProjection cameras[ViewIndex].inverseProjection
|
#define InverseProjection cameras[ViewIndex].inverseProjection
|
||||||
#define Transform draws[DrawId].transform
|
#define Transform draws[DrawId].transform
|
||||||
#define NormalMatrix draws[DrawId].normalMatrix
|
#define NormalMatrix mat3(draws[DrawId].normalMatrix)
|
||||||
#define Color draws[DrawId].color
|
#define Color draws[DrawId].color
|
||||||
|
|
||||||
#define ClipFromLocal (ViewProjection * Transform)
|
#define ClipFromLocal (ViewProjection * Transform)
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
FragColor = VertexColor * Color;
|
FragColor = VertexColor * Color;
|
||||||
|
FragNormal = normalize(NormalMatrix * VertexNormal);
|
||||||
FragUV = VertexUV;
|
FragUV = VertexUV;
|
||||||
Position = DefaultPosition;
|
Position = DefaultPosition;
|
||||||
PointSize = 1.f;
|
PointSize = 1.f;
|
||||||
|
|
|
@ -60,6 +60,8 @@ StringEntry lovrCullMode[] = {
|
||||||
|
|
||||||
StringEntry lovrDefaultShader[] = {
|
StringEntry lovrDefaultShader[] = {
|
||||||
[SHADER_UNLIT] = ENTRY("unlit"),
|
[SHADER_UNLIT] = ENTRY("unlit"),
|
||||||
|
[SHADER_CUBE] = ENTRY("cube"),
|
||||||
|
[SHADER_FILL] = ENTRY("fill"),
|
||||||
[SHADER_FONT] = ENTRY("font"),
|
[SHADER_FONT] = ENTRY("font"),
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
|
@ -911,7 +913,7 @@ static int l_lovrGraphicsNewTexture(lua_State* L) {
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.imageCount == 0 && info.depth == 0) {
|
if (info.depth == 0) {
|
||||||
info.depth = info.type == TEXTURE_CUBE ? 6 : 1;
|
info.depth = info.type == TEXTURE_CUBE ? 6 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -569,6 +569,13 @@ static int l_lovrPassText(lua_State* L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_lovrPassSkybox(lua_State* L) {
|
||||||
|
Pass* pass = luax_checktype(L, 1, Pass);
|
||||||
|
Texture* texture = luax_totype(L, 2, Texture);
|
||||||
|
lovrPassSkybox(pass, texture);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int l_lovrPassFill(lua_State* L) {
|
static int l_lovrPassFill(lua_State* L) {
|
||||||
Pass* pass = luax_checktype(L, 1, Pass);
|
Pass* pass = luax_checktype(L, 1, Pass);
|
||||||
Texture* texture = luax_totype(L, 2, Texture);
|
Texture* texture = luax_totype(L, 2, Texture);
|
||||||
|
@ -864,6 +871,7 @@ const luaL_Reg lovrPass[] = {
|
||||||
{ "torus", l_lovrPassTorus },
|
{ "torus", l_lovrPassTorus },
|
||||||
{ "cylinder", l_lovrPassCylinder },
|
{ "cylinder", l_lovrPassCylinder },
|
||||||
{ "text", l_lovrPassText },
|
{ "text", l_lovrPassText },
|
||||||
|
{ "skybox", l_lovrPassSkybox },
|
||||||
{ "fill", l_lovrPassFill },
|
{ "fill", l_lovrPassFill },
|
||||||
{ "monkey", l_lovrPassMonkey },
|
{ "monkey", l_lovrPassMonkey },
|
||||||
{ "draw", l_lovrPassDraw },
|
{ "draw", l_lovrPassDraw },
|
||||||
|
|
|
@ -1096,7 +1096,7 @@ Texture* lovrTextureCreate(TextureInfo* info) {
|
||||||
Image* image = info->imageCount == 1 ? info->images[0] : info->images[layer];
|
Image* image = info->imageCount == 1 ? info->images[0] : info->images[layer];
|
||||||
uint32_t slice = info->imageCount == 1 ? layer : 0;
|
uint32_t slice = info->imageCount == 1 ? layer : 0;
|
||||||
uint32_t size = lovrImageGetLayerSize(image, level);
|
uint32_t size = lovrImageGetLayerSize(image, level);
|
||||||
lovrCheck(size == levelSizes[level], "Texture/Image size mismatch!");
|
lovrCheck(size == levelSizes[level] / info->depth, "Texture/Image size mismatch!");
|
||||||
void* pixels = lovrImageGetLayerData(image, level, slice);
|
void* pixels = lovrImageGetLayerData(image, level, slice);
|
||||||
memcpy(data, pixels, size);
|
memcpy(data, pixels, size);
|
||||||
data += size;
|
data += size;
|
||||||
|
@ -1426,16 +1426,26 @@ Shader* lovrGraphicsGetDefaultShader(DefaultShader type) {
|
||||||
info.stages[1] = lovrBlobCreate((void*) lovr_shader_unlit_frag, sizeof(lovr_shader_unlit_frag), "Unlit Fragment Shader");
|
info.stages[1] = lovrBlobCreate((void*) lovr_shader_unlit_frag, sizeof(lovr_shader_unlit_frag), "Unlit Fragment Shader");
|
||||||
info.label = "unlit";
|
info.label = "unlit";
|
||||||
break;
|
break;
|
||||||
case SHADER_FONT:
|
case SHADER_CUBE:
|
||||||
info.stages[0] = lovrBlobCreate((void*) lovr_shader_unlit_vert, sizeof(lovr_shader_unlit_vert), "Unlit Vertex Shader");
|
info.stages[0] = lovrBlobCreate((void*) lovr_shader_cubemap_vert, sizeof(lovr_shader_cubemap_vert), "Cubemap Vertex Shader");
|
||||||
info.stages[1] = lovrBlobCreate((void*) lovr_shader_font_frag, sizeof(lovr_shader_font_frag), "Font Fragment Shader");
|
info.stages[1] = lovrBlobCreate((void*) lovr_shader_cubemap_frag, sizeof(lovr_shader_cubemap_frag), "Cubemap Fragment Shader");
|
||||||
info.label = "font";
|
info.label = "cubemap";
|
||||||
|
break;
|
||||||
|
case SHADER_PANO:
|
||||||
|
info.stages[0] = lovrBlobCreate((void*) lovr_shader_cubemap_vert, sizeof(lovr_shader_cubemap_vert), "Cubemap Vertex Shader");
|
||||||
|
info.stages[1] = lovrBlobCreate((void*) lovr_shader_equirect_frag, sizeof(lovr_shader_equirect_frag), "Equirect Fragment Shader");
|
||||||
|
info.label = "equirect";
|
||||||
break;
|
break;
|
||||||
case SHADER_FILL:
|
case SHADER_FILL:
|
||||||
info.stages[0] = lovrBlobCreate((void*) lovr_shader_fill_vert, sizeof(lovr_shader_fill_vert), "Fill Vertex Shader");
|
info.stages[0] = lovrBlobCreate((void*) lovr_shader_fill_vert, sizeof(lovr_shader_fill_vert), "Fill Vertex Shader");
|
||||||
info.stages[1] = lovrBlobCreate((void*) lovr_shader_unlit_frag, sizeof(lovr_shader_unlit_frag), "Unlit Fragment Shader");
|
info.stages[1] = lovrBlobCreate((void*) lovr_shader_unlit_frag, sizeof(lovr_shader_unlit_frag), "Unlit Fragment Shader");
|
||||||
info.label = "fill";
|
info.label = "fill";
|
||||||
break;
|
break;
|
||||||
|
case SHADER_FONT:
|
||||||
|
info.stages[0] = lovrBlobCreate((void*) lovr_shader_unlit_vert, sizeof(lovr_shader_unlit_vert), "Unlit Vertex Shader");
|
||||||
|
info.stages[1] = lovrBlobCreate((void*) lovr_shader_font_frag, sizeof(lovr_shader_font_frag), "Font Fragment Shader");
|
||||||
|
info.label = "font";
|
||||||
|
break;
|
||||||
default: lovrUnreachable();
|
default: lovrUnreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1832,7 +1842,7 @@ Material* lovrMaterialCreate(MaterialInfo* info) {
|
||||||
for (uint32_t i = 0; i < COUNTOF(textures); i++) {
|
for (uint32_t i = 0; i < COUNTOF(textures); i++) {
|
||||||
lovrRetain(textures[i]);
|
lovrRetain(textures[i]);
|
||||||
Texture* texture = textures[i] ? textures[i] : state.defaultTexture;
|
Texture* texture = textures[i] ? textures[i] : state.defaultTexture;
|
||||||
lovrCheck(texture->info.type == TEXTURE_2D, "Material textures must be 2D");
|
lovrCheck(i == 0 || texture->info.type == TEXTURE_2D, "Material textures must be 2D");
|
||||||
bindings[i + 1] = (gpu_binding) { i + 1, GPU_SLOT_SAMPLED_TEXTURE, .texture = texture->gpu };
|
bindings[i + 1] = (gpu_binding) { i + 1, GPU_SLOT_SAMPLED_TEXTURE, .texture = texture->gpu };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4189,6 +4199,26 @@ void lovrPassText(Pass* pass, Font* font, ColoredString* strings, uint32_t count
|
||||||
tempPop(stack);
|
tempPop(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lovrPassSkybox(Pass* pass, Texture* texture) {
|
||||||
|
if (texture->info.type == TEXTURE_2D) {
|
||||||
|
lovrPassDraw(pass, &(Draw) {
|
||||||
|
.mode = VERTEX_TRIANGLES,
|
||||||
|
.shader = SHADER_PANO,
|
||||||
|
.material = texture ? lovrTextureGetMaterial(texture) : NULL,
|
||||||
|
.vertex.format = VERTEX_EMPTY,
|
||||||
|
.count = 6
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
lovrPassDraw(pass, &(Draw) {
|
||||||
|
.mode = VERTEX_TRIANGLES,
|
||||||
|
.shader = SHADER_CUBE,
|
||||||
|
.material = texture ? lovrTextureGetMaterial(texture) : NULL,
|
||||||
|
.vertex.format = VERTEX_EMPTY,
|
||||||
|
.count = 6
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void lovrPassFill(Pass* pass, Texture* texture) {
|
void lovrPassFill(Pass* pass, Texture* texture) {
|
||||||
lovrPassDraw(pass, &(Draw) {
|
lovrPassDraw(pass, &(Draw) {
|
||||||
.mode = VERTEX_TRIANGLES,
|
.mode = VERTEX_TRIANGLES,
|
||||||
|
|
|
@ -253,8 +253,10 @@ const SamplerInfo* lovrSamplerGetInfo(Sampler* sampler);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SHADER_UNLIT,
|
SHADER_UNLIT,
|
||||||
SHADER_FONT,
|
SHADER_CUBE,
|
||||||
|
SHADER_PANO,
|
||||||
SHADER_FILL,
|
SHADER_FILL,
|
||||||
|
SHADER_FONT,
|
||||||
DEFAULT_SHADER_COUNT
|
DEFAULT_SHADER_COUNT
|
||||||
} DefaultShader;
|
} DefaultShader;
|
||||||
|
|
||||||
|
@ -540,6 +542,7 @@ void lovrPassSphere(Pass* pass, float* transform, uint32_t segmentsH, uint32_t s
|
||||||
void lovrPassCylinder(Pass* pass, float* transform, bool capped, float angle1, float angle2, uint32_t segments);
|
void lovrPassCylinder(Pass* pass, float* transform, bool capped, float angle1, float angle2, uint32_t segments);
|
||||||
void lovrPassTorus(Pass* pass, float* transform, uint32_t segmentsT, uint32_t segmentsP);
|
void lovrPassTorus(Pass* pass, float* transform, uint32_t segmentsT, uint32_t segmentsP);
|
||||||
void lovrPassText(Pass* pass, Font* font, ColoredString* strings, uint32_t count, float* transform, float wrap, HorizontalAlign halign, VerticalAlign valign);
|
void lovrPassText(Pass* pass, Font* font, ColoredString* strings, uint32_t count, float* transform, float wrap, HorizontalAlign halign, VerticalAlign valign);
|
||||||
|
void lovrPassSkybox(Pass* pass, Texture* texture);
|
||||||
void lovrPassFill(Pass* pass, Texture* texture);
|
void lovrPassFill(Pass* pass, Texture* texture);
|
||||||
void lovrPassMonkey(Pass* pass, float* transform);
|
void lovrPassMonkey(Pass* pass, float* transform);
|
||||||
void lovrPassDrawModel(Pass* pass, Model* model, float* transform, uint32_t node, bool recurse, uint32_t instances);
|
void lovrPassDrawModel(Pass* pass, Model* model, float* transform, uint32_t node, bool recurse, uint32_t instances);
|
||||||
|
|
Loading…
Reference in New Issue