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

Enhancement ShaderLab PBR #2502

Merged
merged 4 commits into from
Jan 14, 2025
Merged
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
16 changes: 2 additions & 14 deletions packages/shader-shaderlab/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Shader, ShaderFactory } from "@galacean/engine";
import { ShaderFactory } from "@galacean/engine";
import { PBRSource, fragmentList } from "./shaders";

let includeRegistered = false;
let shaderRegistered = false;

export function registerIncludes() {
if (includeRegistered) return;
Expand All @@ -14,15 +13,4 @@ export function registerIncludes() {
includeRegistered = true;
}

export function registerShader() {
if (shaderRegistered) return;

Shader.create(PBRSource);

shaderRegistered = true;
}

/**
* @internal
*/
export { fragmentList };
export { PBRSource, fragmentList };
53 changes: 41 additions & 12 deletions packages/shader-shaderlab/src/shaders/PBR.gs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Shader "PBR.gs" {
EditorProperties {
Shader "PBRShaderName" {
Editor {
Properties{
Header("Base"){
material_IOR("IOR", Range(0, 5, 0.01)) = 1.5;
material_BaseColor("BaseColor", Color) = (1, 1, 1, 1);
Expand All @@ -13,8 +14,9 @@ Shader "PBR.gs" {
}

Header("Anisotropy") {
material_AnisotropyInfo("AnisotropyInfo", Vector3) = (1, 0, 0);
material_AnisotropyTexture("AnisotropyTexture", Texture2D);
anisotropy("Intensity", Range(0, 1, 0.01)) = 0;
anisotropyRotation("Rotation", Range(0, 360, 1)) = 0;
material_AnisotropyTexture("Texture", Texture2D);
}
Comment on lines +17 to +19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Property rename breaks shader functionality

The anisotropy property renames in PBR.gs are incomplete and will break the shader system. The old property names material_AnisotropyInfo and material_AnisotropyTexture are still used in:

  • Shader uniform declarations and calculations in FragmentPBR.glsl, pbr_frag_define.glsl, and pbr_helper.glsl
  • Material implementation in PBRMaterial.ts

Either keep the original property names or update all references consistently across the codebase.

🔗 Analysis chain

Verify impact of anisotropy property renames.

The renaming of anisotropy properties (material_AnisotropyInfoanisotropy, material_AnisotropyTexture name change) improves clarity but may affect existing materials.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for uses of old anisotropy property names
rg "material_AnisotropyInfo|material_AnisotropyTexture"

Length of output: 1632


Header("Normal") {
Expand Down Expand Up @@ -42,40 +44,67 @@ Shader "PBR.gs" {
}

Header("Thin Film Iridescence"){
material_IridescenceInfo("IridescenceInfo", Vector4) = (0, 1.3, 100, 400);
material_IridescenceThicknessTexture("IridescenceThicknessTexture", Texture2D);
material_Iridescence("Iridescence", Range(0, 1, 0.01)) = 0;
material_IridescenceIOR("IOR", Range(1, 5, 0.01)) = 1.3;
material_IridescenceRange("ThicknessRange", Vector2) = (100,400);
material_IridescenceThicknessTexture("ThicknessTexture", Texture2D);
material_IridescenceTexture("IridescenceTexture", Texture2D);
Comment on lines +47 to +50
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Incomplete iridescence property refactoring detected

The iridescence properties have been restructured in PBR.gs but the implementation hasn't been updated accordingly:

  • FragmentPBR.glsl still uses the old material_IridescenceInfo vec4 property which no longer exists
  • PBRMaterial.ts still references the old property via _iridescenceInfoProp
🔗 Analysis chain

Verify impact of iridescence property restructuring.

The iridescence properties have been significantly restructured:

  • material_IridescenceInfo split into separate properties
  • Added new material_IridescenceIOR and material_IridescenceRange
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for uses of old iridescence property
rg "material_IridescenceInfo"

Length of output: 872


Script:

#!/bin/bash
# Search for new iridescence properties
echo "=== Searching for new properties ==="
rg "material_Iridescence[^I]" -A 2
echo -e "\n=== Searching for PBRMaterial.ts changes ==="
rg "material_Iridescence" packages/core/src/material/PBRMaterial.ts -A 2

Length of output: 3605

}

Header("Sheen"){
ui_SheenIntensity("Intensity", Range(0, 1, 0.01)) = 0;
ui_SheenColor("Color", Color ) = (0, 0, 0, 0);
sheenColor("Color", Color ) = (0, 0, 0, 1);
sheenIntensity("Intensity", Range(0, 1, 0.01)) = 1;
material_SheenRoughness("Roughness", Range(0, 1, 0.01)) = 0;
material_SheenTexture("ColorTexture", Texture2D);
material_SheenRoughnessTexture("RoughnessTexture", Texture2D);
}
Header("Transmission"){

Header("Transmission") {
material_Transmission("Transmission", Range(0, 1, 0.01)) = 0;
material_TransmissionTexture("TransmissionTexture", Texture2D);
material_AttenuationColor("AttenuationColor", Color ) = (1, 1, 1, 1);
material_AttenuationDistance("AttenuationDistance", Range(0, 1, 0.01)) = 0;
material_Thickness("Thickness", Range(0, 5, 0.01)) = 0;
material_ThicknessTexture("ThicknessTexture", Texture2D);
refractionMode("RefractionMode", Enum(Sphere:0, Planar:1)) = 1;
material_AttenuationColor("AttenuationColor", Color ) = (1, 1, 1, 1);
material_AttenuationDistance("AttenuationDistance", Range(0, 1, 0.01)) = 0;
}

Header("Common") {
isTransparent("Transparent", Boolean) = false;
renderFace("Render Face", Enum(Front:0, Back:1, Double:2)) = 0;
blendMode("Blend Mode", Enum(Normal:0, Additive:1)) = 0;
material_AlphaCutoff( "AlphaCutoff", Range(0, 1, 0.01) ) = 0;
material_TilingOffset("TilingOffset", Vector4) = (1, 1, 0, 0);
}
}

UIScript "UIScriptPath";
}

SubShader "Default" {
UsePass "pbr/Default/ShadowCaster"

Pass "Forward Pass" {
Tags { pipelineStage = "Forward"}

DepthState {
WriteEnabled = depthWriteEnabled;
}

BlendState {
Enabled = blendEnabled;
SourceColorBlendFactor = sourceColorBlendFactor;
DestinationColorBlendFactor = destinationColorBlendFactor;
SourceAlphaBlendFactor = sourceAlphaBlendFactor;
DestinationAlphaBlendFactor = destinationAlphaBlendFactor;
}

RasterState{
CullMode = rasterStateCullMode;
}

RenderQueueType = renderQueueType;

#define IS_METALLIC_WORKFLOW

VertexShader = PBRVertex;
Expand Down
Loading