Author Topic: How can we do ?  (Read 10604 times)

0 Members and 1 Guest are viewing this topic.

Offline GuillyGuilly

  • ZX 81
  • *
  • Posts: 12
  • Karma: 0
    • View Profile
How can we do ?
« on: June 08, 2016 »
I would like to have 4 layers

Layer 1 (background) is an effect (plasma)
Layer 2 is a scroll text, with transparency . Black color display the plasma (layer 1)
Layer 3 is an effect (another plasma)
Layer 4 is another scroll text with transparency BUT black color display the SECOND plasma and not the first one.

How would you do that (i'm not talking about effects but how to have 4 layers)

Offline inc.

  • Contact me @ skype: a5recordings
  • Amiga 1200
  • ****
  • Posts: 276
  • Karma: 25
  • I SPEAK ENGLISH & GERMAN as good as i can :D
    • View Profile
Re: How can we do ?
« Reply #1 on: June 08, 2016 »
In coding with mp3d lib, you can simple add that Layer number as z-order to each objects or sprites, what ever. I'm not sure if this is easy done with normal PB code. Z- order with normal pb-code is as follow:
Code Line 1 = z order back
Code Line 2 = z order in Front of back
Code Line 3 = z order in Front of Line 2
and so on.
The code starts at the top and goes down. Just like a z order System.  Except you code with Procedures and call them at points were needed.

Maybe there are other solutions. PadMan is the man  ;)

currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Offline padman

  • Senior Member
  • Pentium
  • ********
  • Posts: 990
  • Karma: 260
    • View Profile
Re: How can we do ?
« Reply #2 on: June 09, 2016 »
Ok, I quickly put together an example on how to use the screen as a buffer to achieve what you want. (If I understood you correctly that is... ^^) I didn't code any plasmas, but I guess you should get how it works in principle. Example  source + required pics + exe (windowed version, because inc. hates fullscreen...  :P) in the attached ZIP archive.

Pad.


Code: [Select]
InitSprite() : InitKeyboard()

t.s="                                 THIS IS AN EXAMPLE SCROLLTEXT... THIS IS AN EXAMPLE SCROLLTEXT... THIS IS AN EXAMPLE SCROLLTEXT... THIS IS AN EXAMPLE SCROLLTEXT...                                       "


sco   = 0
tptr  = 1
flag  = 1
a     = 0


OpenWindow(1, 0, 0, 640, 480, "Buffer Example",  #PB_Window_ScreenCentered )
OpenWindowedScreen(WindowID(1), 0, 0, 640, 480, 0, 0, 0)


CatchSprite(40,?font)                             ; catch font
TransparentSpriteColor(40,#White)                 ; it uses white as transparent color

CatchSprite(41,?smiley)                           ; catch smiley


CatchImage(66,?textraster)                        ; catch raster image

Repeat

WaitWindowEvent(1)
       
;/////////////////////////////// use the screen as buffer

;ClearScreen(#Black)                   ;  <---------- uncomment to see what's going on
                                       ;  on the screen and comment the ClearScreen(#Black) further down instead...
If a<=60 And Flag=1: a=a+1 : EndIf
If a>60 : flag =2  : EndIf
If flag =2 : a=a-1 :EndIf
If a<0 : flag= 1 : EndIf

; displays the raster background, put your plasma code here then for example

StartDrawing(ScreenOutput())
DrawImage(ImageID(66),0,a,640,96)         ;  for the scroller
DrawImage(ImageID(66),0,400-a/2,64,96)    ;  for the smiley     
StopDrawing()

; does the scroller over the raster

cco = 0
For cc = 0 To 25
letter = (Asc((Mid(t.s, tptr+cc, 1)))-32)
x = letter % 10
y = letter / 10
ClipSprite(40,x*32,y*32,32,32)
DisplayTransparentSprite(40,sco+cco,60)     
cco = cco + 32
Next


  sco = sco - 3
   
  If sco < -32
    tptr = tptr + 1
    sco = sco + 32
  EndIf
     
  If tptr > Len(t.s)-30
    tptr = 1
  EndIf
 
 
  DisplayTransparentSprite(41,0,400)   ; display smiley, black is set to transparent automatically
 
;  grabs the result from the buffer screen in a new sprite

  GrabSprite(7,0,60,640,32)   ; scroller
 
  GrabSprite(8,0,400,64,62)   ; smiley


;/////////////////////////////////////// end of buffer

; now clear the screen, nothing done before will be visible

ClearScreen(#Black)                         

TransparentSpriteColor(7,RGB(0,0,0))    ; transparent color of the scroller sprite set to black
DisplayTransparentSprite(7,0,280-a*2)   ; display it


TransparentSpriteColor(8,#White)    ; transparent color of the the smiley set to white

angle = (angle+2)%360
DisplayTransparentSprite(8,280+160*Cos(2*#PI*angle/360),200+170*Sin(2*#PI*angle/360))     ; display it


FreeSprite(7)                        ; remove scroller sprite from memory
FreeSprite(8)                        ; remove smiley sprite from memory


FlipBuffers()   
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)

End

DataSection

smiley:
IncludeBinary "smiley.bmp" 
font:
IncludeBinary "fnt.bmp"
textraster:
IncludeBinary "raster.bmp"

EndDataSection
« Last Edit: June 09, 2016 by padman »
Challenge Trophies Won:

Offline inc.

  • Contact me @ skype: a5recordings
  • Amiga 1200
  • ****
  • Posts: 276
  • Karma: 25
  • I SPEAK ENGLISH & GERMAN as good as i can :D
    • View Profile
Re: How can we do ?
« Reply #3 on: June 09, 2016 »
quick n dirty:



Code: [Select]
;//////////////////////////////////////////////////////////////////////////////
;
;
; first of all:
; install the whole FXlibs -> MP3D Lib
; http://www.flasharts.de/mpz/mp33_beta/MP3D_Installer.exe
; then
; Goto: Compiler -> Compiler Options -> Library Subsystem and input: DX9
;
;
;//////////////////////////////////////////////////////////////////////////////

Enumeration
  #Wndw
EndEnumeration

EP_InitFXLib()
UsePNGImageDecoder()
InitSprite()

Define.i Event, EventWindow, EventGadget, EventType, EventMenu

OpenWindow(#Wndw, 0, 0, 800, 600, "Plasma Effect", #PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_TitleBar)
;////////////////////////////////////
;- HANDLE 3D DX SCREEN
;////////////////////////////////////
      MP_ScreenToHandle(WindowID(#Wndw))   ;handle Window #Wndw as Demo 3D Effect screen
;///////////////////////////////////////
; START PLASMA DEFINITION DX HLSL SHADER
;///////////////////////////////////////
      Texture  = MP_CreateBackBufferTexture()

      DataSection
      Shader5:
;{ Size = 1373 bytes
  Data.l $50202F2F,$2E332053,$65762030,$6F697372,$0D0A0D6E,$6F6C660A,$20327461,$6F736572,$6974756C,$3D206E6F,$30387B20,$30362C30
  Data.l $203B7D30,$6D202F2F,$20737375,$206E616D,$67726F76,$6E656265,$65646F20,$69652072,$6361666E,$6C612068,$61762073,$62616972
  Data.l $FC20656C,$67726562,$6E656265,$6C660A0D,$2074616F,$656D6974,$0D0A0D3B,$6F6C660A,$20347461,$6853794D,$72656461,$6F6C6628
  Data.l $20327461,$20786554,$4554203A,$4F4F4358,$20294452,$4F43203A,$0D524F4C,$0A0D7B0A,$66202020,$74616F6C,$6F432034,$3B726F6C
  Data.l $0A0D0A0D,$66202020,$74616F6C,$3D207820,$78655420,$2A20782E,$73657220,$74756C6F,$2E6E6F69,$0D3B2078,$2020200A,$616F6C66
  Data.l $20792074,$6554203D,$20792E78,$6572202A,$756C6F73,$6E6F6974,$0D3B792E,$200A0D0A,$6C662020,$2074616F,$30766F6D,$78203D20
  Data.l $632B792B,$7328736F,$74286E69,$29656D69,$292E322A,$3030312A,$69732B2E,$2F78286E,$2E303031,$30312A29,$3B2E3030,$20200A0D
  Data.l $6F6C6620,$6D207461,$2031766F,$2079203D,$7220202F,$6C6F7365,$6F697475,$20792E6E,$2E30202F,$202B2032,$656D6974,$200A0D3B
  Data.l $6C662020,$2074616F,$32766F6D,$78203D20,$20202F20,$6F736572,$6974756C,$782E6E6F,$30202F20,$3B20322E,$20200A0D,$6F6C6620
  Data.l $63207461,$203D2031,$28736261,$286E6973,$31766F6D,$6D69742B,$322F2965,$6F6D2B2E,$322F3276,$6F6D2D2E,$6D2D3176,$2B32766F
  Data.l $656D6974,$0A0D3B29,$66202020,$74616F6C,$20326320,$6261203D,$69732873,$3163286E,$6E69732B,$766F6D28,$30312F30,$2B2E3030
  Data.l $656D6974,$69732B29,$2F79286E,$2B2E3034,$656D6974,$69732B29,$7828286E,$2F29792B,$2E303031,$2E332A29,$0D3B2929,$2020200A
  Data.l $616F6C66,$33632074,$61203D20,$73287362,$63286E69,$6F632B32,$6F6D2873,$6D2B3176,$2B32766F,$2B293263,$28736F63,$32766F6D
  Data.l $69732B29,$2F78286E,$30303031,$2929292E,$200A0D3B,$65722020,$6E727574,$6C6F4320,$3D20726F,$6F6C6620,$28347461,$2C316320
  Data.l $632C3263,$2E312C33,$0D3B2930,$0A0D7D0A,$2F2F0A0D,$2D2D2D20,$2D2D2D2D,$2D2D2D2D,$2D2D2D2D,$2D2D2D2D,$2D2D2D2D,$2D2D2D2D
  Data.l $2D2D2D2D,$2D2D2D2D,$2D2D2D2D,$2D2D2D2D,$0A0D2D2D,$56202F2F,$65747265,$68532078,$72656461,$0A0D0A0D,$75727473,$56207463
  Data.l $4E495F53,$0D545550,$0A0D7B0A,$20202020,$616F6C66,$70203374,$7469736F,$096E6F69,$4F50203A,$49544953,$0D3B4E4F,$2020200A
  Data.l $6F6C6620,$20327461,$74786574,$30657275,$20202020,$54203A20,$4F435845,$3044524F,$7D0A0D3B,$0D0A0D3B,$7274730A,$20746375
  Data.l $4F5F5356,$55505455,$7B0A0D54,$20200A0D,$66202020,$74616F6C,$70682034,$7469736F,$206E6F69,$4F50203A,$49544953,$0D3B4E4F
  Data.l $2020200A,$6C662020,$3274616F,$78657420,$65727574,$3A202030,$58455420,$524F4F43,$0D3B3044,$0D3B7D0A,$560A0D0A,$554F5F53
  Data.l $54555054,$76796D20,$56202873,$4E495F53,$20545550,$29204E49,$0D7B0A0D,$2020200A,$5F535620,$5054554F,$4F205455,$0D3B5455
  Data.l $200A0D0A,$4F202020,$682E5455,$69736F70,$6E6F6974,$66203D20,$74616F6C,$4E492834,$736F702E,$6F697469,$20782E6E,$2E4E492C
  Data.l $69736F70,$6E6F6974,$2C20792E,$702E4E49,$7469736F,$2E6E6F69,$31202C7A,$0A0D3B29,$20202020,$2E54554F,$74786574,$30657275
  Data.l $49203D20,$65742E4E,$72757478,$0D3B3065,$2020200A,$74657220,$206E7275,$3B54554F,$0D7D0A0D,$202F2F0A,$2D2D2D2D,$2D2D2D2D
  Data.l $2D2D2D2D,$2D2D2D2D,$2D2D2D2D,$2D2D2D2D,$2D2D2D2D,$2D2D2D2D,$2D2D2D2D,$2D2D2D2D,$2D2D2D2D,$0D0A0D2D,$6365740A,$71696E68
  Data.l $50206575,$5074736F,$65636F72,$0A0D7373,$200A0D7B,$70202020,$20737361,$0A0D3170,$20202020,$200A0D7B,$20202020,$2F2F2020
  Data.l $67694C20,$6E697468,$203D2067,$65757254,$200A0D3B,$20202020,$65562020,$78657472,$64616853,$3D207265,$6D6F6320,$656C6970
  Data.l $5F737620,$20305F33,$7376796D,$0D3B2928,$2020200A,$20202020,$78695020,$68536C65,$72656461,$63203D20,$69706D6F,$7020656C
  Data.l $5F335F73,$794D2030,$64616853,$29287265,$200A0D3B,$7D202020,$0A0D0A0D
  Data.b $7D
;}
      Shader5_End:
      EndDataSection

      Dim Plasma.i(1)
      shader5FX.s = PeekS(?Shader5,?Shader5_End-?Shader5) ; Load Plasma Shader
      Plasma(1) = MP_CreateMyShader(shader5FX)

      Post_FX = 1
;////////////////////////////////////
; END PLASMA DEFINITION HERE
;////////////////////////////////////
     

;////////////////////////////////////
;- SINUS FONT
;////////////////////////////////////
      EP_CatchFont32(Font,?Font, ?FontEnd)
      EP_SetScrollText(Font, "   THIS IS AN EXAMPLE SCROLLTEXT... THIS IS AN EXAMPLE SCROLLTEXT... THIS IS AN EXAMPLE SCROLLTEXT... THIS IS AN EXAMPLE SCROLLTEXT...                          ")
      EP_Create32Scroll(Font, 0, 0,240, 0,810)
      EP_SetSinScroll32(Font, 0, 2, 130, -4) ;DEFINE BEHAVIOR BY SINUS: 3=?, 2= Letter height (0=Default) , 130= SinusHeight, -4= SinusWidth
;////////////////////////////////////
;- LOGO GFX
;////////////////////////////////////     
      Logo = MP_CatchSprite(?Logo, ?LogoEnd - ?Logo); catch a Logo
     
Repeat
  Event = WindowEvent()
  eventtype = EventType()

    MP_RenderBegin() ;render all the demo screen
;////////////////////////////////////
; START POSTPROCESSING PLASMA
;////////////////////////////////////
   If Post_FX > 0
      MP_ShaderSetVar_f (Plasma(Post_FX),"time",MP_ElapsedMicroseconds()/100000 )   
      MP_SetTechniqueMyShader (Plasma(Post_FX),"PostProcess")   
      MP_UseBackbufferShader(Texture, Plasma(Post_FX))
   EndIf
   
   If Post_FX > 0
      MP_RenderToTexture( Texture )
      MP_TextureToBackBuffer (Texture)
   EndIf
;/////////////////////////////////////////////////////
;-SCROLL TEXT NOW - FIRST CALL BEFORE LOGO = Z INDEX 2
;/////////////////////////////////////////////////////
      EP_Move32Scroll(0)
      MP_SpriteSetZ(Font, 0)  ;0 = Z INDEX NOT WORKING WITH FX SHADER MUST FIX IT
      ;/////////////////////////////////////////////
; LOGO GFX  - 2nd CALL AFTER SCROLL TEXT = Z INDEX 1
;///////////////////////////////////////////////////
      MP_DrawSprite(Logo, 25, 200); SHOW Logo
      MP_SpriteSetZ(Logo, 0) ;0 = Z INDEX NOT WORKING WITH FX SHADER MUST FIX IT
      MP_ScaleSprite(Logo, 80, 80);scale the image to a smaller size. from 100% to 80%     
;/////////////////////////////////////////
;- now render all GFX and other Demo stuff
;  that we can see it on our screen
;/////////////////////////////////////////
      MP_RenderSprite ()
      MP_Render2D ()     
      MP_RenderText ()
      MP_RenderEnd()
  MP_Flip (); flip Buffers to show the whole DX9 Screen
   
Select Event
    ; ///////////////////
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
    ; ////////////////////////
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = #Wndw
        CloseWindow(#Wndw)
        Break
      EndIf
  EndSelect
 
 
ForEver

DataSection

Font:
IncludeBinary "fnt.bmp"
FontEnd:
Logo:
IncludeBinary "inc_logo.png"
LogoEnd:

EndDataSection

currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Offline waste

  • C= 64
  • **
  • Posts: 50
  • Karma: 2
    • View Profile
Re: How can we do ?
« Reply #4 on: June 13, 2016 »
 :clap: great !  i love the plasma , code well commented  :goodpost:

 

Offline GuillyGuilly

  • ZX 81
  • *
  • Posts: 12
  • Karma: 0
    • View Profile
Re: How can we do ?
« Reply #5 on: June 13, 2016 »
Thanks to all :)

.inc, the same but the plasma ONLY IN letters ? :)

Offline inc.

  • Contact me @ skype: a5recordings
  • Amiga 1200
  • ****
  • Posts: 276
  • Karma: 25
  • I SPEAK ENGLISH & GERMAN as good as i can :D
    • View Profile
Re: How can we do ?
« Reply #6 on: June 13, 2016 »
Plasma is imported as HLSL Shader:

plain code:
Code: [Select]
float2 resolution = {800,600}; // add your used Demo screen resolution
float time;

float4 MyShader(float2 Tex : TEXCOORD) : COLOR
{
   float4 Color;

   float x = Tex.x * resolution.x ;
   float y = Tex.y * resolution.y;

   float mov0 = x+y+cos(sin(time)*2.)*100.+sin(x/100.)*1000.;
   float mov1 = y /  resolution.y / 0.2 + time;
   float mov2 = x /  resolution.x / 0.2 ;
   float c1 = abs(sin(mov1+time)/2.+mov2/2.-mov1-mov2+time);
   float c2 = abs(sin(c1+sin(mov0/1000.+time)+sin(y/40.+time)+sin((x+y)/100.)*3.));
   float c3 = abs(sin(c2+cos(mov1+mov2+c2)+cos(mov2)+sin(x/1000.)));
   return Color = float4( c1,c2,c3,1.0);
}

// ---------------------------------------------
// Vertex Shader

struct VS_INPUT
{
    float3 position : POSITION;
    float2 texture0     : TEXCOORD0;
};

struct VS_OUTPUT
{
     float4 hposition : POSITION;
     float2 texture0  : TEXCOORD0;
};

VS_OUTPUT myvs( VS_INPUT IN )
{
    VS_OUTPUT OUT;

    OUT.hposition = float4(IN.position.x ,IN.position.y ,IN.position.z, 1);
    OUT.texture0 = IN.texture0;
    return OUT;
}
// ---------------------------------------------

technique PostProcess
{
    pass p1
    {
       // Lighting = True;
       VertexShader = compile vs_3_0 myvs();
        PixelShader = compile ps_3_0 MyShader();
    }

}
currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Offline waste

  • C= 64
  • **
  • Posts: 50
  • Karma: 2
    • View Profile
Re: How can we do ?
« Reply #7 on: June 17, 2016 »
hi inc. i never put a hand or other things into shaders !!

how do you obtain the shader array values into data section (Data.l $50202F2F,$2E332053 .....) ?   with the plasma.fx shader file ?

thanks

Offline inc.

  • Contact me @ skype: a5recordings
  • Amiga 1200
  • ****
  • Posts: 276
  • Karma: 25
  • I SPEAK ENGLISH & GERMAN as good as i can :D
    • View Profile
Re: How can we do ?
« Reply #8 on: June 17, 2016 »
you can call it via
Code: [Select]
DataSection
;{ INCLUDE PLASMA SHADER
   Shader:
    IncludeBinary "plasma.fx"
   Shader_End:
;}
EndDataSection

or it can be converted into Data. I never found a working tool. So i use PureForm. Sounds crazy, but it converts everything.

example:
https://youtu.be/5bfVARIOQSw
currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Offline waste

  • C= 64
  • **
  • Posts: 50
  • Karma: 2
    • View Profile
Re: How can we do ?
« Reply #9 on: June 20, 2016 »
 :clap: for the PureForm , i think it 's the easyest way

i use this code to do that ,

Code: [Select]
;------FileToBytes---------------;


FileIn.s=OpenFileRequester("Convert to Data.b","C:\","All|*.*",0)
FileOut.s="c:\out.txt"

Enumeration
#In
#Out
EndEnumeration

OpenFile(#In,FileIn)
CreateFile(#Out,FileOut)
WriteString(#out,"DataSection"+#CRLF$+"Data.b ")

Repeat
 
  FileSeek(#in,index)
  If Eof(#In)
    Break
  Else
    If index>0
     
      WriteString(#out,",")
    EndIf
  EndIf
 
  Byte=ReadByte(#in)
 
  WriteString(#out,Str(Byte))
  index+1
ForEver

;/ Add 'EndDataSection' and close all files

WriteString(#out,#CRLF$+"EndDataSection"+#CRLF$)
CloseFile(#Out)
CloseFile(#In)

Offline inc.

  • Contact me @ skype: a5recordings
  • Amiga 1200
  • ****
  • Posts: 276
  • Karma: 25
  • I SPEAK ENGLISH & GERMAN as good as i can :D
    • View Profile
Re: How can we do ?
« Reply #10 on: June 20, 2016 »
your's is not working to me as i expect.
i prefer the PureForm methode :D

maybe, i write a own Tool bin2Data
currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Offline inc.

  • Contact me @ skype: a5recordings
  • Amiga 1200
  • ****
  • Posts: 276
  • Karma: 25
  • I SPEAK ENGLISH & GERMAN as good as i can :D
    • View Profile
Re: How can we do ?
« Reply #11 on: June 21, 2016 »
:clap: for the PureForm , i think it 's the easyest way

i use this code to do that ,

here you go :D

Finally the Bin2Data Tool thanks to " ts-soft "




EDIT
Yes PadMan you're right.  The tool was not programmed by me. It has already exist. Done by TS SOFT.
It's perfect and wasted time, if i would start over with another Clone.  I didn't knew about the tool until today. TS gave me the code this afternoon :)
« Last Edit: June 21, 2016 by inc. »
currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Offline padman

  • Senior Member
  • Pentium
  • ********
  • Posts: 990
  • Karma: 260
    • View Profile
Re: How can we do ?
« Reply #12 on: June 21, 2016 »
I think it's just fair to mention that the Bin2Data tool was developed by ts-soft. Source can be found in here: >> Click <<
Challenge Trophies Won:

Offline inc.

  • Contact me @ skype: a5recordings
  • Amiga 1200
  • ****
  • Posts: 276
  • Karma: 25
  • I SPEAK ENGLISH & GERMAN as good as i can :D
    • View Profile
Re: How can we do ?
« Reply #13 on: June 21, 2016 »
I think it's just fair to mention that the Bin2Data tool was developed by ts-soft. Source can be found in here: >> Click <<

Absolutely  :kewl:.  Sorry for the misunderstanding. i mentioned it for sure, but forgot it in my previous post. sorry.
« Last Edit: June 21, 2016 by inc. »
currently coding in PureBasic: GLSL Shader Maker & Editor Tool for further Demo coding usage

Offline padman

  • Senior Member
  • Pentium
  • ********
  • Posts: 990
  • Karma: 260
    • View Profile
Re: How can we do ?
« Reply #14 on: June 23, 2016 »
All is cool. Credit is more than clear now.  ;)
Challenge Trophies Won: