Thứ Năm, 25 tháng 7, 2013

Thursday Has Better Veg

Veg Improvements

Thanks to an urgent rush on a veg model, some tinkering and tweaking, the terrain module how has a better vegetation system which looks better, does not overhang cliffs, fits better on the ground and is faster for performance too.

Terrain Edit Cursor Highlighter

Thanks to the fact I am using a shader for my terrain, and I no longer need to save four texture stages for cascade shadow mapping, I have added three more diffuse texture options and a cursor highlighter texture as the last texture stage. Using some pokery, I am able to have the cursor render at the mouse coordinate during editing, and also reflect the radius of the brush which is now under shortcut control. It looks pretty snazzy too, as though a glowing light of creation spawns terrain from it's terrible orb of power :)

More Shader Fun

To combine the different textures coming into the terrain, I am using a control map (the veg shader map I mentioned in previous blogs) and rather that gobble up my useful channels, I can specify which of the five diffuse textures from a single Blue channel of the control map.  Here some code which does it:

float texselectorV = tex2D(NormalSampler,IN.TexCoord/500.0f).b;
float texselectorcol1 = max(0,0.25f-abs(texselectorV-0.00))*4.0f;
float texselectorcol2 = max(0,0.25f-abs(texselectorV-0.25))*4.0f;
float texselectorcol3 = max(0,0.25f-abs(texselectorV-0.50))*4.0f;
float texselectorcol4 = max(0,0.25f-abs(texselectorV-0.75))*4.0f;
float texselectorcol5 = max(0,0.25f-abs(texselectorV-1.00))*4.0f;
float3 textpart1 = tex2D(DiffuseSampler1,IN.TexCoord).xyz*texselectorcol1;
float3 textpart2 = tex2D(DiffuseSampler2,IN.TexCoord).xyz*texselectorcol2;
float3 textpart3 = tex2D(DiffuseSampler3,IN.TexCoord).xyz*texselectorcol3;
float3 textpart4 = tex2D(DiffuseSampler4,IN.TexCoord).xyz*texselectorcol4;
float3 textpart5 = tex2D(DiffuseSampler5,IN.TexCoord).xyz*texselectorcol5;

finalcolor.xyz = textpart1+textpart2+textpart3+textpart4+textpart5;

Neat I know, but when you have limited resources you need to get creative with what you have. Old school 8 bit experience that one!  I've also been impressed with the raw power of the GPU when running shaders. Almost all my bottlenecks have come from poor coding or some intense CPU activity, which is very encouraging for all the wonderful ideas one can perform through a shader!

Signing Off

The plan is to carry on and get the prototype so I can paint to the 'veg shader control map' by writing the texture directly from my program (performance alert) which can then reflect in the textures used by the terrain in real-time. This will lead onto being able to paint the veg color and at the same time the actual veg data which the vegetation system will use to populate the terrain. Right now the veg is being used for the entire terrain, which works fine and fast, but I dare say not everyone will want veg everywhere!

After that, I will add some quick 'randomize terrain' functionality and perhaps some 'save what I have done' code to make sure this edit can be reloaded and continued. The final step will then be to add it to the main FPSC IDE which is what I hope will occupy my Friday and have the weekend as an overflow buffer before the meeting on Monday.  I still have to play S.T.A.L.K.E.R (deferred renderer) which is still in it's shrink wrap :)

Không có nhận xét nào:

Đăng nhận xét