Sunday, April 15, 2012

Troubleshooting

Just got back from short vacation (did zero work on project) and decided to fire up a grandiose workspace with the 42 inch LCD as a second display for the Macbook.  Worked pretty well...except I find myself hunching over...need taller workstation...TV trays aren't cutting it.

My whole goal for the day was to implement my plan for 'dirty' tracking so that I could changing my texturing technique based on whether I was digging pristine virgin ground or adding (or removing) dirt to a location.  Was really only about 10 lines of code...but 4 hours later, I still had issues.  I would get streaky/striped dirt where I was supposed to have a solid dirt texture.   Originally I wanted to use a boolean for my array of 'dirty' vertices but apparently (in WebGL), you cant use a boolean type as a varying...so I switched to using floats: 1.0 for dirty, 0.0 for 'virgin'.

 It was as if the 'dirty' flag was being intermittently interpreted as different values (even if I hardcoded ALL vertices as 'dirty', there would be 'streaks' of grass showing through.  Drove me crazy.  I finally went to bed...but was dreaming/thinking about it until I forced myself awake at 5:00am with a possible plan of attack that didn't work out.  Google searching began, culminating with this bad boy: "webgl fragment shader varying weird problem".  Sure enough, I stumbled across this gem. I knew better than to compare floating point exact values...yet that was exactly what I was doing.....  ==1.0 was dirty and ==0.0 was virgin.  Stupid.  A simple change to use > and < and I was back in business after a 6 hour road bump.

Results look less-than-desirable (my 'dirt' is being shown as textured triangles (I am keeping my poly count low to increase frame rate) and look very stark against the green grass...and not 100% sure if I am going to deal with it.  I could do some complex texture merging based on height and surrounding fragments..or later increase the poly count to smooth things out a bit...but for now, I want to concentrate on using this 'dirty' technique in conjunction with raising the height of the terrain and start piling some dirt.  Can't have a placer mining game without piling dirt near the washplant!

No comments:

Post a Comment