-
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.
- Loading branch information
1 parent
4c75557
commit a9a8cb7
Showing
5 changed files
with
92 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
#pragma once | ||
|
||
namespace Neshny { | ||
|
||
#if defined(NESHNY_GL) | ||
#elif defined(NESHNY_WEBGPU) | ||
|
||
// TODO: move all appropriate code out of .h into here | ||
|
||
bool TextureSkybox::Init(std::string_view path, Params params, std::string& err) { | ||
std::vector<std::string> names = { "right", "left", "top", "bottom", "front", "back" }; | ||
for (int i = 0; i < 6; i++) { | ||
|
||
std::string fullname = ReplaceAll(path, "*", names[i]); | ||
|
||
SDL_Surface* surface = IMG_Load(fullname.data()); | ||
if (!surface) { | ||
err = std::format("Could not load image {}", path); | ||
return false; | ||
} | ||
|
||
if (surface->format->format != g_CorrectSDLFormat) { | ||
SDL_Surface* converted_surface = SDL_ConvertSurfaceFormat(surface, g_CorrectSDLFormat, 0); | ||
SDL_FreeSurface(surface); | ||
surface = converted_surface; | ||
} | ||
|
||
if (i == 0) { | ||
m_Texture.InitCubeMap(surface->w, surface->h); | ||
} | ||
auto sync_token = Core::Singleton().SyncWithMainThread(); | ||
m_Texture.CopyDataLayer(i, (unsigned char*)surface->pixels, surface->format->BytesPerPixel, surface->pitch, false); | ||
} | ||
return true; | ||
}; | ||
|
||
void TextureSkybox::Render(WebGPURTT& rtt, const Matrix4& view_perspective) { | ||
WebGPUPipeline::RenderParams render_params; | ||
render_params.p_DepthWriteEnabled = false; | ||
render_params.p_DepthCompare = WGPUCompareFunction_Always; | ||
Neshny::EntityPipeline::RenderBuffer(SrcStr(), "SkyBox", Core::GetBuffer("Square"), render_params) | ||
.SetUniform(view_perspective.ToGPU()) | ||
.AddTexture("SkyBox", &m_Texture) | ||
.AddSampler("Sampler", Core::GetSampler(WGPUAddressMode_Repeat)) | ||
.Render(&rtt); | ||
} | ||
|
||
#endif | ||
|
||
} // namespace Neshny |
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,29 @@ | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
struct VertexIn { | ||
@location(0) aPos : vec2f | ||
} | ||
struct VertexOut { | ||
@builtin(position) Position : vec4f, | ||
@location(0) vScreenPos : vec2f | ||
} | ||
|
||
@vertex | ||
fn vertex_main(input : VertexIn) -> VertexOut { | ||
var output : VertexOut; | ||
output.vScreenPos = input.aPos; | ||
output.Position = vec4f(input.aPos, 0.0, 1.0); | ||
return output; | ||
} | ||
@fragment | ||
fn frag_main(input: VertexOut) -> @location(0) vec4f { | ||
|
||
var eye_pos_a : vec4f = Uniform.Matrix4x4 * vec4f(input.vScreenPos.xy, -1.0, 1.0); | ||
var eye_pos_b : vec4f = Uniform.Matrix4x4 * vec4f(input.vScreenPos.xy, -0.9, 1.0); | ||
eye_pos_a /= eye_pos_a.w; | ||
eye_pos_b /= eye_pos_b.w; | ||
let eye_pos_dir : vec3f = normalize(eye_pos_b.xyz - eye_pos_a.xyz); | ||
|
||
let skybox_lookup = textureSampleLevel(SkyBox, Sampler, eye_pos_dir, 0.0).xyz; | ||
|
||
return vec4f(skybox_lookup, 1.0); | ||
} |
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