virtual-world-framework / vwf

Virtual World Framework
https://virtual.wf
Other
142 stars 53 forks source link

Branch/shader material support #493

Closed BrettASwift closed 9 years ago

BrettASwift commented 9 years ago

Fixed some issues with shader material components. The uniforms list was being passed by reference, so multiple materials extending the same shader material component were overwriting each other. To fix this, I made it so that the uniforms list is copied in the driver when a node is created, so a new uniforms object is created instead of using the reference of the old one. I added the function getUniformValueByType to assist in initializing the shader values in the uniforms list to the appropriate type. There are many more types that should probably be handled, but I haven't had a use case that compelled me to do it.

I also made it so that you can change the value of a uniform by simply setting a property of the same name on the node. If that property name is not handled sooner (if it is named vertexShader, for instance, it will not reach the uniform setting conditional. Obviously uniforms should be named uniquely). The uniforms list creates the uniforms on the shader material threeObject and the properties allow you to set the value without having to set the type or use the this.uniforms.property.value syntax.

Additionally, I needed a way to store data on the threeObject itself for use in the updateFunction. To do this, I made it so that properties starting with an underscore (_time for instance) are stored on the threeObject. The only other way was to set them as uniforms, which isn't a good way to do it.

I also added the ability to set the lights property on a shader material so that three js will pass the light data to it. There are probably more material properties that should be exposed in the same way.

So far, this is the best way I could think of to accomplish all of this and it works very well so far. The VWF node/component model doesn't innately handle the complexity of shader materials well, so a lot of this feels somewhat hacky, but it's necessary in order to expose all of the options to developers.

@kadst43 @AmbientOSX

@scottnc27603 @eric79 This is going into the mars-game branch for now, but with the intent to eventually make it to development, so if you want to look over it, that would be good.

kadst43 commented 9 years ago

It's all black magic to me, but appears to be working without adverse effects. :+1: