Texturing splattering on terrain using blending.
Blitz3D Forums/Blitz3D Programming/Texturing splattering on terrain using blending.
| ||
I am searching for some basic basic code of how to blend textures into one surface. i belive its possible. i knwo there is examples but i fail to found them. Here is code. i use a jpg for grass texture i use a jpg for mudd texture i use a 33x33 BMP with black and white in. Ressult of below is not good.. :D but it is as far as i come. Please some one that is king of the hill of blending. help me. ;Blending texture school lession 1. your fist blend. ;Goal is to create 3 textures. 1 grass, 2 Sand, 3 black and wite texture to do alpha of the textures. ;Setup gfx Graphics3D 1280,800,32,2 SetBuffer BackBuffer() Cls camera=CreateCamera() CameraViewport camera,0,0,1280,800 ;Creates a plan mesh of 33x33 vertices mesh=CreateMesh() surf=CreateSurface(mesh) For z=0 To 32 For x=0 To 32 vert=AddVertex (surf,x,0,z,x,z) Next Next For z=0 To 31 For x=0 To 31 V1=Z*33+X V2=(Z+1)*33+X V3=Z*33+X+1 V4=(Z+1)*33+X+1 AddTriangle surf,v1,v2,v3 AddTriangle surf,v3,v2,v4 Next Next ;Position an rotate camera to point to the mesh PositionEntity camera,0,50,0 PointEntity camera,mesh PositionEntity camera,16,25,16 tex_grass=LoadTexture("Grass.jpg") ; loads the grass texture. If Not tex_grass Then RuntimeError "Grass.jpg" TextureBlend tex_grass,2 tex_blend1=LoadTexture("blend1.bmp",4) ;loads the blend1 texture. If Not tex_blend1 Then RuntimeError "Blend1.bmp" TextureBlend tex_blend1,2 ScaleTexture tex_blend1,33,33 tex_mudd=LoadTexture("mudd.jpg") ; loads the mudd texture. If Not tex_mudd Then RuntimeError "mudd.jpg" TextureBlend tex_mudd,2 tex_blend2=LoadTexture("blend2.bmp",4) ;loads the blend1 texture. If Not tex_blend2 Then RuntimeError "Blend2.bmp" TextureBlend tex_blend2,2 ScaleTexture tex_blend2,33,33 EntityTexture mesh,tex_grass,0,1 EntityTexture mesh,tex_blend1,0,2 EntityTexture mesh,tex_mudd,0,3 EntityTexture mesh,tex_blend2,0,4 EntityBlend mesh,1 While Not KeyHit(1) UpdateWorld() RenderWorld Flip Wend |
| ||
I made a second surface, with vertexalpha. So now, there is 2 surface layers on top of each other. Actually you would only need to use 2 layers on the parts where a transition between the two textures is made: |
| ||
Thanks but i know about the vertex alpha.. I ned to know is someone accaly made a good working Blending textures the same way vertex alpha works. but not entity FX32 witch disable zbufffer. Reason for using blending is that it kepps zbuffer intact. and one can have paritcle fx and whater that dosent mix with the terrain in bad ways. So please somone helpme sort out this Blending terrain texture. |
| ||
I think Mikhail FastExt lib does that with no problems at all |
| ||
Are you sure it destroys the z-buffer ? I used BrusFX instead of EntityFx, so the 1st brush should keep it's z buffering. The second brush is rendered on top of it, and -since it has the same z-depth, there should be no problems with the z-order ? |
| ||
YEs iam 100% Vertex Alpha is working as long as every other objects ever aint going to use alpha. No lib for this i know i did this before.. here is sample of vertex alpha... but i want to test out the texture splating with layering and blend the texture via masks. ![]() Last edited 2013 |
| ||
It's definetly possible, but then you have the 8 textures per surface limit on most cards. 4 on some older hardware. Plus your going to need some HUGE textures, with the actual texture tiled on the texture. Because the texture will have to stretch across the entire terrain, with the parts marked black for where you don't want that texture to affect the terrain. That's why the vertex alpha is so handy. You can use smallish textures and get the vertex alpha to fade out the bits you don't want textured with that texture. |
| ||
Finaly some progress... (still issues) I am narrowing it down.. i managed to get 2 textures on one surface. tittled and ican decide witch one that will be shown. http://www.tiberion.eu/blend.zip ; Images and codes. ;Blending texture school lession 1. your fist blend. ;Goal is to create 3 textures. 1 grass, 2 Sand, 3 black and wite texture to do alpha of the textures. ;so the camera rutine will work.. Controll is WASD and rightmouse down + movemouse to turn camera around. Global Camera ;Setup gfx Graphics3D 1280,800,32,2 SetBuffer BackBuffer() Cls camera=CreateCamera() CameraViewport camera,0,0,1280,800 CameraRange camera,0.01,100 CameraClsColor camera,128,128,255 ;Creates a plan mesh of 33x33 vertices mesh=CreateMesh() surf=CreateSurface(mesh) EntityFX mesh,1 ;Full bright as we have no light For z=0 To 32 For x=0 To 32 vert=AddVertex (surf,x,Cos(wave#+x*20),z,x,z) wave#=wave#+0.5 ;Make surface uneven Next Next For z=0 To 31 For x=0 To 31 V1=Z*33+X V2=(Z+1)*33+X V3=Z*33+X+1 V4=(Z+1)*33+X+1 AddTriangle surf,v1,v2,v3 AddTriangle surf,v3,v2,v4 Next Next ;Position an rotate camera to point to the mesh PositionEntity camera,16,5,-4 TurnEntity camera,30,0,0 tex_grass=LoadTexture("Grass.jpg") ; loads the grass texture. If Not tex_grass Then RuntimeError "Grass.jpg" tex_blend2=LoadTexture("blend2.bmp",4) ;loads the blend1 texture. If Not tex_blend2 Then RuntimeError "Blend2.bmp" TextureBlend tex_blend2,1 ScaleTexture tex_blend2,33,33 tex_mudd=LoadTexture("mudd.jpg") ; loads the mudd texture. If Not tex_mudd Then RuntimeError "mudd.jpg" TextureBlend tex_mudd,2 EntityTexture mesh,tex_grass,0,1 EntityTexture mesh,tex_blend2,0,2 EntityTexture mesh,tex_mudd,0,3 ;EntityBlend mesh,3 While Not KeyHit(1) camera_handling() UpdateWorld() RenderWorld Flip Wend ; My Uneversial camera rutine. usfull for editors etc.. jsut paste and use. make sure "Global camera" ; is in at top Function camera_handling() If KeyDown(17) Then MoveEntity camera,0,0,0.05 ;W ;If KeyDown(18) Then MoveEntity camera,0,0,0.05 ; E If KeyDown(31) Then MoveEntity camera,0,0,-0.05 ;S If KeyDown(30) Then MoveEntity camera,-0.05,0,0 ;A If KeyDown(32) Then MoveEntity camera,0.05,0,0 ;D If MouseDown(2) smx#=MouseXSpeed()/10.0 smy#=MouseYSpeed()/10.0 TurnEntity camera,smy#,-smx#,0 RotateEntity camera,EntityPitch#(camera),EntityYaw#(camera),0 ;TranslateEntity camera,0,-0.1,0 MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 End If End Function Last edited 2013 |
| ||
Progress... but still not so cool yet..![]() Last edited 2013 |
| ||
To be perfectly honest. I don't think you'll get great results doing it this way. Not with the size of terrain you are making. Maybe you should chop your terrain into fairly small chunks? That way, your textures won't be stretching over such large areas. |
| ||
yes yes i know the drabacks. but i plan to render these transistions while game is running. I have invented a render Ques to handle one thing at a time.. causeing no damage to FPS. I just want to see the difirense and how much one can push a mordern pc who can take 8 textels. many ask why i trying to use mask instead of alpha.. its simply cause of the Z Buffer is nuked then using alpha. And i dont like to exclude ideas before try em out. to se the drawbacks. Drawback of vertex alpha = z buffer errors and strange unpreticeble thins hapend. I am hoping to get a secondary landscape using blend mode instead of alpha. to visualy se the difirens. |
| ||
Since you are creating the terrain with AddVertex, maybe you could use a big texture that contains all the textures that you'll need as 'tiles' (sort of an AnimImage), with the needed crossovers, and then apply the different tiles using the mesh terrain's uv coordinates ? This way, it would only need one single texture layer. |
| ||
the texture based blending would only work if Mark would give you the possibility to enforce given filtering on the texture. then you could filter the blending texture actually to give it smooth outlines instead of blocky ones. But until this day, there are 2 possible ways: 1. Vertex Alpha Splatting. If you want to get rid of the alpha problem, use an alpha threshold. Normally 0.49+ is used, this will prevent the depth sorting issues to happen normally. 2. Do as Sswifts terrain system, my own old and others do it: split your mesh into chunks of submeshes which use a single baked texture per chunk. This gives you very good detail and good performance but a higher VRAM usage. But if you do that with DDS and DXT compression you should have more or less the fastest possible solution actually. |
| ||
Iam still not done with the texture blending :D herese a nicer smoth one. Thoe vertex alpha is easyer to use i must admit.. but blend cause no problem with the z buffer.. investigating more... ![]() Last edited 2013 |
| ||
As dreamora suggested, have you tried using the alpha limit, to stop the z-order getting messed up. Works fine usually. |
| ||
Stop mungle about alpha. this thread is abouit blending not vertex alpha. :D byt maby i test dreamora ideas... problem is i now use blitz v1.99 witch has Major proglem with my terrain as i am using lockbuffer and readpixelfast.. |
| ||
I have encounter an Expected Flaw.. using Texture Blending Alpha masking... the light information on the sand texture lose light information taken from the Mesh. Mesh | \ / Texture1 | \ / White Mask Full Bright. no way we blend with mesh we blend with texture 1 and ligh info is gone from here on. | \ / Texture2 = Mudd = full bright as the Mask over is bright and dont have light info saved. I hope the above exaplains it.. no light avaiable here lol ? However Eponny has told me that he used his own light info on Blended terrains... this is probably a big drawback as i am planing to have night and days :D |
| ||
What can i say i found a sweet loog 3 years old :/ depressing about texture blending. sswift (Posted 3 years ago) Unfortunately, due to the way texture blending modes work, you can't have a masked texture affected by a light. What you are doing is this: 1. Apply light to white pixel. 2. Multiply first texture color with lit pixel color. 3. Replace pixel with mask texture pixel where mask is opaque. As you can seem the lighting information is lost where the mask replaces the color of the pixel below it. You would need to be able to apply the pixel lighting as the last step rather than the first for this to work. However, I don't know if it would be possible to do that at all, and Blitz certainly does not support it. In addition, doing that would make other effects, such as making parts of a mesh glow despite not being lit, impossible. To achieve the effect you want, what you will have to do instead is use a second surface with the masked texture on it. Then it will have it's own untarnished plain lit pixel to multiply with, resulting in the appearance of being lit like the rest of the mesh. Unfortunately, each surface comes at a great cost, and you will be limited to around 200-400 surfaces visible at once on the screen in your game if you want to maintain an acceptable framerate. Personally I reccomend that you just make two textures, one with moss, one without. It's much simpler, and you're not very likely to run out of texture ram unless you are making a huge project. |
| ||
Check out BSM Render (think that what it was called) it allows normalmapping with light effect. It does that by using a smallsize cubemap for the light handling. You could use that side (without the normalmap) to do the light on your terrain as well by setting this cubemap the highest texture level. And remember: On older hardware 5 textures as well mean 2 surfaces, as those only handle 4 textures in parallel for blending! (old in this case means GF2 class, GF4 mx and the like) |
| ||
This project has encounter a unexpected errror.. .the light information dose not work if one blends.. :/ Well se you all soon in the next thread about vertex alpha and .49 :) |