Quantcast

Jump to content

» «
Photo

[REL|CLEO] Shader API

60 replies to this topic
_DK
  • _DK

    Homie

  • Feroci Racing
  • Joined: 12 Apr 2009
  • Ukraine

#1

Posted 23 April 2014 - 10:30 PM Edited by _DK, 24 April 2014 - 10:29 AM.

CLEO Shader API - write & use HLSL shaders with CLEO scripts
 
Overview
CLEO Shader API is based on Shader class. Its interface has following methods:
Load("FileName%v")
Loads shader (effect) from file and returns shader's handle
Draw("Shader%h" "Technique%v" "Left%f" "Top%f" "Right%f" "Bottom%f")
Draws rect with shader's technique
DrawHudElement("Shader%h" "Technique%v" "Left%f" "Top%f" "Right%f" "Bottom%f")
Draws rect with shader's technique at HUD rendering
SetFloat("Shader%h" "ParamName%v" "Value%f")
Sets float param
SetInt("Shader%h" "ParamName%v" "Value%i")
Sets integer param
SetBool("Shader%h" "ParamName%v" "Value%b")
Sets boolean param
SetVector("Shader%h" "ParamName%v" "X%f" "Y%f" "Z%f" "W%f")
Sets vector param
SetMatrix("Shader%h" "ParamName%v" "Matrix%h")
Sets matrix param. Second parameter is a pointer to D3DMATRIX struct.
SetTexture("Shader%h" "ParamName%v" "TextureName%v")
Sets texture param. Second parameter is name of texture loaded with LoadTexture() method.
SetRwTexture("Shader%h" "ParamName%v" "Texture%h")
Sets texture param. Second parameter is a pointer to RwTexture object.
LoadTexture("Name%v" "FileName%v")
Loads texture from file
UnloadTexture("Name%v")
Unloads texture
 
Features
Semantics
You can use some default paramters, without passing them in CLEO script. They are marked with semantics. CLEO Shader API supports such semantics:
Type SemanticName Description
texture SCREEN_TEX frame buffer texture
texture DEPTH_TEX z-buffer texture
float3 SUN_CORONA_COL sun's corona color
float3 SUN_CORE_COL sun's core color
float3 SKY_TOP_COL
float3 SKY_BOTTOM_COL
float3 AMBIENT_COL
float2 SUN_POSN sun position (screen-space coordinates)
float SUN_SIZE
float DAYNIGHT_STATE
float WEATHER_FOGGYNESS
float WEATHER_CLOUD_COVERAGE
float WEATHER_RAIN
float WEATHER_UNDER_WATERNESS
int MULTISAMPLE_LEVELS AA level in game menu
bool NIGHT_VISION
bool INFRARED_VISION
bool HEAT_VISUALS
When defining a variable for such parameter, use shared specificator:

shared float2 sunPosn : SUN_POSN;

Screen size constants
Use following parameter if you want to draw full/half screen effect:
SCREEN_BASE_X
SCREEN_BASE_Y
SCREEN_SIZE_X
SCREEN_SIZE_Y
SCREEN_HALF_X
SCREEN_HALF_Y

 

Examples
Simple blur shader:

shared texture screen : SCREEN_TEX;
float dist;
 
sampler2D screenSampler = sampler_state
{
    Texture = <screen>;
};
 
float4 PS_screen(float2 tex: TEXCOORD0): COLOR
{
    float4 color;
    color =  tex2D(screenSampler, tex);
    color += tex2D(screenSampler, tex + dist);
    color += tex2D(screenSampler, tex - dist);
    return color / 3;
}
 
technique ShowScreen
{
    pass P0
    {
        PixelShader  = compile ps_2_0 PS_screen();
    }
}[size=4]

CLEO-script for this shader:

{$CLEO}
{$I shaderApi}
 
var
    0@: shader
end
 
if
    0@ = shader.Load("CLEO\blur.txt")
then
    while true
        wait 0
        068D: get_camera_position_to 4@ 5@ 6@
        050A: 7@ = distance_between_XYZ 1@ 2@ 3@ and_XYZ 4@ 5@ 6@
        7@ *= 0.0008
        068D: get_camera_position_to 1@ 2@ 3@
        0@.SetFloat("dist", 7@)
        0@.Draw("ShowScreen", SCREEN_BASE_X, SCREEN_BASE_Y, SCREEN_SIZE_X, SCREEN_SIZE_Y)
        
    end
end
0A93: end_custom_thread

Download links

https://www.mediafir...pze89mkv09ig087

  • Wesser, ThirteenAG, Shmoopy and 13 others like this

Marty McFly
  • Marty McFly

    A Elbereth Gilthoniel

  • Feroci Racing
  • Joined: 07 Nov 2010
  • None

#2

Posted 24 April 2014 - 12:10 PM

Great! Waited for this quite a time. But I have some questions:

 

- which CLEO version is required?

- modloader compatible? Or does the shader txt file have to be in SA folder\CLEO folder?

- is the one shaderapi file intented to be without a file extension?

- which shader model is required or does this depend on shader file?

-the variable "dist" is declared outside the pixel shader without a value and needs to be added to the CLEO file. What if I declare it like "float dist = 1.0;" do I have to add it to the cleoscript, too?


madleg
  • madleg

    Player Hater

  • Members
  • Joined: 01 Jan 2014
  • Russia

#3

Posted 24 April 2014 - 01:51 PM

amazing plugin <3 :cookie:  :cookie:  :cookie:

 

 

-the variable "dist" is declared outside the pixel shader without a value and needs to be added to the CLEO file. What if I declare it like "float dist = 1.0;" do I have to add it to the cleoscript, too?

ofc no, that opcodes just allow u to make params dynamic through cleo

 

p.s.

Spoiler
  • ThirteenAG, Ashwin.Star, ByteCode2014 and 1 other like this

ChopTheDog.
  • ChopTheDog.

    War. War never changes.

  • Members
  • Joined: 31 May 2010
  • None

#4

Posted 25 April 2014 - 05:58 PM

96xu.jpg

 

m4de.jpg

 

 

 

Holy f*ck.

  • Platinum Card likes this

FMHn
  • FMHn

    kinurrrrrr

  • Members
  • Joined: 31 Aug 2013

#5

Posted 27 April 2014 - 06:09 AM

awesome work sir! love it,more simple life, waiting for this for a long time :D

 

will try it soon, good luck!


madleg
  • madleg

    Player Hater

  • Members
  • Joined: 01 Jan 2014
  • Russia

#6

Posted 27 April 2014 - 02:37 PM

there is any way to do multipass postprocess of screen image? i mean if i call .Draw second time, can i change sharing texture to already processed one? if it so - how?

sorry for bad understanding and i know that i can do all shi in a single shader (but it sux a bit)


_DK
  • _DK

    Homie

  • Feroci Racing
  • Joined: 12 Apr 2009
  • Ukraine

#7

Posted 27 April 2014 - 04:03 PM Edited by _DK, 27 April 2014 - 04:04 PM.

technique ShowScreen
{
    pass P0
    {
        PixelShader = compile ps_2_0 PS_screen();
    }
    pass P1
    {
        PixelShader = compile ps_2_0 PS_screen_2();
    }
}
  • ByteCode2014 likes this

madleg
  • madleg

    Player Hater

  • Members
  • Joined: 01 Jan 2014
  • Russia

#8

Posted 01 May 2014 - 04:49 PM Edited by madleg, 03 May 2014 - 01:07 PM.

i give up... there is some way to store pixel data as texture in hlsl and then use it like sampler? will be great if you will add something like saving result of processed shader as texture (like in mta)

bloom without mask from ultraThing, i guess

Spoiler

Rafal22
  • Rafal22

    Player Hater

  • Members
  • Joined: 02 Jul 2011
  • Poland

#9

Posted 06 May 2014 - 12:57 PM

Hi
How make black-white screen using this?

  • Concavax likes this

jayd00
  • jayd00

    Rat

  • Members
  • Joined: 24 May 2008

#10

Posted 10 May 2014 - 01:40 AM

it is possible to apply shaders for a specific texture in game?
like this;
engineApplyShaderToWorldTexture ( myShader, "waterclear256" )

madleg
  • madleg

    Player Hater

  • Members
  • Joined: 01 Jan 2014
  • Russia

#11

Posted 24 May 2014 - 07:33 AM

DK, can you show please an example how to draw a texture loaded from file?


_DK
  • _DK

    Homie

  • Feroci Racing
  • Joined: 12 Apr 2009
  • Ukraine

#12

Posted 24 May 2014 - 08:07 AM Edited by _DK, 24 May 2014 - 08:16 AM.

You need to pass a texture as a parameter to shader.

if and
    0@ = shader.Load("CLEO\blur.txt")
    shader.LoadTexture("myTex", "CLEO\myTex.png")
then
    0@.SetTexture("shaderTexParam", "myTex")
    while true
        wait 0
        0@.Draw("ShowTex", SCREEN_BASE_X, SCREEN_BASE_Y, SCREEN_SIZE_X, SCREEN_SIZE_Y)
    end
end

madleg
  • madleg

    Player Hater

  • Members
  • Joined: 01 Jan 2014
  • Russia

#13

Posted 24 May 2014 - 01:56 PM

 

You need to pass a texture as a parameter to shader.

 

well, i though so and i did, but it wont work for me. In result i get black screen, like texture wasnt loaded.

can you help me, if im wrong? or maybe show your shader example? ty

texture screenTex;
sampler2D ScreenSamp = sampler_state 
{
    Texture = (screenTex);
};

float4 PixelShaderFunction(float2 TexCoord : TEXCOORD0) : COLOR0
{
    float4 col = tex2D(ScreenSamp, TexCoord);
    return col; 
}

technique shader
{
    pass P0
    {
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}

//cleo
{$I shaderApi}
0000:
if
    0DF0: 0@ "CLEO\shader0.txt"
    then
    0DF8: load_dx_texture "TEX" from_file "cleo\map.png"
    0DF7: set_shader 0@ dx_texture_param "screenTex" to "TEX"
    else
    0a93:
end
while true
    wait 0
    0DF1: 0@ "shader" 1 2 3 4
end

jayd00
  • jayd00

    Rat

  • Members
  • Joined: 24 May 2008

#14

Posted 24 May 2014 - 10:09 PM Edited by jayd00, 24 May 2014 - 10:12 PM.

 

 

You need to pass a texture as a parameter to shader.

 

well, i though so and i did, but it wont work for me. In result i get black screen, like texture wasnt loaded.

can you help me, if im wrong? or maybe show your shader example? ty

 

 

ahm.. :/ it's not quite difficult..
but I see that your shader will return black screen anyway..
while I was testing, I did this one;
 
shared texture originaltexture : SCREEN_TEX;
shared texture newtexture : SCREEN_TEX;

sampler OriginalSampler = sampler_state
{
    Texture = <originaltexture>;
};

sampler NewSampler = sampler_state
{
    Texture = <newtexture>;
};

float4 PixelShaderFunction(float2 TextureCoordinate : TEXCOORD0) : COLOR0 
{ 
	// sample original texture
	float4 original= tex2D(OriginalSampler , TextureCoordinate.xy); 
    // sample a pixel from NewSampler texture
	float4 second= tex2D(NewSampler , TextureCoordinate.xy); 
    original.r =  original.r * second.g;
    original.g =  original.b * second.b;
    original.b =  original.g * second.r;
    //original.r =  original.r + second.g;
	return original; 
}

technique mixtextures
{
    pass P0
    {
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}

{$CLEO}
{$I shaderApi}
0000:

while true

repeat
 wait 0
until  0AB0:   key_pressed 50 // number 2

if 0DF0: 0@ = load_shader_from_file "CLEO\shaders\externalTexture.fx"
then

    //0ACA: show_text_box "on"
    wait 500
    0DF8: load_dx_texture "externalT" from_file "CLEO\shaders\humo.png"
    0DF7: set_shader 0@ dx_texture_param "newtexture" to "externalT"
    repeat
                
        0DF1: draw_shader 0@ technique "mixtextures" at SCREEN_BASE_X SCREEN_BASE_Y SCREEN_SIZE_X SCREEN_SIZE_Y        

        wait 0
    until  0AB0:   key_pressed 50 // number 2
    0DF9: unload_dx_texture "externalT"
    
    //0ACA: show_text_box "off"
    wait 500

else  0ACA: show_text_box "not loaded"
end

 wait 0
end

the texture, is any SMOKE texture... ;)

 

 

ps.

 

DK, can you explain how to use this opcode;

SetRwTexture("Shader%h" "ParamName%v" "Texture%h")
Sets texture param. Second parameter is a pointer to RwTexture object.

 

thanks ;)


Shmoopy
  • Shmoopy

    Thug (͡ ͜ʖ ͡)

  • Members
  • Joined: 16 Jun 2009
  • None

#15

Posted 25 May 2014 - 11:01 PM Edited by Manfred Von Karma, 03 June 2014 - 08:44 PM.

Inverted colors :

Spoiler

Spoiler

Emboss:
Spoiler

Spoiler

Photocopy:
Spoiler

Spoiler

Toon Shading :

Spoiler

Spoiler

Rafal22
  • Rafal22

    Player Hater

  • Members
  • Joined: 02 Jul 2011
  • Poland

#16

Posted 27 May 2014 - 10:15 PM Edited by Rafal22, 27 May 2014 - 10:15 PM.

Is possible get picture from other camera by coordinate?


jayd00
  • jayd00

    Rat

  • Members
  • Joined: 24 May 2008

#17

Posted 29 May 2014 - 06:30 AM

 

Toon Shading :

Spoiler

 

it like me your toon shader... 

can you lend me your code? ;)

 

  • _DK likes this

Shmoopy
  • Shmoopy

    Thug (͡ ͜ʖ ͡)

  • Members
  • Joined: 16 Jun 2009
  • None

#18

Posted 29 May 2014 - 11:29 AM Edited by Manfred Von Karma, 29 May 2014 - 11:31 AM.

You mean the cleo code ? cz i've already gave the shader code :

/*
/* Shader API header
/* 
/* Shader API CLEO developed by DK22Pac
*/
{$OPCODE 0DF0=2, %2d% = load_shader_from_file %1s%}
{$OPCODE 0DF1=6,draw_shader %1d% technique %2s% at %3d% %4d% %5d% %6d%}
{$OPCODE 0DF2=3,set_shader %1d% float_param %2s% to %3d%}
{$OPCODE 0DF3=3,set_shader %1d% int_param %2s% to %3d%}
{$OPCODE 0DF4=3,set_shader %1d% bool_param %2s% to %3d%}
{$OPCODE 0DF5=6,set_shader %1d% vector_param %2s% to %3d% %4d% %5d% %6d%}
{$OPCODE 0DF6=3,set_shader %1d% matrix_param %2s% to %3d%}
{$OPCODE 0DF7=3,set_shader %1d% dx_texture_param %2s% to %3s%}
{$OPCODE 0DF8=2,load_dx_texture %1s% from_file %2s%}
{$OPCODE 0DF9=1,unload_dx_texture %1s%}
{$OPCODE 0DFA=6,draw_shader %1d% technique %2s% at %3d% %4d% %5d% %6d% as_hud_element}
{$OPCODE 0DFB=3,set_shader %1d% rw_texture_param %2s% to %3h%}

const
SCREEN_BASE_X=1
SCREEN_BASE_Y=2
SCREEN_SIZE_X=3
SCREEN_SIZE_Y=4
SCREEN_HALF_X=5
SCREEN_HALF_Y=6
end


if
    0DF0: 0@ = load_shader_from_file "cleo\toon.txt" 
then
    while true
        wait 0
        0DF1: draw_shader 0@ technique "ShowScreen" at SCREEN_BASE_X SCREEN_BASE_Y SCREEN_SIZE_X SCREEN_SIZE_Y
    end
end


jayd00
  • jayd00

    Rat

  • Members
  • Joined: 24 May 2008

#19

Posted 29 May 2014 - 10:22 PM Edited by jayd00, 29 May 2014 - 10:24 PM.

:p well.. I meant the shader code ;) thanks...

 

I let here the opcodes, that can be added to SB (to use with opcode search)

0DF0: 0@ = load_shader_from_file "CLEO\shader.fx"
0DF1: draw_shader 0@ technique "technique" at 1 2 3 4 //{SCREEN_BASE_X=1}{SCREEN_BASE_Y=2}{SCREEN_SIZE_X=3}{SCREEN_SIZE_Y=4}{SCREEN_HALF_X=5}{SCREEN_HALF_Y=6}       
0DF2: set_shader 0@ float_param "sFloatParam" to 255.0  // (Float)
0DF3: set_shader 0@ int_param "sIntParam" to 255   // (Int)
0DF4: set_shader 0@ bool_param "sBoolColor" to 0  // (Bool) (0-1)
0DF5: set_shader 0@ vector_param "sFloat4Param" to 255.0 255.0 255.0 255.0 // (Float)
0DF6: set_shader 0@ matrix_param "sMatrixParam" to 5@
0DF7: set_shader 0@ dx_texture_param "sTextureParam" to "newTexture"
0DF8: load_dx_texture "newTexture" from_file "CLEO/texture.png"
0DF9: unload_dx_texture "newTexture"
0DFA: draw_shader 0@ technique "technique" at 1 2 3 4 as_hud_element //{SCREEN_BASE_X=1}{SCREEN_BASE_Y=2}{SCREEN_SIZE_X=3}{SCREEN_SIZE_Y=4}{SCREEN_HALF_X=5}{SCREEN_HALF_Y=6}
0DFB: set_shader 0@ rw_texture_param "sTextureParam" to 10@ // "newTexture" in 10@

and also the opcode definitions for SASCM.INI (instead of using SB opcode definition) (is the same thing...)

; shader.cleo opcodes by DK22Pac
0DF0=2, %2d% = load_shader_from_file %1s%
0DF1=6,draw_shader %1d% technique %2s% at %3d% %4d% %5d% %6d%
0DF2=3,set_shader %1d% float_param %2s% to %3d%
0DF3=3,set_shader %1d% int_param %2s% to %3d%
0DF4=3,set_shader %1d% bool_param %2s% to %3d%
0DF5=6,set_shader %1d% vector_param %2s% to %3d% %4d% %5d% %6d%
0DF6=3,set_shader %1d% matrix_param %2s% to %3d%
0DF7=3,set_shader %1d% dx_texture_param %2s% to %3s%
0DF8=2,load_dx_texture %1s% from_file %2s%
0DF9=1,unload_dx_texture %1s%
0DFA=6,draw_shader %1d% technique %2s% at %3d% %4d% %5d% %6d% as_hud_element
0DFB=3,set_shader %1d% rw_texture_param %2s% to %3h%

if there is something wrong, feel free to correct it... 


_DK
  • _DK

    Homie

  • Feroci Racing
  • Joined: 12 Apr 2009
  • Ukraine

#20

Posted 29 May 2014 - 10:37 PM Edited by _DK, 28 July 2014 - 01:10 AM.

Why do you need it in opcode search? WTF?
Use this
shader.
 
 

{SCREEN_BASE_X=1}{SCREEN_BASE_Y=2}{SCREEN_SIZE_X=3}{SCREEN_SIZE_Y=4}{SCREEN_HALF_X=5}{SCREEN_HALF_Y=6}

Thanks guys, I tried to simplify your work, but you don't look for easy ways.
  • S Y E D likes this

jayd00
  • jayd00

    Rat

  • Members
  • Joined: 24 May 2008

#21

Posted 30 May 2014 - 10:34 PM

Why do you need it in opcode search? WTF?
Use this

shader.
{SCREEN_BASE_X=1}{SCREEN_BASE_Y=2}{SCREEN_SIZE_X=3}{SCREEN_SIZE_Y=4}{SCREEN_HALF_X=5}{SCREEN_HALF_Y=6}

 

Thanks guys, I tried to simplify your work, but you don't look for easy ways.

 

haha that picture is funny.. 

there are some people like me, that we use the "write opcodes" in SB options. 
 
and unfortunately.. you're right. :p  classes are easy but... sometimes we have some troubles with them...
like this one for example;
45c070329987382.jpg 
 
we are not expert in SB... some people like me learned about "coding". only to stop f*ck you out with requests.
and you're gone DK, you write something once, at month. with lucky...
I'm sure you have more interesting things to do... definitelly..
 
but is not good to judge someone with "wtf"?  with meaning; "your'e an asshole"
we only don't do the same like you, and all the coders. 
 
some people like me only dedicate to make money.
take as example, if I start talking with you about boilers, what can you talk me about it?  I'm engineer, and this is my branch.
you see now... definitely, you don't know the same like me in this branch.
 
and that's what happens to me in topics like "coding" 
for me, this is only for fun.
but probably for you, this is what you do in real life.
 
if you're only a child, I hope you take it the most serious possible.
I hope you understand my point now... 
 
peace
and keep doing great things for this game... ;)

_DK
  • _DK

    Homie

  • Feroci Racing
  • Joined: 12 Apr 2009
  • Ukraine

#22

Posted 31 May 2014 - 01:07 AM

You didn't add shader class to classes.db. See how other classes are defined and try to understand it.

Shmoopy
  • Shmoopy

    Thug (͡ ͜ʖ ͡)

  • Members
  • Joined: 16 Jun 2009
  • None

#23

Posted 31 May 2014 - 05:31 PM Edited by Manfred Von Karma, 15 June 2014 - 01:37 PM.

Sepia : ( Would look amazing with a texture shader of film grains or lines)

Spoiler

Spoiler


Radial blur :  ( Would be awesome in a parkour or a racing mod )
Spoiler

Spoiler


Moving noise : ( If you want it to be static , remove the 5@ += 1.0 line)
Spoiler

Spoiler

Vignette :
Spoiler

Spoiler
  • _DK, ChopTheDog., LINK/2012 and 2 others like this

KeeJay
  • KeeJay

    Noob on blackout

  • Members
  • Joined: 06 Mar 2013
  • Poland

#24

Posted 03 June 2014 - 08:07 PM

@Manfred Von Karma - can you do also one with vignette effect?


Shmoopy
  • Shmoopy

    Thug (͡ ͜ʖ ͡)

  • Members
  • Joined: 16 Jun 2009
  • None

#25

Posted 03 June 2014 - 08:42 PM

@Manfred Von Karma - can you do also one with vignette effect?

Done , check the previous post :^:

  • Concavax likes this

Rafal22
  • Rafal22

    Player Hater

  • Members
  • Joined: 02 Jul 2011
  • Poland

#26

Posted 12 June 2014 - 01:14 PM

Is it possible to do depth of field effect when using shader api?

  • KeeJay likes this

Junior_Djjr
  • Junior_Djjr

    BMS - Brazilian Modding Studio

  • Members
  • Joined: 16 Dec 2011
  • Brazil

#27

Posted 14 June 2014 - 02:09 PM Edited by Junior_Djjr, 14 June 2014 - 02:17 PM.

i loved, this is a in-game configuration of madleg's shader:

10357671_310206535801490_762762149640120

10410536_310672322421578_724505319099541

(only to test :p i think)

but... the .cleo removed my anti aliasing .-.

i think of anti aliasing of GPU (gf 8400 gs ddr2 512 mbs), 'cause the anti aliasing of my GTA is off lol

 

edit: wtf, i looked now and the second print the shirt of my CJ is bugged, the shirt is black @_@

  • _DK, VERSA, Musi and 2 others like this

_DK
  • _DK

    Homie

  • Feroci Racing
  • Joined: 12 Apr 2009
  • Ukraine

#28

Posted 15 June 2014 - 01:56 AM Edited by _DK, 15 June 2014 - 01:57 AM.

Programmable pipeline can't be combined with gpu AA... You need to do it inside shader.
And also, nice stuff there!

Junior_Djjr
  • Junior_Djjr

    BMS - Brazilian Modding Studio

  • Members
  • Joined: 16 Dec 2011
  • Brazil

#29

Posted 15 June 2014 - 01:51 PM

strange, anyone lose the anti aliasing when put the shaderApi.cleo?

 

but, when i forced the AA of GPU in the game, worked as fine and laggy... when i don't forced continues with a light AA and don't lags (in the confg of game, the AA is off wtf), but when i put the .cleo in game, the graphics stay a sh*t without AA


_DK
  • _DK

    Homie

  • Feroci Racing
  • Joined: 12 Apr 2009
  • Ukraine

#30

Posted 17 June 2014 - 12:37 AM

Well, I just said it before. Didn't you read my post?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users