WebGL and weird varying variable

Started by
2 comments, last by WoopsASword 7 years, 11 months ago

Hi, there! I am learning WebGL. I am trying to merge an example about shadowing and another about textures to achieve shaded texture. But something weird happens. I delete the varying assignment and it is working better than using the varying. I say better, because it is never working. You can check the code in the link I added. Thanks in advance!

https://drive.google.com/folderview?id=0B7GT_P0j23JAOXdodzlkbEY0Yjg&usp=sharing

Advertisement

First of all, it would be better to read the shaders in an external files. you don't need to be a muggle.

Secondly, "Varying" means your data is trasnfered between the shaders but with interpolation based on the fragment location.

That's why you get a different value.

And last for your issue:

Did you mean light effect? I don't see any trace for shadow rendering. (Usually it's done via double rendering or more math :) )

Try using a different algorithm, honsetly it is the first time I see something like this,

what is the result of your dot product in the fragment shader? and what are the magic numbers in setting this "reverseLightDirection" ?

Maybe I should say 'lightning' instead "shadowing". In the example code in the WebGL reference card, there the varying is used the same way I use it. Have you tried it in your machine? the best result I achieve so far is to load and show that 1px texture and then it turns black, but outcommenting the varying line in the vertex shader which is wrong to do it, but only this way I can see something on the screen. If you manage to see the "light"-ed texture, let me know how you did it. (if you run the index.html you will see the shaders codes nicely printed in an alert box)

Maybe I should say 'lightning' instead "shadowing". In the example code in the WebGL reference card, there the varying is used the same way I use it. Have you tried it in your machine? the best result I achieve so far is to load and show that 1px texture and then it turns black, but outcommenting the varying line in the vertex shader which is wrong to do it, but only this way I can see something on the screen. If you manage to see the "light"-ed texture, let me know how you did it. (if you run the index.html you will see the shaders codes nicely printed in an alert box)

I would love to help you with the implementation but it would take me some time, which I don't have.

I mentioned to you that you have something weird about how you implement the lighting. Try ambient lighting which is really easy (Just one variable).

If you come to implement diffuse light (Directional for example) try looking in this tutorial:

http://www.mbsoftworks.sk/index.php?page=tutorials&series=1&tutorial=11

The concepts are almost identical.

This topic is closed to new replies.

Advertisement