Sign in to follow this  
majqq

Shader problem.

Recommended Posts

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);
};

 

Share this post


Link to post
Posted (edited)

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

Share this post


Link to post
Posted (edited)

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

Share this post


Link to post

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

Share this post


Link to post
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?

Share this post


Link to post
14 minutes ago, majqq said:

 

Эй, спасибо за ответ. Но я не совсем понял, что мне делать. Можете ли вы объяснить это лучше?

give me full code

Share this post


Link to post
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)

 

Share this post


Link to post
On 04/04/2019 at 19:57, XaskeL said:

give me full code

Hey, so can you help me with it?

Share this post


Link to post

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

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

After applying shader with dxDrawImage.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Posted (edited)

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

Share this post


Link to post
Posted (edited)

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

Edited by Ren_712
  • Like 1

Share this post


Link to post
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.

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.