Jump to content

Shader problem.


ds1-e

Recommended Posts

  • Scripting Moderators

Hey, i'm not experienced with shaders so i have a problem on my way.

I don't know can i apply screenSource for this shader texture, something is wrong because i have black screen instead of shader.

texture gTexture0 < string textureState="0,Texture"; >;

sampler Sampler0 = sampler_state
{
    Texture = (gTexture0);
};

 

Link to comment
  • Scripting Moderators

And one more problem. How can i mix shader effect in one result? I mean that if one shader works, second don't wanna work.

local screenWidth, screenHeight = guiGetScreenSize()
local firstShader = dxCreateShader("shader.fx")
local secondShader = dxCreateShader("shader2.fx")
local screenSource = dxCreateScreenSource(screenWidth, screenHeight)

function onClientRender()
  dxUpdateScreenSource(screenSource)
  dxDrawImage(0, 0, screenWidth, screenHeight, firstShader)
  dxDrawImage(0, 0, screenWidth, screenHeight, secondShader)
end
addEventHandler("onClientRender", getRootElement(), onClientRender)

 

Edited by majqq
Link to comment
  • Scripting Moderators

To make things simpler, and focus on main problem.

- I have shader which change colors of player screen.

- I have second shader which blur player screen.

- After applying both shaders, only one works.

So i need solution:

- Maybe i make it wrong?

 Or there's possibility to get result:

- Use first shader, get result.

- Use second shader on result from first shader.

Edited by majqq
Link to comment

input "shader" to "shader" for blur and output result "dxDrawImage(...,shader)"

local grayShdr = ...

dxSetShaderValue(grayShdr, "ScreenSource", screen);

local blur = ...

dxSetShaderValue(blur, "ScreenSource", grayShdr)

dxDrawImage(..., gray)

 

or use pass0, pass1 in shader

  • Like 1
Link to comment
  • Scripting Moderators
6 hours ago, XaskeL said:

input "shader" to "shader" for blur and output result "dxDrawImage(...,shader)"

local grayShdr = ...

dxSetShaderValue(grayShdr, "ScreenSource", screen);

local blur = ...

dxSetShaderValue(blur, "ScreenSource", grayShdr)

dxDrawImage(..., gray)

 

or use pass0, pass1 in shader

 

Hey, thanks for answer. But didn't really understand what i should to do. Can you explain it better?

Link to comment
  • Scripting Moderators
21 minutes ago, XaskeL said:

give me full code

local screenWidth, screenHeight = guiGetScreenSize()
local firstShader = dxCreateShader("shader2.fx")
local secondShader = dxCreateShader("shader.fx")
local screenSource = dxCreateScreenSource(screenWidth, screenHeight)

local blurAmount = 50
local uvAmount = 400
local blendAmount = 6

function onClientRender()
	dxUpdateScreenSource(screenSource)
	dxSetShaderValue(firstShader, "colorAmount", 0.50)
	dxSetShaderValue(firstShader, "coloredTexture", screenSource)
	dxDrawImage(0, 0, screenWidth, screenHeight, firstShader)
	dxSetShaderValue(secondShader, "ScreenSource", result)
	dxSetShaderValue(secondShader, "OverlayTexture", result)
	dxSetShaderValue(secondShader, "BlurStrength", blurAmount)
	dxSetShaderValue(secondShader, "UVSize", screenWidth - uvAmount, screenHeight - uvAmount)
	dxSetShaderValue(secondShader, "Blend", blendAmount)
	dxDrawImage(0, 0, screenWidth, screenHeight, secondShader)
end
addEventHandler("onClientRender", getRootElement(), onClientRender)

 

Link to comment
  • Scripting Moderators

Looks like solved. If someone else would have same problem use:

dxUpdateScreenSource(screenSource, true) -- second argument should be true

After applying shader with dxDrawImage.

Link to comment
local screenWidth, screenHeight = guiGetScreenSize()
local firstShader = dxCreateShader("shader2.fx")
local secondShader = dxCreateShader("shader.fx")
local screenSource = dxCreateScreenSource(screenWidth, screenHeight)

local blurAmount = 50
local uvAmount = 400
local blendAmount = 6

function onClientRender()
	dxUpdateScreenSource(screenSource)
	dxSetShaderValue(firstShader, "colorAmount", 0.50)
	dxSetShaderValue(firstShader, "coloredTexture", screenSource)
	--dxDrawImage(0, 0, screenWidth, screenHeight, firstShader)
	dxSetShaderValue(secondShader, "ScreenSource", firstShader)
	dxSetShaderValue(secondShader, "OverlayTexture", result)
	dxSetShaderValue(secondShader, "BlurStrength", blurAmount)
	dxSetShaderValue(secondShader, "UVSize", screenWidth - uvAmount, screenHeight - uvAmount)
	dxSetShaderValue(secondShader, "Blend", blendAmount)
	dxDrawImage(0, 0, screenWidth, screenHeight, secondShader)
end
addEventHandler("onClientRender", getRootElement(), onClientRender)

 

  • Like 1
Link to comment
  • Scripting Moderators
8 minutes ago, XaskeL said:

local screenWidth, screenHeight = guiGetScreenSize()
local firstShader = dxCreateShader("shader2.fx")
local secondShader = dxCreateShader("shader.fx")
local screenSource = dxCreateScreenSource(screenWidth, screenHeight)

local blurAmount = 50
local uvAmount = 400
local blendAmount = 6

function onClientRender()
	dxUpdateScreenSource(screenSource)
	dxSetShaderValue(firstShader, "colorAmount", 0.50)
	dxSetShaderValue(firstShader, "coloredTexture", screenSource)
	--dxDrawImage(0, 0, screenWidth, screenHeight, firstShader)
	dxSetShaderValue(secondShader, "ScreenSource", firstShader)
	dxSetShaderValue(secondShader, "OverlayTexture", result)
	dxSetShaderValue(secondShader, "BlurStrength", blurAmount)
	dxSetShaderValue(secondShader, "UVSize", screenWidth - uvAmount, screenHeight - uvAmount)
	dxSetShaderValue(secondShader, "Blend", blendAmount)
	dxDrawImage(0, 0, screenWidth, screenHeight, secondShader)
end
addEventHandler("onClientRender", getRootElement(), onClientRender)

 

 

Didn't worked. debugscript says it needs a texture, but got shader. Anyway thanks for trying to help, i already solved it. @XaskeL

Link to comment
  • 2 weeks later...
  • Scripting Moderators

bump. Still wanna get to work last one shader.

texture gTexture0           < string textureState="0,Texture"; >;

How i should apply shader value for it?

I don't have any idea, how i could do it. This is from mta-helper.fx:

//------------------------------------------------------------------------------------------
// textureState (partial) - String value should be a texture number followed by 'Texture'
//------------------------------------------------------------------------------------------

texture gTexture0           < string textureState="0,Texture"; >;
texture gTexture1           < string textureState="1,Texture"; >;
texture gTexture2           < string textureState="2,Texture"; >;
texture gTexture3           < string textureState="3,Texture"; >;

 

Edited by majqq
Link to comment
  • 4 weeks later...
  • Scripting Moderators
On 16/04/2019 at 00:43, Ren_712 said:

look into shader examples on wiki, mainly shader_bloom to see how to set texture for dxDrawImage.

bump.

I was looking into it, and there is a lot of function, so i'm not even sure where i should start looking for.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...