- Home /
Question by
ABerlemont · Jan 03, 2014 at 03:32 PM ·
shaderlines
Shader draw lines
Hey !
I'm currently trying to write a shader to draw horizontal lines on the screen (kinda like a scanline shader but not regular).
I managed to write a frag shader but because of the transformation of the screen coordinate from 0,1 to 0,screenSize sometimes the shader isn't precise enought and misses some lines to render.
struct vertOut {
float4 pos:SV_POSITION;
float4 src:TEXCOORD;
};
vertOut vert(appdata_base v) {
vertOut o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.src = ComputeScreenPos(o.pos);
return o;
}
fixed4 frag(vertOut i) : COLOR0 {
// _ScreenParams.xy => width/height of screen
fixed4 output = fixed4(1,1,1,1);
float2 wcoord = (i.src.xy / i.src.w);
wcoord.y = 1 - wcoord.y;
int y = floor(wcoord.y * _ScreenParams.y);
The y here is most of the time the right position in the screen but sometimes it match the previous or next line ...
I guess my question is : What would be the best way to be able to draw horizontal lines of 1px (thickness) at a specific position of the screen ? Maybe there is a better way than shaders ? :D
(Must work on iOS)
Many thanks !
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613125437im_/https://answers.unity.com/themes/thub/images/avi.jpg)