Skip to content

Commit

Permalink
toggle css class fix / pbrmaterial double sided
Browse files Browse the repository at this point in the history
  • Loading branch information
pandrr committed Sep 5, 2024
1 parent c410ed4 commit b59b5d2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const inUseVertexColours = op.inValueBool("Use Vertex Colours", false);
const inVertexColourMode = op.inSwitch("Vertex Colour Mode", ["colour", "AORM", "AO", "R", "M", "lightmap"], "colour");
const inHeightDepth = op.inFloat("Height Intensity", 1.0);
const inUseOptimizedHeight = op.inValueBool("Faster heightmapping", false);
const inDoubleSided = op.inValueBool("Double Sided", false);

// texture inputs
const inTexIBLLUT = op.inTexture("IBL LUT");
Expand Down Expand Up @@ -70,7 +71,7 @@ op.toWorkShouldNotBeChild("Ops.Gl.TextureEffects.ImageCompose", CABLES.OP_PORT_T

inDiffuseR.setUiAttribs({ "colorPick": true });
op.setPortGroup("Shader Parameters", [inRoughness, inMetalness, inAlphaMode]);
op.setPortGroup("Advanced Shader Parameters", [inEmissionIntensity, inToggleGR, inToggleNMGR, inUseVertexColours, inVertexColourMode, inHeightDepth, inUseOptimizedHeight]);
op.setPortGroup("Advanced Shader Parameters", [inEmissionIntensity, inToggleGR, inToggleNMGR, inUseVertexColours, inVertexColourMode, inHeightDepth, inUseOptimizedHeight, inDoubleSided]);
op.setPortGroup("Textures", [inTexAlbedo, inTexAORM, inTexNormal, inTexEmission, inTexHeight, inLightmap, inTexThinFilm]);
op.setPortGroup("Lighting", [inDiffuseIntensity, inSpecularIntensity, inLightmapIntensity, inLightmapRGBE, inTexIBLLUT, inTexIrradiance, inTexPrefiltered, inMipLevels]);
op.setPortGroup("Tonemapping", [inTonemapping, inTonemappingExposure]);
Expand Down Expand Up @@ -180,6 +181,7 @@ PBRShader.uniformPbrRoughness = inRoughnessUniform;
inTexPrefiltered.onChange = updateIBLTexDefines;

inTexAORM.onChange =
inDoubleSided.onChange =
inLightmapRGBE.onChange =
inUseNormalMapForCC.onChange =
inUseClearCoat.onChange =
Expand All @@ -201,6 +203,7 @@ inTexAORM.onChange =

function updateDefines()
{
PBRShader.toggleDefine("DOUBLE_SIDED", inDoubleSided.get());
PBRShader.toggleDefine("USE_OPTIMIZED_HEIGHT", inUseOptimizedHeight.get());
PBRShader.toggleDefine("USE_CLEAR_COAT", inUseClearCoat.get());
PBRShader.toggleDefine("USE_NORMAL_MAP_FOR_CC", inUseNormalMapForCC.get());
Expand Down
14 changes: 11 additions & 3 deletions src/ops/base/Ops.Gl.Pbr.PbrMaterial/Ops.Gl.Pbr.PbrMaterial.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
{
"message": "created op",
"author": "amajesticseaflapflap",
"date": 1642599258807
"date": 1642599258807,
"type": "new"
},
{
"message": "Ops.Dev.PbrMaterial renamed to Ops.Gl.Pbr.PbrMaterial",
"message": "Added toggle for double sided, which will flip normals when the face is not front-facing ",
"type": "feature",
"author": "pandur",
"date": 1644228803318
"date": 1725553568070
}
],
"layout": {
Expand Down Expand Up @@ -199,6 +201,12 @@
"group": "Advanced Shader Parameters",
"subType": "boolean"
},
{
"type": 0,
"name": "Double Sided",
"group": "Advanced Shader Parameters",
"subType": "boolean"
},
{
"type": 2,
"name": "IBL LUT",
Expand Down
5 changes: 5 additions & 0 deletions src/ops/base/Ops.Gl.Pbr.PbrMaterial/att_BasicPBR.frag
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ void main()
internalNormals = normalize(TBN * internalNormals);
#else
vec3 internalNormals = normM;

#ifdef DOUBLE_SIDED
if(!gl_FrontFacing) internalNormals = internalNormals*-1.0;
#endif

#endif
#ifdef USE_LIGHTMAP
#ifndef VERTEX_COLORS
Expand Down
35 changes: 17 additions & 18 deletions src/ops/base/Ops.Sidebar.Toggle_v4/Ops.Sidebar.Toggle_v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ label.appendChild(labelText);

const icon = document.createElement("div");

if (defaultValuePort.get())
{
icon.classList.remove("icon_toggle_false");
icon.classList.add("icon_toggle_true");
}
else
{
icon.classList.remove("icon_toggle_true");
icon.classList.add("icon_toggle_false");
}
valuePort.set(defaultValuePort.get());

icon.classList.add("icon_toggle");
Expand All @@ -53,7 +43,11 @@ el.appendChild(icon);
el.appendChild(label);
el.addEventListener("dblclick", reset);

op.init = reset;
op.init = () =>
{
reset();
updateClass();
};
op.onDelete = onDelete;
parentPort.onChange = onParentChanged;
labelPort.onChange = onLabelTextChanged;
Expand All @@ -77,14 +71,9 @@ function storeDefaultValue()
op.refreshParams();
}

function onInputClick()
function updateClass()
{
el.classList.toggle(classNameActive);

const isActive = el.classList.contains(classNameActive);
valuePort.set(isActive);
inputValue.set(isActive);

const isActive = valuePort.get();
if (isActive)
{
icon.classList.add("icon_toggle_true");
Expand All @@ -95,7 +84,17 @@ function onInputClick()
icon.classList.remove("icon_toggle_true");
icon.classList.add("icon_toggle_false");
}
}

function onInputClick()
{
el.classList.toggle(classNameActive);

const isActive = el.classList.contains(classNameActive);
valuePort.set(isActive);
inputValue.set(isActive);

updateClass();
outToggled.trigger();
op.refreshParams();
}
Expand Down
6 changes: 6 additions & 0 deletions src/ops/base/Ops.Sidebar.Toggle_v4/Ops.Sidebar.Toggle_v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
"type": "improvement",
"author": "pandur",
"date": 1715693416129
},
{
"message": "CSS classes are applied correctly now on init",
"type": "improvement",
"author": "pandur",
"date": 1725551784635
}
],
"license": "MIT",
Expand Down

0 comments on commit b59b5d2

Please sign in to comment.