raynner Posted December 4, 2022 Share Posted December 4, 2022 Hey guys, I have the S@moke box shader, I need to apply the shader to the texture, not the screen I know I need to add the raplace part to the code but I don't know how to remove the screensource part correctly from the encoder. Can someone help me ? original code i change texture screenSource to tex to use dxSetShaderValue(mytexture) I don't know how to modify texturesample and remove self PixelShaderFunction texture screenSource; float2 screenSize = float2(0.0f, 0.0f); float pencilStrength = 1.0f; float saturation = 1.0f; float contrast = 1.0f; float brightness = 1.0f; sampler TextureSampler = sampler_state { Texture = <screenSource>; AddressU = Mirror; AddressV = Mirror; }; static const float2 blurring[16] = { float2(-0.326212f, -0.40581f), float2(-0.840144f, -0.07358f), float2(-0.695914f, 0.457137f), float2(-0.203345f, 0.620716f), float2(0.96234f, -0.194983f), float2(0.473434f, -0.480026f), float2(0.519456f, 0.767022f), float2(0.185461f, -0.893124f), float2(0.507431f, 0.064425f), float2(0.89642f, 0.412458f), float2(-0.32194f, -0.932615f), float2(-0.65432f, -0.87421f), float2(-0.456899f, -0.633247f), float2(-0.123456f, -0.865433f), float2(-0.664332f, -0.25680f), float2(-0.791559f, -0.59771f) }; float4 PixelShaderFunction(float2 texCoords : TEXCOORD0) : COLOR0 { float4 baseColor = tex2D(TextureSampler, texCoords); for(int i = 0; i < 16; i++) { float2 newCoords = texCoords.xy + (blurring[i] / screenSize * pencilStrength); baseColor += tex2D(TextureSampler, newCoords); } baseColor /= 17.0f; if (baseColor.r <= 0.1f) { baseColor.a = 0.0f; } if (baseColor.g <= 0.1f) { baseColor.a = 0.0f; } if (baseColor.b <= 0.1f) { baseColor.a = 0.0f; } float4 mainColor = tex2D(TextureSampler, texCoords); float4 outlineColor = saturate(mainColor / baseColor); float value = (outlineColor.r + outlineColor.g + outlineColor.b) / 3.0f; outlineColor.r = value; outlineColor.g = value; outlineColor.b = value; outlineColor.rgb = 1 - outlineColor.rgb; outlineColor.a *= outlineColor.r; float4 finalColor = baseColor - (outlineColor * 2.0f); float3 luminanceWeights = float3(0.299f, 0.587f, 0.114f); float luminance = dot(finalColor, luminanceWeights); finalColor.rgb = lerp(luminance, finalColor.rgb, saturation); finalColor.a = finalColor.a; finalColor.rgb = ((finalColor.rgb - 0.5f) * max(contrast, 0.0f)) + 0.5f; finalColor.rgb *= brightness; return finalColor; } technique Cartoon_01 { pass Pass1 { PixelShader = compile ps_2_0 PixelShaderFunction(); } } // Fallback technique Fallback { pass P0 { // Just draw normally } } Link to comment
Trust aka Tiffergan Posted December 10, 2022 Share Posted December 10, 2022 (edited) To apply the S@moke box shader to a texture instead of the screen, you need to remove the followin fragments of code: sampler TextureSampler = sampler_state { Texture = <screenSource>; AddressU = Mirror; AddressV = Mirror; }; and float4 PixelShaderFunction(float2 texCoords : TEXCOORD0) : COLOR0 { // shader code } then you need to add following code sampler TextureSampler = sampler_state { Texture = <tex>; AddressU = Mirror; AddressV = Mirror; }; technique Draw { pass P0 { PixelShader = compile ps_3_0 PixelShaderFunction(texCoords); } } In the above code, `tex` is used as the name of the texture that the shader should be applied to, instead of `screenSource`. Also, a `technique` section was added, which allows the shader to be called from code. Including these changes should allow the shader to be applied to the texture instead of the screen. @raynner Edited December 10, 2022 by LOOah 1 Link to comment
raynner Posted December 13, 2022 Author Share Posted December 13, 2022 To apply the S@moke box shader to a texture instead of the screen, you need to remove the followin fragments of code: sampler TextureSampler = sampler_state { Texture = <screenSource>; AddressU = Mirror; AddressV = Mirror; }; and float4 PixelShaderFunction(float2 texCoords : TEXCOORD0) : COLOR0 { // shader code } then you need to add following code sampler TextureSampler = sampler_state { Texture = <tex>; AddressU = Mirror; AddressV = Mirror; }; technique Draw { pass P0 { PixelShader = compile ps_3_0 PixelShaderFunction(texCoords); } } In the above code, `tex` is used as the name of the texture that the shader should be applied to, instead of `screenSource`. Also, a `technique` section was added, which allows the shader to be called from code. Including these changes should allow the shader to be applied to the texture instead of the screen. @raynner ok ! I will test as soon as possible, thank you men 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