Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preliminary support for multi-pass shadertoys. #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions glsl2hlsl-wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod utils;

use glsl2hlsl::{get_files, make_shader};
use glsl2hlsl::{get_files, get_image_files, make_shader, ShaderType};
use wasm_bindgen::prelude::*;

// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
Expand All @@ -12,6 +12,8 @@ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[wasm_bindgen(module = "/www/file.js")]
extern "C" {
fn download_file(name: &str, contents: &str);
fn download_image(name: &str, contents: &str);
fn reset();
}

#[wasm_bindgen]
Expand All @@ -22,16 +24,24 @@ extern "C" {

#[wasm_bindgen]
pub fn transpile(input: String, extract_props: bool, raymarch: bool) -> String {
glsl2hlsl::transpile(input, extract_props, raymarch)
glsl2hlsl::transpile(input, extract_props, raymarch, ShaderType::MainImage(format!("main"), None, vec![]))
}

#[wasm_bindgen]
pub fn download(json: String, extract_props: bool, raymarch: bool) {
let shader = make_shader(&json).unwrap();
let files = get_files(&shader, extract_props, raymarch);
let images = get_image_files(&shader);
reset();
for f in files.iter() {
unsafe {
download_file(&f.name, &f.contents);
}
}
for f in images.iter() {
unsafe {
download_image(&f.name, &f.contents);
}
}

}
18 changes: 18 additions & 0 deletions glsl2hlsl-wasm/www/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,22 @@ export function download_file(name, contents) {
a.download = name;
document.body.appendChild(a);
a.click();
}

export function download_image(name, contents) {

const c = document.createElement("br");
document.querySelector("#links").appendChild(c);
const a = document.createElement("a");
a.innerHTML = name;
a.href = contents;
a.download = name;
document.querySelector("#links").appendChild(a);

//document.body.appendChild(a);
// a.click();
}

export function reset() {
document.querySelector("#links").innerHTML="<p></p><h2>Textures (Ctrl+Click and Save-As):</h2><br>";
}
5 changes: 3 additions & 2 deletions glsl2hlsl-wasm/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ <h2>Shaderlab (Unity) code:</h2>
<input type="checkbox" id="extract" style="margin-left:10%;"></input>Extract properties (Super experimental, might break)
<input type="checkbox" id="raymarch" style="margin-left:10%;"></input>Raymarched (Super experimental, might break)
<br><br>

<div id="links"></div>
<br><br>
<input id="download" type="button" value="Download from URL or ID">
<input id="shader" value="https://www.shadertoy.com/view/XsXXDn" style="width:30%"><br>
<br><br>

<style>
* { box-sizing: border-box; }
Expand Down Expand Up @@ -75,7 +77,6 @@ <h2>Shaderlab (Unity) code:</h2>
}

</style>

<script src="./bootstrap.js"></script>
</body>
</html>
Loading