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

CustomShader with procedural normals missing #define HAS_NORMALS #10181

Open
ptrgags opened this issue Mar 9, 2022 · 1 comment
Open

CustomShader with procedural normals missing #define HAS_NORMALS #10181

ptrgags opened this issue Mar 9, 2022 · 1 comment

Comments

@ptrgags
Copy link
Contributor

ptrgags commented Mar 9, 2022

While working on a sandcastle for #10180, I had tried making procedural normals for a torus. the lighting wasn't showing up and it took my a while to realize, the HAS_NORMALS define is only applied if the original model had normals. the lightingModel: LightingModel.PBR option does not add this define.

excerpt from this sandcastle (requires the feature-id-labels branch from #10180):

  // This is a bug, I shouldn't have to add this define in custom shaders...
  #define HAS_NORMALS

  void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
    // See https://en.wikipedia.org/wiki/Toroidal_and_poloidal_coordinates
    float toroidal = 2.0 * czm_pi * (float(fsInput.featureIds.featureId_0) / 29.0);
    float poloidal = 2.0 * czm_pi * (float(fsInput.featureIds.featureId_1) / 19.0);
    mat3 rotate = mat3(
      cos(toroidal), sin(toroidal), 0.0,
      -sin(toroidal), cos(toroidal), 0.0,
      0.0, 0.0, 1.0
    );

    // normal when toroidal = 0;
    vec3 normal0 = vec3(cos(poloidal), 0.0, sin(poloidal));
    vec3 normalMC = rotate * normal0;
    
    // unfortunately this requires using private API, czm_normal
    material.normalEC = czm_normal * normalMC;
    material.specular = vec3(0.98, 0.90, 0.59);
    material.roughness = 0.3;
  }

Not sure the cleanest place to handle this in the code. Maybe in CustomShaderPipelineStage? or should it be handled later in LightingPipelineStage regardless of what set the PBR mode? And should ShaderBuilder have a way to add a define if it doesn't already exist so we don't add repeated code?

Regardless, this is low priority since procedural normals computed in the shader is likely not a very common use case.

@magixmin
Copy link

magixmin commented Jul 7, 2024

fsInput.featureIds.featureId_0 ,this value not exit .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment