Giter VIP home page Giter VIP logo

component-material's People

Contributors

drcmda avatar emmelleppi avatar gsimone avatar joshuaellis avatar skuteli avatar tirzono avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

component-material's Issues

Replace string from shader chunk

Sometimes you might want to replace a specific string inside of a chunk, rather than the whole chunk.

Currently I'm doing this:

<ComponentMaterial.Vert.defaultnormal_vertex
    replaceChunk
    children={ShaderChunk.defaultnormal_vertex.replace(
      "vec3 transformedNormal = objectNormal;",
      "vec3 transformedNormal = displacedNormal;"
    )}
  />

Would be a bit easier if I could do this:

<ComponentMaterial.Vert.defaultnormal_vertex
    replaceString="vec3 transformedNormal = objectNormal;",
    children="vec3 transformedNormal = displacedNormal;"
  />

Reuse common parts across multiple materials?

I need a few different materials in my project, but they share a lot of functionality. I'm not sure what the best approach to do this would be. One idea would be to reuse common tags. For example you could define them inside a fragment and then reuse that fragment inside of many materials.

function CommonTags () {
  return (
    <>
      <ComponentMaterial.Vert.defaultnormal_vertex
        replaceChunk
        children={ShaderChunk.defaultnormal_vertex.replace(
          "vec3 transformedNormal = objectNormal;",
          `vec3 transformedNormal = displacedNormal;`
        )} />
      <ComponentMaterial.Vert.displacementmap_vertex
        replaceChunk
        children="transformed = displacedPosition;"  />
    </>
  )
}

Request: hot reload when shader code changes

When writing a plain <shaderMaterial />, the material will hot reload when the shader code changes which enables rapid iteration during development.

By contrast, a <Material /> from component-material only hot reloads when uniforms change, while code changes require a full page reload. This makes it hard for me to adopt component-material in my workflow.

Add default vert and frag

Default vert would be used like

<M>
   <M.vert /> // empty
</M>

and result in a default non-transforming vertex shader

void main() {
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.);
}

Stopped working with three.js version 0.127.0 and MeshPhongMaterial

Have a look here:

https://codesandbox.io/s/react-component-threejs-127-32ch1

The issue is that this:

  return class extends baseMaterial {
    constructor(parameters = {}) {
      const entries = Object.entries(uniforms)
      super(parameters)

Is converted to:

    function _class(parameters) {
      var _this;

      if (parameters === void 0) {
        parameters = {};
      }

      var entries = Object.entries(uniforms);
      _this = _baseMaterial.call(this, parameters) || this;

Which is probably done by tsdx. I unfortunately don't know much about tsdx so I hope someone else has more knowledge about that and knows a quick fix for this.

Transpiling glsl by default

We started the project including babel-glsl-macro in the library to let users just add glslify-type imports that would just work.

We later removed it because we didn't want to make babel a dependency - since your build process would HAVE to include babel core and babel macros.

On the other hand, babel-macros ships by default in:

  • create-react-app
  • gatsby
  • next

The options are:

  • leave it to the user to add a glsl pipeline to their build process
  • add it in the library and require users to add babel & macros if they want to use the features

Questions:

Can we make it fail gracefully if the users don't have macros setup?

if (user.hasMacros) {
   shader = glsl(shader)
}

TODO support simple cases for shaders that don't use chunks

ShaderMaterial and RawShaderMaterial don't use chunks, so you can just use strings and a simpler tree like this

<ComponentMaterial from={RawShaderMaterial}>
   {/* common would be added to both vert and frag */}
   <common>
     <tools.rotate />
     <noise.simplex3rd />
   </common>
   <vert>
      ...all vertex code...
    </vert>
    <frag>
       ...all frag code...
    </frag>
</ComponentMaterial>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.