Skip to content

implenent texture3d uniform #30

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

Open
wants to merge 10 commits 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
2 changes: 1 addition & 1 deletion Source/blockly/patches/GEN_GLSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ function updateGLSL(event) {
if (type == "matrix_2x") type = "mat2";
if (type == "matrix_3x") type = "mat3";
if (type == "matrix_4x") type = "mat4";
if (type == "texture3d") type = "sampler3D";

let appendance = "";

Expand Down Expand Up @@ -147,7 +148,6 @@ function updateGLSL(event) {
penPlus.Generated_GLSL = penPlus.monacoEditor.getValue();
penPlus.dispatchEvent("onMainScriptCompiled");
}

penPlus.Generated_Frag = "";
penPlus.Generated_Vert = "";

Expand Down
3 changes: 2 additions & 1 deletion Source/blockly/patches/extensionFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,15 @@ penPlus.penPlusExtension = class {
if (type == "matrix_2x") type = "mat2";
if (type == "matrix_3x") type = "mat3";
if (type == "matrix_4x") type = "mat4";
if (type == "texture3d") type = "sampler3D";

let scope = variable.name.split(" ")[0];
if (scope != "hat") return;

if (!variable.name.split(" ")[1]) return;

//Types that don't have precision
if (variable.type == "texture" || variable.type == "cubemap" || variable.type == "int") returnedGLSL += `${type} ${variable.name.split(" ")[1]} = ${type}(1);\n`;
if (variable.type == "texture" || variable.type == "cubemap" || variable.type == "int" || variable.type == "sampler3D") returnedGLSL += `${type} ${variable.name.split(" ")[1]} = ${type}(1);\n`;
else returnedGLSL += `highp ${type} ${variable.name.split(" ")[1]} = ${type}(1);\n`;
});

Expand Down
2 changes: 1 addition & 1 deletion Source/blocks/looks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
getInfo() {
penPlus.addBlockColorSet("texture_blocks", "#b464e7", "#a755cf", "#9a48c4");
penPlus.addBlockColorSet("cubemap_blocks", "#8672ff", "#7465d6", "#6657cb");
penPlus.addBlockColorSet("3DTexture_blocks", "#967FD7", "#8771C4", "#7760B5");
penPlus.addBlockColorSet("texture3d_blocks", "#967FD7", "#8771C4", "#7760B5");
return {
name: "Looks",
id: "looks",
Expand Down
20 changes: 10 additions & 10 deletions Source/blocks/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,7 @@
const variable = block.getFieldValue("VAR");

const variableName = variable.split(" ")[1];
const variableType = variable.split(" ")[2];

if (variableType == "matrix_2x") variableType = "mat2";
if (variableType == "matrix_3x") variableType = "mat3";
if (variableType == "matrix_4x") variableType = "mat4";
let variableType = variable.split(" ")[2];

const value = generator.valueToCode(block, "VALUE", Order.ATOMIC);

Expand All @@ -431,6 +427,10 @@

block.setStyle(__colorVariableBlock(variableType));

if (variableType == "matrix_2x") variableType = "mat2";
if (variableType == "matrix_3x") variableType = "mat3";
if (variableType == "matrix_4x") variableType = "mat4";

return `${variableName} = ${variableType}(${value});\n` + nextBlockToCode(block, generator);
}

Expand Down Expand Up @@ -641,8 +641,8 @@
</div>
${(penPlus.is300Version && penPlus.experimental) ? `
<!--3D Texture-->
<div id="texture3D" style="left:150%; position:absolute;background-color: var(--EditorTheme_Theme_3);border-radius:1em;width:auto;height:100%;aspect-ratio:7/6; justify-content: center;">
<div style="background-color:var(--3DTexture_blocks);position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); border-radius:100%; aspect-ratio:1; width:auto; height:50%;">
<div id="texture3d" style="left:150%; position:absolute;background-color: var(--EditorTheme_Theme_3);border-radius:1em;width:auto;height:100%;aspect-ratio:7/6; justify-content: center;">
<div style="background-color:var(--texture3d_blocks);position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); border-radius:100%; aspect-ratio:1; width:auto; height:50%;">
</div>

<p class="noSelect" style="position:absolute;top:85%;left:50%;transform:translate(-50%,-50%);font-size: 1.125em; width:50%; height:50%;">3D Texture</p>
Expand Down Expand Up @@ -780,9 +780,9 @@
};

if ((penPlus.is300Version && penPlus.experimental)) {
variableTypeChangers.texture3D = document.getElementById("texture3D");
variableTypeChangers.texture3D.onclick = () => {
cycleVariable("texture3D");
variableTypeChangers.texture3d = document.getElementById("texture3d");
variableTypeChangers.texture3d.onclick = () => {
cycleVariable("texture3d");
setScopeVisibilities(false, true, false, false, false);
}
}
Expand Down
4 changes: 4 additions & 0 deletions Source/css/syntaxHighlighting.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
color: var(--texture_blocks);
}

.texture3d_Highlight {
color: var(--texture3d_blocks);
}

.cubemap_Highlight {
color: var(--cubemap_blocks);
}
Expand Down
9 changes: 9 additions & 0 deletions Source/editor/buttons/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@
</div>
</div>

<div class="modalContentSetting">
<div>
<label>
<input type="color" id="texture3dColor"></input>
<span style="color:var(--EditorTheme_Text_1);">Texture 3d</span>
</label>
</div>
</div>
</div>
</div>
`);
Expand Down Expand Up @@ -388,6 +396,7 @@

matrix: document.getElementById("matrixColor"),
texture: document.getElementById("textureColor"),
texture3d: document.getElementById("texture3dColor"),
cubemap: document.getElementById("cubemapColor"),
};

Expand Down
27 changes: 26 additions & 1 deletion Source/editor/compileTime/shaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,31 @@ function getTypedInput(type, name, index) {

return input;

case "sampler3D":
keys = Object.keys(penPlus.textures3d);

input = document.createElement("select");
input.style.width = "75%";
input.className = "scratchStyledInput";

//Loop through textures to add them to the list
options = "";
keys.forEach((key) => {
options += `<option value="${key}">texture ${key}</option>`;
});

input.innerHTML = options;

if (penPlus.previousVariableStates[name]) input.value = penPlus.previousVariableStates[name];
gl.shaders.editorShader.uniforms[name].value = penPlus.previousVariableStates[name] ? penPlus.previousVariableStates[name] : penPlus.textures3d[input.value];

input.addEventListener("change", () => {
gl.shaders.editorShader.uniforms[name].value = penPlus.textures3d[input.value];
penPlus.previousVariableStates[name] = input.value;
});

return input;

case "float":
input = document.createElement("input");
input.style.width = "75%";
Expand Down Expand Up @@ -768,10 +793,10 @@ function genProgram() {
}
return;
}

//Handle non arrays
if (!refreshedPoints) gl.shaders["editorShader"].setupUniform(attribute.name, attribute.type);


//Remove pen+ uniforms that are static
if (attribute.name != "u_timer" && attribute.name != "u_res" && attribute.name != "u_transform") {
let divElement = document.createElement("div");
Expand Down
Loading