bover Posted December 22, 2022 Share Posted December 22, 2022 (edited) Hi, im using hudmask shader from https://wiki.multitheftauto.com/wiki/Shader_examples, also have a blur shader that i found somewhere on internet. I want to join those both shaders to make a shader that blurs screen source and clamp that on mask that i provide. Already connected both shaders, blur works but mask not. I were trying a lot of things but I'm not specialist of HLSL. Anyone can help? Shader: #include "tex_matrix.fx" texture screenSource; texture maskTexture; float factor; float2 gUVPrePosition = float2( 0, 0 ); float2 gUVScale = float( 1 ); float2 gUVScaleCenter = float2( 0.5, 0.5 ); float gUVRotAngle = float( 0 ); float2 gUVRotCenter = float2( 0.5, 0.5 ); float2 gUVPosition = float2( 0, 0 ); float3x3 getTextureTransform() { return makeTextureTransform(gUVPrePosition, gUVScale, gUVScaleCenter, gUVRotAngle, gUVRotCenter, gUVPosition); }; sampler Sampler0 = sampler_state { Texture = screenSource; AddressU = Clamp; AddressV = Clamp; }; struct PSInput { float2 TexCoord : TEXCOORD0; }; float4 PixelShader_Background(PSInput PS) : COLOR0 { float4 sum = tex2D(Sampler0, PS.TexCoord); for (float i = 1; i < 3; i++) { sum += tex2D(Sampler0, float2(PS.TexCoord.x, PS.TexCoord.y + (i * factor))); sum += tex2D(Sampler0, float2(PS.TexCoord.x, PS.TexCoord.y - (i * factor))); sum += tex2D(Sampler0, float2(PS.TexCoord.x - (i * factor), PS.TexCoord.y)); sum += tex2D(Sampler0, float2(PS.TexCoord.x + (i * factor), PS.TexCoord.y)); } sum /= 9; sum.a = 1.0; return sum; } technique complercated { pass P0 { PixelShader = compile ps_2_0 PixelShader_Background(); } } technique simple { pass P0 { Texture[0] = screenSource; TextureTransform[0] = getTextureTransform(); TextureTransformFlags[0] = Count2; AddressU[0] = Clamp; AddressV[0] = Clamp; ColorOp[0] = Modulate; ColorArg1[0] = Texture; ColorArg2[0] = Diffuse; AlphaOp[0] = Modulate; AlphaArg1[0] = Texture; AlphaArg2[0] = Diffuse; Texture[1] = maskTexture; TexCoordIndex[1] = 0; AddressU[1] = Clamp; AddressV[1] = Clamp; ColorOp[1] = SelectArg1; ColorArg1[1] = Current; AlphaOp[1] = Modulate; AlphaArg1[1] = Current; AlphaArg2[1] = Texture; ColorOp[2] = Disable; AlphaOp[2] = Disable; } } tex_matrix.fx: // // tex_matrix.fx // //------------------------------------------- // Returns a translation matrix //------------------------------------------- float3x3 makeTranslationMatrix ( float2 pos ) { return float3x3( 1, 0, 0, 0, 1, 0, pos.x, pos.y, 1 ); } //------------------------------------------- // Returns a rotation matrix //------------------------------------------- float3x3 makeRotationMatrix ( float angle ) { float s = sin(angle); float c = cos(angle); return float3x3( c, s, 0, -s, c, 0, 0, 0, 1 ); } //------------------------------------------- // Returns a scale matrix //------------------------------------------- float3x3 makeScaleMatrix ( float2 scale ) { return float3x3( scale.x, 0, 0, 0, scale.y, 0, 0, 0, 1 ); } //------------------------------------------- // Returns a combined matrix of doom //------------------------------------------- float3x3 makeTextureTransform ( float2 prePosition, float2 scale, float2 scaleCenter, float rotAngle, float2 rotCenter, float2 postPosition ) { float3x3 matPrePosition = makeTranslationMatrix( prePosition ); float3x3 matToScaleCen = makeTranslationMatrix( -scaleCenter ); float3x3 matScale = makeScaleMatrix( scale ); float3x3 matFromScaleCen = makeTranslationMatrix( scaleCenter ); float3x3 matToRotCen = makeTranslationMatrix( -rotCenter ); float3x3 matRot = makeRotationMatrix( rotAngle ); float3x3 matFromRotCen = makeTranslationMatrix( rotCenter ); float3x3 matPostPosition = makeTranslationMatrix( postPosition ); float3x3 result = mul( mul( mul( mul( mul( mul( mul( matPrePosition ,matToScaleCen) ,matScale) ,matFromScaleCen) ,matToRotCen) ,matRot) ,matFromRotCen) ,matPostPosition) ; return result; } Shader usage: local screenSource = dxCreateScreenSource(1920, 1080) local shader = dxCreateShader("blurMask.fx") local texture = dxCreateTexture("panel.png") local renderTarget = dxCreateRenderTarget(539, 539, true) dxSetShaderValue(shader, 'screenSource', screenSource) dxSetShaderValue(shader, 'factor', 0.007) dxSetShaderValue(shader, 'maskTexture', texture) function renderScreen() dxUpdateScreenSource(screenSource) dxSetRenderTarget(renderTarget, true) dxDrawImage(-(1920/2-(539/2)), -(1080/2-(539/2)), 1920, 1080, screenSource) dxSetRenderTarget() dxDrawImage(0, 0, 539, 539, texture) dxSetShaderValue(shader, 'screenSource', renderTarget) for intensity = 0, 4 do dxSetShaderValue(shader, 'factor', 0.0080 * 1 + (intensity / 4 * 0.001 * 1)); end dxDrawImage(1920/2-(539/2), 1080/2-(539/2), 539, 539, shader) end addEventHandler('onClientRender', root, renderScreen) Effect I've got: Expected effect should mask the blur for a texture i provide (this circle that is rendered on the left top side of screen) Edited December 22, 2022 by bover Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now