Shading Terrains?
Blitz3D Forums/Blitz3D Programming/Shading Terrains?
| ||
Hey, I'm still workin on the "visible polys on terrain" project, but i figured out that the function that Stevie if im not wrong, gave me, is not good enough for my needs. So someone there said "why won't you put a spotlight and shade the not visible areas?" So what i need is a sample of how if at all possible, i can use devils shadow system in order to shadow the not visible areas on the same mesh(i mean the receiver and the caster would be the same mesh so hills would cast on the ground. like creating dynamically a lightmap for the terrain by a given position of the spotlight). the terrain mesh is about 25k polys i think( its not the same mesh all the time), so i might need a function to divide the mesh to blocks. Thanks in advance |
| ||
Are we going to break a record? nevermind. well here is the topic i was talking about: http://blitzbasic.com/Community/posts.php?topic=77338#865829 |
| ||
Like I said - post or e-mail your code and explain explicitly what you want ( a picture would be a help too ) and I ( and others ) should be able to help. |
| ||
do you want the whole code? or just a part of it? EDIT: nevermind. I didn't want to do that but youve asked for it(muhahahaha), here is my very not organized code: So my need is a function that would be used like that: spotlight1=createlight(); I guess positionentity spotlight1,entityx(camera_pivot),entity(camera_pivot),entityz(camera_pivot) if keyhit(key_r) shadeterrainacordingtospotlight(terrain1,spotlight1) end if or another option is if keyhit(key_r) shadeterrainacordingtoposition(terrain1,x,y,z) end if so what will come out will be like the function you gave me using line pick on last topic, but it should be much more accurated(the problem with tha function you gave is that it send a linepick to the center of the triangle, but my need is like to send it to every single point on the triangle and even if one is visible then color the triangle(and some why it wasnt accurated and colored some triangle wrong) |
| ||
When I said post the code - I meant something which I can run without other include files / media etc.. btw. Native spotlights are going to light hidden poly's so this isn't what you want. The function I gave you could be easily amended to do a check on all 3 vertices of the triangle. Function TRIScolor( Mesh , Viewer ) ;get viewers direction normal TFormNormal 0,0,1,Viewer, 0 CamNx# = TFormedX() CamNy# = TFormedY() CamNz# = TFormedZ() For su = 1 To CountSurfaces( Mesh ) s = GetSurface( Mesh , su ) For t = 0 To CountTriangles( s ) - 1 ;get vertices in triangle - normals should be same on each v0 = TriangleVertex( s, t, 0 ) v1 = TriangleVertex( s, t, 1 ) v2 = TriangleVertex( s, t, 2 ) ;get triangle normal in world space coords TFormVector VertexNX( s, v0 ), VertexNY( s, v0 ) , VertexNZ( s, v0 ) , Mesh , 0 TriNx# = TFormedX() TriNy# = TFormedY() TriNz# = TFormedZ() ;compute dot product of camera normal and tri normal CdotN# = CamNx * TriNx + CamNY * TriNy + CamNz * TriNz ;default rgb to white tR = 255 tG = 255 tB = 255 If CdotN <= .000001 Then ;this triangle is facing camera so check whether any of the vertices are obscured For v = v0 To v2 ;get vertex position in world space coords TFormPoint VertexX( s, v ) , VertexY( s, v ) , VertexZ( s, v ), mesh, 0 ;get direction vector from vertex position to viewer Dx# = TFormedX() - EntityX( viewer, 1 ) Dy# = TFormedY() - EntityY( viewer, 1 ) Dz# = TFormedZ() - EntityZ( viewer, 1 ) ;do a linepick from the viewer to the vertex Picked = LinePick( EntityX( viewer , 1 ) , EntityY( viewer , 1 ) , EntityZ( viewer , 1 ) , Dx, Dy , Dz ) ;the linepick hit something so this tri is obscured If PickedTime() < 1.0 tR = 255 tG = 0 tB = 0 Exit EndIf Next EndIf ;color this triangle For v = v0 To v2 VertexColor s, v, tR, tG , tB Next Next Next End Function Does this work for you? Stevie |
| ||
I'm pretty noob in blitz but not that i cant think of doing that for the 3 vertexes. even though when ive done that, it wasn't really accurate(it was even worse when using all the 3 vertexes) and colored wrongly. |