Minus_Alpha argument

Everything related to 3D programming
User avatar
Lexicon
User
User
Posts: 98
Joined: Mon Jul 22, 2013 6:16 am
Contact:

Minus_Alpha argument

Post by Lexicon »

Hi!

This is model was exported from 3d max.

Screen: http://stalkerfangroup.ru/Stalker_2/sho ... -56-34.jpg

This is material

Code: Select all

material mtl_fence_01_S
{
	technique
	{
		pass
		{
			ambient 0.588 0.588 0.588 1 
			diffuse 0.588 0.588 0.588 1 
			specular 0 0 0 1 10 
			scene_blend one one_minus_src_alpha 
			cull_hardware none 
			cull_software none

			texture_unit 
			{
				texture mtl_fence_01.dds 
			}
		}
	}
}
material mtl_pod_01_S3
{
	technique
	{
		pass
		{
			ambient 0.588 0.588 0.588 1 
			diffuse 0.588 0.588 0.588 1 
			specular 0 0 0 1 10 
			scene_blend one one_minus_src_alpha 

			texture_unit 
			{
				texture mtl_pod_01.dds
			}
		}
	}
}
material prop_barbwire3_S
{
	technique
	{
		pass
		{
			ambient 0.588 0.588 0.588 1 
			diffuse 0.588 0.588 0.588 1 
			specular 0 0 0 1 10 
			scene_blend one one_minus_src_alpha 
			cull_hardware none 
			cull_software none

			texture_unit 
			{
				texture prop_barbwire3.dds
			}
		}
	}
}
Create Entity with #PB_Material_None argument.

Where is mistake? Why alpha not removed? Alpha channel are present.
Thanks
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Minus_Alpha argument

Post by Samuel »

Hello.

If I understood your question correctly you just have a small mix up.

Instead of [scene_blend one one_minus_src_alpha] use [scene_blend one one_minus_dest_alpha].
Then you should have black instead of alpha.

The format goes like this [scene_blend <source> <destination>].
So in your case you had a source in your destination.

I don't have a great knowledge on this subject. So, if anyone sees a mistake please correct me.

The new material script.

Code: Select all

material mtl_fence_01_S
{
   technique
   {
      pass
      {
         ambient 0.588 0.588 0.588 1
         diffuse 0.588 0.588 0.588 1
         specular 0 0 0 1 10
         scene_blend one one_minus_dest_alpha
         cull_hardware none
         cull_software none

         texture_unit
         {
            texture mtl_fence_01.dds
         }
      }
   }
}
material mtl_pod_01_S3
{
   technique
   {
      pass
      {
         ambient 0.588 0.588 0.588 1
         diffuse 0.588 0.588 0.588 1
         specular 0 0 0 1 10
         scene_blend one one_minus_dest_alpha

         texture_unit
         {
            texture mtl_pod_01.dds
         }
      }
   }
}
material prop_barbwire3_S
{
   technique
   {
      pass
      {
         ambient 0.588 0.588 0.588 1
         diffuse 0.588 0.588 0.588 1
         specular 0 0 0 1 10
         scene_blend one one_minus_dest_alpha
         cull_hardware none
         cull_software none

         texture_unit
         {
            texture prop_barbwire3.dds
         }
      }
   }
}
User avatar
Lexicon
User
User
Posts: 98
Joined: Mon Jul 22, 2013 6:16 am
Contact:

Re: Minus_Alpha argument

Post by Lexicon »

Samuel wrote:Hello.

If I understood your question correctly you just have a small mix up.

Instead of [scene_blend one one_minus_src_alpha] use [scene_blend one one_minus_dest_alpha].
Then you should have black instead of alpha.

The format goes like this [scene_blend <source> <destination>].
So in your case you had a source in your destination.

I don't have a great knowledge on this subject. So, if anyone sees a mistake please correct me.

The new material script.

Code: Select all

material mtl_fence_01_S
{
   technique
   {
      pass
      {
         ambient 0.588 0.588 0.588 1
         diffuse 0.588 0.588 0.588 1
         specular 0 0 0 1 10
         scene_blend one one_minus_dest_alpha
         cull_hardware none
         cull_software none

         texture_unit
         {
            texture mtl_fence_01.dds
         }
      }
   }
}
material mtl_pod_01_S3
{
   technique
   {
      pass
      {
         ambient 0.588 0.588 0.588 1
         diffuse 0.588 0.588 0.588 1
         specular 0 0 0 1 10
         scene_blend one one_minus_dest_alpha

         texture_unit
         {
            texture mtl_pod_01.dds
         }
      }
   }
}
material prop_barbwire3_S
{
   technique
   {
      pass
      {
         ambient 0.588 0.588 0.588 1
         diffuse 0.588 0.588 0.588 1
         specular 0 0 0 1 10
         scene_blend one one_minus_dest_alpha
         cull_hardware none
         cull_software none

         texture_unit
         {
            texture prop_barbwire3.dds
         }
      }
   }
}
Hi Samuel and thank you.
But now background of the image is black. No transparent. I want to do the grid (net). But alpha is not removed.

http://stalkerfangroup.ru/Stalker_2/sho ... -40-00.jpg
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
User avatar
Lexicon
User
User
Posts: 98
Joined: Mon Jul 22, 2013 6:16 am
Contact:

Re: Minus_Alpha argument

Post by Lexicon »

YESS!!! :D

I found this Comtois post...

http://www.purebasic.fr/english/viewtop ... 50#p393450

and change my material...

Code: Select all

material mtl_fence_01_S
{
	technique
	{
		pass
		{
			cull_hardware none
			cull_software none
			scene_blend alpha_blend
			depth_write off

			texture_unit 
			{
				texture mtl_fence_01.dds
			}
		}
	}
}
material mtl_pod_01_S3
{
	technique
	{
		pass
		{
			texture_unit 
			{
				texture mtl_pod_01.dds
			}
		}
	}
}
material prop_barbwire3_S
{
	technique
	{
		pass
		{
			cull_hardware none
			cull_software none

			scene_blend alpha_blend
			depth_write off

			texture_unit 
			{
				texture prop_barbwire3.dds
			}
		}
	}
}

Now I have right the net!

http://stalkerfangroup.ru/Stalker_2/sho ... -25-28.jpg
http://stalkerfangroup.ru/Stalker_2/sho ... -40-89.jpg

:D
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Minus_Alpha argument

Post by Samuel »

I'm sorry I misunderstood the question. I thought that you wanted to remove the alpha and then draw a solid color in its place. I'm glad you figured it out though.
User avatar
Lexicon
User
User
Posts: 98
Joined: Mon Jul 22, 2013 6:16 am
Contact:

Re: Minus_Alpha argument

Post by Lexicon »

Samuel wrote:I'm sorry I misunderstood the question. I thought that you wanted to remove the alpha and then draw a solid color in its place. I'm glad you figured it out though.
Thanks Samuel! You gave me an idea! :wink:
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
User avatar
Lexicon
User
User
Posts: 98
Joined: Mon Jul 22, 2013 6:16 am
Contact:

Re: Minus_Alpha argument

Post by Lexicon »

Yes, all are fine! But we are not looking for the easy ways! :D

There is a problem after the BuildMeshShadowVolume().

http://stalkerfangroup.ru/Stalker_2/sho ... -23-34.jpg
http://stalkerfangroup.ru/Stalker_2/sho ... -42-28.jpg

What is it who knows?
Thanks!
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
User avatar
Lexicon
User
User
Posts: 98
Joined: Mon Jul 22, 2013 6:16 am
Contact:

Re: Minus_Alpha argument

Post by Lexicon »

Oh, excuse me. Pictures have been updated.
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Minus_Alpha argument

Post by Samuel »

I can think of three things that might cause this problem.

First, is there more then one light. You could try just using a single light and see if you get the same result.
That probably isn't the problem, but just in case you could give it a try.

Second, are the normals of the mesh facing the wrong way. I've had meshes with the normals reversed and the shadows had a similar effect.

Third, does your mesh have facing on front and back of both sides. Since, there is alpha involved I could see a problem like this happening.

Hope this helps. Let me know if you need more info on one of these three things.
Olby
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Jan 12, 2009 10:33 am
Contact:

Re: Minus_Alpha argument

Post by Olby »

Lexicon wrote:Yes, all are fine! But we are not looking for the easy ways! :D

There is a problem after the BuildMeshShadowVolume().

http://stalkerfangroup.ru/Stalker_2/sho ... -23-34.jpg
http://stalkerfangroup.ru/Stalker_2/sho ... -42-28.jpg

What is it who knows?
Thanks!
Not sure about OGRE stencil shadows but the ones I've used throughout the years never support alpha maps. In other words you can not have stencil shadows (the ones you use in the pictures) to render alpha shadows. Have a look at Doom3. It also uses stencil shadows (opposed to texture/shader based shadows).
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
User avatar
Lexicon
User
User
Posts: 98
Joined: Mon Jul 22, 2013 6:16 am
Contact:

Re: Minus_Alpha argument

Post by Lexicon »

Thanks Samuel.
Olby wrote:Not sure about OGRE stencil shadows but the ones I've used throughout the years never support alpha maps. In other words you can not have stencil shadows (the ones you use in the pictures) to render alpha shadows. Have a look at Doom3. It also uses stencil shadows (opposed to texture/shader based shadows).
Hi Olby and thanks for your answer.
Ok, no stancil shadows. However, please look at the screen.

http://stalkerfangroup.ru/Stalker_2/sho ... -42-28.jpg

After BuildMeshShadowVolume() function net is black again. But when you'll see at the shadow of net through the net you'll see an amazing view. I think that I gotta insert some strings into the material.
What I gotta do?

Thanks.
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: Minus_Alpha argument

Post by Bananenfreak »

In my opinion you don´t Need BuildMeshShadowVolume(). shadows work in my program without it.

The reason why the shadow is so... ugly is that left Hand doesn´t know what the right Hand does.
In our case: Material is splitted from Mesh.
Shadows are calculated with the mesh, and this is a plane without any holes (the fence). What we see, is the Material. You ordered the Material to be with Alpha_blend, but you missed the shadow.

I´ve already tried to get this working (For my trees ^^), but I failed :(

According to the OGRE Forum, you have to write your own shadowcaster (caster, not the same as Receiver). You have to calculate the shadow and delete These Pixels, where your texture (alphamap) has a value greater than ~128 or so.

http://www.ogre3d.org/forums/viewtopic.php?f=2&t=58992

If anyone knows how to get this working, please tell us :)
Image
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Minus_Alpha argument

Post by Samuel »

Is this what you guys want? This is a material script that will cast a shadow through any alpha on materials.

First, the script.

AlphaToShadow.MATERIAL

Code: Select all

material Transparent
{
   receive_shadows off
   transparency_casts_shadows off
   technique Default
   {
      pass Main
      {
         ambient 0.8 0.8 0.8 0.8
         specular 0 0 0 0 0
         emissive  0.8 0.8 0.8 0.8

         cull_hardware none
         cull_software none
         scene_blend alpha_blend 
         
         alpha_rejection greater 128 
         depth_write on 

         
         texture_unit
         {
             //CHANGE Spark1.png to a texture that has some alpha.
            texture Spark1.png -1
         }         
      }
   }
}
Now, the code to run and display the script.
Don't Forget to set the paths for the script and texture.

Code: Select all

;PRESS Escape to exit

#CameraSpeed = 1

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()

  InitSprite()
  InitKeyboard()
  InitMouse()
  ExamineDesktops()
  
DeskWid=DesktopWidth(0)
DeskHei=DesktopHeight(0)

Add3DArchive("C:\Script", #PB_3DArchive_FileSystem);####SET THE PATH TO YOUR MATERIAL SCRIPT.
Add3DArchive("C:\Texture", #PB_3DArchive_FileSystem);####SET THE PATH TO YOUR TEXTURE THAT THE MATERIAL SCRIPT USES.

 If OpenWindow(0, 0, 0, DeskWid, DeskHei, "Alpha to Shadow", #PB_Window_ScreenCentered)
  If OpenWindowedScreen(WindowID(0), 0, 0, DeskWid, DeskHei, 0, 0, 0)
    
    Parse3DScripts()
    
    GetScriptMaterial(BoxMaterial, "Transparent")
    
    BoxMesh=CreateCube(#PB_Any,40)
    BoxEntity=CreateEntity(#PB_Any,MeshID(BoxMesh),MaterialID(BoxMaterial),0,-15,0)
    
    PlaneTexture=CreateTexture(#PB_Any,32,32)
    StartDrawing(TextureOutput(PlaneTexture))
      Box(0,0,32,32,RGB(0,0,255))
    StopDrawing()
    
    PlaneMaterial=CreateMaterial(#PB_Any, TextureID(PlaneTexture))
    
    PlaneMesh=CreatePlane(#PB_Any,10000,10000,10,10,10,10)
    PlaneEntity=CreateEntity(#PB_Any,MeshID(PlaneMesh),MaterialID(PlaneMaterial),0,-40,0)
    EntityRenderMode(PlaneEntity,0)
    
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, -50, 0, 100, #PB_Absolute)
    CameraLookAt(0,0,0,0)

    CreateLight(0,RGB(255,255,255),500,500,200)
    
    WorldShadows(#PB_Shadow_TextureAdditive, 0, RGB(127, 127, 127), 4096)
    
    Repeat
            
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf  
      
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed 
        Else
          KeyX = 0
        EndIf
                  
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed 
        Else
          KeyY = 0
        EndIf

      EndIf
            
      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera(0, KeyX, 0, KeyY)

    
      RenderWorld()

      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) 
  EndIf
 EndIf
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
  
End
I hope this took care of your problems. If not let me know.
User avatar
Lexicon
User
User
Posts: 98
Joined: Mon Jul 22, 2013 6:16 am
Contact:

Re: Minus_Alpha argument

Post by Lexicon »

Bananenfreak wrote:http://www.ogre3d.org/forums/viewtopic.php?f=2&t=58992

If anyone knows how to get this working, please tell us :)
Thanks Bananenfreak. I'll thinking.
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Minus_Alpha argument

Post by Samuel »

Check my previous post. Should take care of his and your problem. I think.....
Post Reply