|
nomadsoul
|
 |
« on: September 03, 2010, 08:29:19 AM » |
|
 hi i've got some probleme with AddAlphaChannel I have a small programm which allow me to take the output webcam frame into truevision texture. Then the texture is calculated to be in 2 color ( black-white), the result is my futur alpha texture! In my doloop sub i have this line: tvtext.AddAlphaChannel(MyTexture, MyTextureToBlack, "alpha51") tv2d.Draw_Texture(globals.GetTex("assassin"), 0, 0, 1024, 512) tv2d.Draw_Texture(globals.GetTex("alpha51"), 0, 0, 1024, 512)
tvtext.DeleteTexture(globals.GetTex("alpha51")) The programme slow down to 8 FPS! Can it be possible to update my alpha51 texture each frame whitout using addalphachannel. The programme work nearly 1700 FPS with output webcam texture in tv and nearly 60 FPS for the black-white texture! Any solution to keep it working at nearly 40 Fps  Thanks 2 vids: http://www.dailymotion.com/video/xenzy9_ditvar-transparent-effect_techhttp://www.dailymotion.com/video/xen0ni_ditvar-v1_videogames
|
|
|
|
|
Logged
|
|
|
|
Lenn
Customers
Community Member
    
Posts: 876
+/-
|
 |
« Reply #1 on: September 03, 2010, 01:38:01 PM » |
|
Create a texture with alpha in the first place, then you won't have to add it every time. Did you miss that, or did I not understand your problem?
|
|
|
|
|
Logged
|
|
|
|
Mithrandir
Community Member

Posts: 325
|
 |
« Reply #2 on: September 04, 2010, 11:41:33 AM » |
|
Depending on what the format of your data is you can use SetPixelArray to change the alpha of an existing texture. It might be faster ...
|
|
|
|
|
Logged
|
|
|
|
Toaster
Community Member

Posts: 378
|
 |
« Reply #3 on: September 04, 2010, 12:57:14 PM » |
|
You could always just use a shader..  but ya what lenn said. -Toaster
|
|
|
|
|
Logged
|
|
|
|
|
nomadsoul
|
 |
« Reply #4 on: September 05, 2010, 04:16:01 AM » |
|
look the two vids post previously please! The alphatexture change every frame due to the webcam output ! I can not use setpixelarray, if i use the ".a" value into 0 it not become transparent. I don't know if shader can be apply on a texture only ( i don't use mesh but just draw2d) 
|
|
|
|
|
Logged
|
|
|
|
Lenn
Customers
Community Member
    
Posts: 876
+/-
|
 |
« Reply #5 on: September 05, 2010, 10:02:36 AM » |
|
You mean, if you use setpixelarray with all .a values = 0, then nothing is transparent? How are you creating the array that you are passing to it that way?
|
|
|
|
|
Logged
|
|
|
|
|
nomadsoul
|
 |
« Reply #6 on: September 06, 2010, 03:19:41 AM » |
|
this is my code tvtext.GetPixelArray(MyTexture, 0, 0, MyBitmapData.Width, MyBitmapData.Height, retwhitecolorarray) If alphabutt.Checked = True Or RadioBLT.Checked = True Then Dim ut As Integer ut = 0 find = 0
For ut = 1 To MyBitmapData.Width * MyBitmapData.Height ' blackorwhith(ut) = New TV_COLOR ' blackorwhith(ut) = globals.DecodeRGBA(retwhitecolorarray(ut)) blackorwhith(ut) = globals.DecodeRGBA(retwhitecolorarray(ut)) ' If blackorwhith(ut).r > redvalueup / 255 = True And blackorwhith(ut).g < 75 / 255 And blackorwhith(ut).b < 90 / 255 Then If blackorwhith(ut).r > redvaluedown / 255 And blackorwhith(ut).r < redvalueup / 255 And blackorwhith(ut).g > greenvaluedown / 255 And blackorwhith(ut).g < greenvalueup / 255 And blackorwhith(ut).b > bluevaluedown / 255 And blackorwhith(ut).b < bluevalueup / 255 Then
blackorwhith(ut) = New TV_COLOR(0, 0, 0, 0) ' blackorwhith(ut).a = 0 Else blackorwhith(ut) = New TV_COLOR(1, 1, 1, 1) ' blackorwhith(ut).a = 1 End If
retwhitecolorarray(ut) = globals.RGBA(blackorwhith(ut).r, blackorwhith(ut).g, blackorwhith(ut).b, 1) ' fff((Int(ut / 640) - (ut / 640) * 480), ut / 640) = blackorwhith(ut).r
If blackorwhith(ut).r = 0 Then find = find + 1 whereiswhith(find) = ut End If
Next tvtext.LockTexture(MyTextureToBlack, False) tvtext.SetPixelArray(MyTextureToBlack, 0, 0, MyBitmapData.Width, MyBitmapData.Height, retwhitecolorarray) tvtext.UnlockTexture(MyTextureToBlack, True) This code show how the black-white texture is created
|
|
|
|
|
Logged
|
|
|
|
Lenn
Customers
Community Member
    
Posts: 876
+/-
|
 |
« Reply #7 on: September 06, 2010, 06:04:30 AM » |
|
Thats kind of confusing to me because I wouldn't do it that way, but why are you setting alpha always as 1? retwhitecolorarray(ut) = globals.RGBA(blackorwhith(ut).r, blackorwhith(ut).g, blackorwhith(ut).b, 1)
shouldnt it be like this: retwhitecolorarray(ut) = globals.RGBA(blackorwhith(ut).r, blackorwhith(ut).g, blackorwhith(ut).b, blackorwhith(ut).a)

|
|
|
|
|
Logged
|
|
|
|
|
nomadsoul
|
 |
« Reply #8 on: September 07, 2010, 04:07:18 AM » |
|
yea when i post my message i see my error i correct it into my game but 0 or 1 doesn't change every think ! only addalphachanel work ! it come from tv2d.drawtexture ? when i set scene.setautotransparentcolor into black , it doesn't work too !
|
|
|
|
|
Logged
|
|
|
|
Lenn
Customers
Community Member
    
Posts: 876
+/-
|
 |
« Reply #9 on: September 07, 2010, 09:01:36 AM » |
|
You don't need AddAlphaChannel. Look, this: tex = TexFact.CreateTexture(256, 256, False, "TexName") TexFact.AddAlphaChannel(tex, alphatex, "TexNewName")
is same as this: tex = TexFact.CreateTexture(256, 256, True, "TexName")
alphatex can be an 8bit texture, or a texture that already has an alpha channel. I am using texture with alpha, and it always works. You can write alpha to the texture using SetPixel for example. Dim ccol as Integer ccol = Globals.RGBA(0,0,0, YourAlphaValue)
TexFact.SetPixel(tex, x,y, ccol)
tex needs to be locked. It always works, IF YOU create the texture with HasAlpha = true (read above). So if it doesnt work, you're doing something else wrong. DrawTexture is working just fine.
|
|
|
|
|
Logged
|
|
|
|
|
nomadsoul
|
 |
« Reply #10 on: September 07, 2010, 02:36:32 PM » |
|
 i am very very very NUL and newbie i use tv3d for a long time and i have forget the true when i creat my texture ! Thanks a lot for your help ! Now it run nearly 150 FPS when i render my Transparent texture !
|
|
|
|
|
Logged
|
|
|
|
|
serial
|
 |
« Reply #11 on: September 07, 2010, 07:45:12 PM » |
|
I bet it would be worth checking out how to do this in a shader.
|
|
|
|
|
Logged
|
|
|
|
Lenn
Customers
Community Member
    
Posts: 876
+/-
|
 |
« Reply #12 on: September 08, 2010, 06:56:06 AM » |
|
 i am very very very NUL and newbie i use tv3d for a long time and i have forget the true when i creat my texture ! Thanks a lot for your help ! Now it run nearly 150 FPS when i render my Transparent texture ! You are welcome. Read the intellisense a little better, sometimes it pays to just go thru the method list for various tv classes. I bet it would be worth checking out how to do this in a shader.
In a shader it would be 800 FPS and very easy to do, IF you know how to make them. He's probably happy as it is. 
|
|
|
|
|
Logged
|
|
|
|
|
nomadsoul
|
 |
« Reply #13 on: September 09, 2010, 02:36:23 AM » |
|
Is it possible to apply a shader on a texture and then render the result with tv2d.drawtexture ? if yes i will use this method because we can make more effect with shader and it's more easy than using my own algorythm on each pixel ! 
|
|
|
|
|
Logged
|
|
|
|
|
|
|
nomadsoul
|
 |
« Reply #15 on: September 09, 2010, 01:54:29 PM » |
|
"fullscreen" mean without any form ? or mean that it render in all tv3d screen (picturebox) ? the result can be a picture to be save into memory or a file ?
thanks
|
|
|
|
|
Logged
|
|
|
|
|
ZaPPZion
|
 |
« Reply #16 on: September 09, 2010, 05:19:20 PM » |
|
it is possible to render to a picturebox as well, so you're fine with going for that approach
|
|
|
|
|
Logged
|
|
|
|
|
nomadsoul
|
 |
« Reply #17 on: September 11, 2010, 04:41:08 AM » |
|
I took the tutorial number 21 from "Arius Tutorials VB.NET" call "HLSL Per pixel object". I have try to implement my own code but it doesn't work. I try to take a texture, create a fullscreenshader and render the result with tv2d.drawtexture. Can you tell me what it's wrong in this code ? ( the shader work well for the cube but not for fullscreenshader) Public Class Form1 Private TV As TVEngine 'This is the main engine class. It's all we require for a blank screen. Private Scene As TVScene 'This is used for instantiating resource types - Geometry, Render Targets, Shaders and so on. Private TF As TVTextureFactory 'This is for basic texturing functionality Private Cube As TVMesh 'This is the mesh that will contain the cube we're going to render. Private Cam As TVCamera 'This is a camera Private tv2d As TVScreen2DImmediate Private Shader As TVShader 'This is our post shader. Private Text2D As TVScreen2DText 'We're gonna need some text so we know how much bump is being applied. Private Input As TVInputEngine 'We want to +/- the bump amount on keypress, so we need some input.
Private fTime As Single 'This is our tick value Private bLoop As Boolean 'This variable will make sure the program loops Private IDDiffuse As Integer 'This is an ID for our texture. You can store a string also, but that's slower. Private IDNormal As Integer 'This is an ID for our bump texture. RGB is a normal map, A is a parallax map. I've done it this way to demonstrate that you can pack data in textures. So here we have all of our required bumping information in one sole RGBA texture map - instead of 2 seperate ones. Private IDFont As Integer 'This is an ID for our font texture. Private survace As TVRenderSurface Private fBumpAmount As Single Private screen As TVRenderSurface 'This is our bump amount.
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated SetupScene(Me.Handle) 'Setup the engine. We need to send the handle of this form, since the engine needs to know where to render to. bLoop = True 'Make it possible to run the loop Main_Loop() 'Let's execute the main loop End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Show() End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing bLoop = False 'Stop the loop End Sub
Private Sub SetupScene(ByVal hWnd As IntPtr) 'Instantiate the classes. NOTE: We do not instantiate geometry in this way. TV = New TVEngine Scene = New TVScene TF = New TVTextureFactory Cam = New TVCamera Text2D = New TVScreen2DText Input = New TVInputEngine tv2d = New TVScreen2DImmediate 'Now, lets initialize the engine. It's important to understand that this must be done before any other TV class is used - with the exception of TVDeviceInfo. TV.SetDebugFile("c:debug21.txt") 'Set the debug file to the same folder as the program itself. This is very useful, Sylvain is good at catching common mistakes and informing you that you've made them in this files log. TV.Init3DWindowed(hWnd, True) 'We want to initialize on our windows handle and we have hardware transform and lighting.
survace = Scene.CreateRenderSurface(512, 512, True, CONST_TV_RENDERSURFACEFORMAT.TV_TEXTUREFORMAT_A8R8G8B8, "ess") Input.Initialize(True, False) 'We don't need the mouse, so we set it to false
'Load the texture into the integer ID holder IDDiffuse = TF.LoadTexture("..\\..\\..\\..\\common\\tv3dlogo_d.dds", "diffuse texture", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, True) IDNormal = TF.LoadTexture("..\\..\\..\\..\\common\\tv3dlogo_n.dds", "bump texture", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_USE_ALPHA_CHANNEL, True)
'Create a texture font. IDFont = Text2D.TextureFont_Create("font", "consolas", 8, True, False, False, False, True)
'Set a starting bump amount. We'll start low. fBumpAmount = 1
'Create and load our shader Shader = Scene.CreateShader("object_post") Shader.CreateFromEffectFile("..\\..\\..\\..\\common\\shaders\\ppl.shade") Shader.SetEffectParamVector3("LPos", New TV_3DVECTOR(0, 5, -50)) 'Give the shader a 3-vector, the shader will take this as a light position. Shader.SetEffectParamFloat("BumpAmount", fBumpAmount)
'Now we instantiate our geometry Cube = Scene.CreateMeshBuilder("Cube") Cube.CreateBox(5, 5, 5, False) 'We create a box of 5x5x5 units. Cube.SetTexture(IDDiffuse, -1) 'Apply the texture to the cube Shader.SetEffectParamTexture("Normal", IDNormal) 'Set our bump map so the shader can find it. You can do this via semantics, but I wanted to demonstrate SetEffectParam etc.
'Apply the shader to the mesh. Cube.SetShader(Shader) 'Tell TV we want tangent information etc. 'Cube.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_BUMPMAPPING_TANGENTSPACE, 0, 0)
Cam.SetPosition(0, 0, -10) 'We move the camera 20 units back on the Z axis, because the cube is at (0;0;0). So we move it back in order to see it. End Sub
Private Sub Main_Loop() Dim iTextColor As Integer = New TV_COLOR(1, 1, 1, 1).GetIntColor() While (bLoop) fTime = TV.AccurateTimeElapsed() 'render a frame TV.Clear() ' Cube.Render() tv2d.Action_Begin2D() tv2d.Draw_Texture(survace.GetTexture, 0, 0, 512, 512) tv2d.Action_End2D() Cube.Render() TV.RenderToScreen() rendersurface() UpdateScene() 'Update our scene. We want the cube to spin. Application.DoEvents() End While TV.ReleaseAll() 'if the loop ends, everything needs to be released TV = Nothing Me.Close() End Sub
Private Sub UpdateScene() 'Rotate the cube by an amount scaled by our fTime tick variable. ' Cube.RotateX(0.00003 * fTime, True) ' Cube.RotateY(0.0003 * fTime, True) ' Cube.RotateZ(0.000003 * fTime, True)
If (Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_1)) Then fBumpAmount += 0.001 * fTime Shader.SetEffectParamFloat("BumpAmount", fBumpAmount) End If If (Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_2)) Then fBumpAmount -= 0.001 * fTime Shader.SetEffectParamFloat("BumpAmount", fBumpAmount) End If End Sub Private Sub rendersurface() survace.StartRender()
'tv2d.Draw_Texture(IDNormal, 0, 0, 512, 512) tv2d.Draw_FullscreenQuadWithShader(Shader, 0, 0, 512, 512)
survace.EndRender() End Sub End Class
|
|
|
|
« Last Edit: September 11, 2010, 04:59:56 AM by nomadsoul »
|
Logged
|
|
|
|
|
ZaPPZion
|
 |
« Reply #18 on: September 11, 2010, 08:12:49 AM » |
|
Go for the #20 tutorial, that's with fullscreenquad  Or the #22 tutorial, that's also a fullscreen effect.
|
|
|
|
|
Logged
|
|
|
|
|
nomadsoul
|
 |
« Reply #19 on: September 11, 2010, 10:35:33 AM » |
|
 thanks, i have found another way (and better), for me i just want to render my webcam output frame into picturebox with tv3d and apply effect then export the result ! I have made a big box that take the all screen apply my output wecam frame as a texture on it. then i can aplly to the box all shader i want and export the result (vertex and pixelshader)! It work better than fullscreenquad. And i can apply light on the box... Thanks for your help Guys
|
|
|
|
|
Logged
|
|
|
|
|