trunk/hlsl/vector.fx
| r0 | r19975 | |
| 1 | //----------------------------------------------------------------------------- |
| 2 | // Effect File Variables |
| 3 | //----------------------------------------------------------------------------- |
| 4 | |
| 5 | texture Diffuse; |
| 6 | |
| 7 | sampler DiffuseSampler = sampler_state |
| 8 | { |
| 9 | Texture = <Diffuse>; |
| 10 | MipFilter = LINEAR; |
| 11 | MinFilter = LINEAR; |
| 12 | MagFilter = LINEAR; |
| 13 | AddressU = CLAMP; |
| 14 | AddressV = CLAMP; |
| 15 | AddressW = CLAMP; |
| 16 | }; |
| 17 | |
| 18 | //----------------------------------------------------------------------------- |
| 19 | // Vertex Definitions |
| 20 | //----------------------------------------------------------------------------- |
| 21 | |
| 22 | struct VS_OUTPUT |
| 23 | { |
| 24 | float4 Position : POSITION; |
| 25 | float4 Color : COLOR0; |
| 26 | float2 TexCoord : TEXCOORD0; |
| 27 | }; |
| 28 | |
| 29 | struct VS_INPUT |
| 30 | { |
| 31 | float3 Position : POSITION; |
| 32 | float4 Color : COLOR0; |
| 33 | float2 TexCoord : TEXCOORD0; |
| 34 | }; |
| 35 | |
| 36 | struct PS_INPUT |
| 37 | { |
| 38 | float4 Color : COLOR0; |
| 39 | float2 TexCoord : TEXCOORD0; |
| 40 | }; |
| 41 | |
| 42 | //----------------------------------------------------------------------------- |
| 43 | // Simple Vertex Shader |
| 44 | //----------------------------------------------------------------------------- |
| 45 | |
| 46 | uniform float TargetWidth; |
| 47 | uniform float TargetHeight; |
| 48 | |
| 49 | VS_OUTPUT vs_main(VS_INPUT Input) |
| 50 | { |
| 51 | VS_OUTPUT Output = (VS_OUTPUT)0; |
| 52 | |
| 53 | Output.Position = float4(Input.Position.xyz, 1.0f); |
| 54 | Output.Position.x /= TargetWidth; |
| 55 | Output.Position.y /= TargetHeight; |
| 56 | Output.Position.y = 1.0f - Output.Position.y; |
| 57 | Output.Position.x -= 0.5f; |
| 58 | Output.Position.y -= 0.5f; |
| 59 | Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f); |
| 60 | Output.Color = float4(0.0f, 0.0f, Input.Color.z, 1.0f); |
| 61 | Output.TexCoord = Input.Position.xy / float2(TargetWidth, TargetHeight); |
| 62 | |
| 63 | return Output; |
| 64 | } |
| 65 | |
| 66 | //----------------------------------------------------------------------------- |
| 67 | // Simple Pixel Shader |
| 68 | //----------------------------------------------------------------------------- |
| 69 | |
| 70 | float4 ps_main(PS_INPUT Input) : COLOR |
| 71 | { |
| 72 | float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord); |
| 73 | return BaseTexel * Input.Color; |
| 74 | } |
| 75 | |
| 76 | //----------------------------------------------------------------------------- |
| 77 | // Simple Effect |
| 78 | //----------------------------------------------------------------------------- |
| 79 | |
| 80 | technique TestTechnique |
| 81 | { |
| 82 | pass Pass0 |
| 83 | { |
| 84 | Lighting = FALSE; |
| 85 | |
| 86 | //Sampler[0] = <DiffuseSampler>; |
| 87 | |
| 88 | VertexShader = compile vs_2_0 vs_main(); |
| 89 | PixelShader = compile ps_2_0 ps_main(); |
| 90 | } |
| 91 | } |
trunk/src/osd/windows/d3dhlsl.h
| r19974 | r19975 | |
| 45 | 45 | #include "aviio.h" |
| 46 | 46 | |
| 47 | 47 | //============================================================ |
| 48 | // CONSTANTS |
| 49 | //============================================================ |
| 50 | |
| 51 | #define HLSL_VECTOR (0) |
| 52 | |
| 53 | //============================================================ |
| 48 | 54 | // TYPE DEFINITIONS |
| 49 | 55 | //============================================================ |
| 50 | 56 | |
| r19974 | r19975 | |
| 111 | 117 | |
| 112 | 118 | bool enabled() { return master_enable; } |
| 113 | 119 | |
| 120 | bool vector_enabled() { return vector_enable && (bool)HLSL_VECTOR; } |
| 121 | d3d_render_target* get_vector_target(d3d_info *d3d); |
| 122 | void create_vector_target(d3d_info *d3d, render_primitive *prim); |
| 123 | |
| 114 | 124 | void begin(); |
| 115 | 125 | void init_effect_info(d3d_poly_info *poly); |
| 116 | 126 | void render_quad(d3d_poly_info *poly, int vertnum); |
| r19974 | r19975 | |
| 159 | 169 | win_window_info * window; // D3D window info |
| 160 | 170 | |
| 161 | 171 | bool master_enable; // overall enable flag |
| 172 | bool vector_enable; // vector post-processing enable flag |
| 162 | 173 | bool paused; // whether or not rendering is currently paused |
| 163 | 174 | int num_screens; // number of emulated physical screens |
| 164 | 175 | int curr_screen; // current screen for render target operations |
| r19974 | r19975 | |
| 193 | 204 | d3d_texture * snap_texture; // snapshot upscaled texture |
| 194 | 205 | int snap_width; // snapshot width |
| 195 | 206 | int snap_height; // snapshot height |
| 207 | bool lines_pending; // whether or not we have lines to flush on the next quad |
| 196 | 208 | |
| 197 | 209 | // HLSL effects |
| 198 | 210 | d3d_surface * backbuffer; // pointer to our device's backbuffer |
| 199 | 211 | d3d_effect * curr_effect; // pointer to the currently active effect object |
| 200 | | d3d_effect * effect; // pointer to the current primary-effect object |
| 201 | | d3d_effect * prescale_effect; // pointer to the current prescale-effect object |
| 202 | | d3d_effect * post_effect; // pointer to the current post-effect object |
| 203 | | d3d_effect * pincushion_effect; // pointer to the current pincushion-effect object |
| 204 | | d3d_effect * focus_effect; // pointer to the current focus-effect object |
| 205 | | d3d_effect * phosphor_effect; // pointer to the current phosphor-effect object |
| 206 | | d3d_effect * deconverge_effect; // pointer to the current deconvergence-effect object |
| 207 | | d3d_effect * color_effect; // pointer to the current color-effect object |
| 208 | | d3d_effect * yiq_encode_effect; // pointer to the current YIQ encoder effect object |
| 209 | | d3d_effect * yiq_decode_effect; // pointer to the current YIQ decoder effect object |
| 212 | d3d_effect * effect; // pointer to the primary-effect object |
| 213 | d3d_effect * prescale_effect; // pointer to the prescale-effect object |
| 214 | d3d_effect * post_effect; // pointer to the post-effect object |
| 215 | d3d_effect * pincushion_effect; // pointer to the pincushion-effect object |
| 216 | d3d_effect * focus_effect; // pointer to the focus-effect object |
| 217 | d3d_effect * phosphor_effect; // pointer to the phosphor-effect object |
| 218 | d3d_effect * deconverge_effect; // pointer to the deconvergence-effect object |
| 219 | d3d_effect * color_effect; // pointer to the color-effect object |
| 220 | d3d_effect * yiq_encode_effect; // pointer to the YIQ encoder effect object |
| 221 | d3d_effect * yiq_decode_effect; // pointer to the YIQ decoder effect object |
| 222 | #if HLSL_VECTOR |
| 223 | d3d_effect * vector_effect; // pointer to the vector-effect object |
| 224 | #endif |
| 210 | 225 | d3d_vertex * fsfx_vertices; // pointer to our full-screen-quad object |
| 211 | 226 | |
| 212 | 227 | public: |
trunk/src/osd/windows/d3dhlsl.c
| r19974 | r19975 | |
| 191 | 191 | hlsl_info::hlsl_info() |
| 192 | 192 | { |
| 193 | 193 | master_enable = false; |
| 194 | vector_enable = true; |
| 194 | 195 | prescale_size_x = 1; |
| 195 | 196 | prescale_size_y = 1; |
| 196 | 197 | prescale_force_x = 0; |
| r19974 | r19975 | |
| 1062 | 1063 | g_slider_list = init_slider_list(); |
| 1063 | 1064 | |
| 1064 | 1065 | const char *fx_dir = downcast<windows_options &>(window->machine().options()).screen_post_fx_dir(); |
| 1066 | |
| 1067 | // Replace all this garbage with a proper data-driven system |
| 1065 | 1068 | char primary_name_cstr[1024]; |
| 1066 | | char post_name_cstr[1024]; |
| 1067 | | char prescale_name_cstr[1024]; |
| 1068 | | char pincushion_name_cstr[1024]; |
| 1069 | | char phosphor_name_cstr[1024]; |
| 1070 | | char focus_name_cstr[1024]; |
| 1071 | | char deconverge_name_cstr[1024]; |
| 1072 | | char color_name_cstr[1024]; |
| 1073 | | char yiq_encode_name_cstr[1024]; |
| 1074 | | char yiq_decode_name_cstr[1024]; |
| 1075 | | |
| 1076 | 1069 | sprintf(primary_name_cstr, "%s\\primary.fx", fx_dir); |
| 1077 | 1070 | TCHAR *primary_name = tstring_from_utf8(primary_name_cstr); |
| 1078 | 1071 | |
| 1072 | char post_name_cstr[1024]; |
| 1079 | 1073 | sprintf(post_name_cstr, "%s\\post.fx", fx_dir); |
| 1080 | 1074 | TCHAR *post_name = tstring_from_utf8(post_name_cstr); |
| 1081 | 1075 | |
| 1076 | char prescale_name_cstr[1024]; |
| 1082 | 1077 | sprintf(prescale_name_cstr, "%s\\prescale.fx", fx_dir); |
| 1083 | 1078 | TCHAR *prescale_name = tstring_from_utf8(prescale_name_cstr); |
| 1084 | 1079 | |
| 1080 | char pincushion_name_cstr[1024]; |
| 1085 | 1081 | sprintf(pincushion_name_cstr, "%s\\pincushion.fx", fx_dir); |
| 1086 | 1082 | TCHAR *pincushion_name = tstring_from_utf8(pincushion_name_cstr); |
| 1087 | 1083 | |
| 1084 | char phosphor_name_cstr[1024]; |
| 1088 | 1085 | sprintf(phosphor_name_cstr, "%s\\phosphor.fx", fx_dir); |
| 1089 | 1086 | TCHAR *phosphor_name = tstring_from_utf8(phosphor_name_cstr); |
| 1090 | 1087 | |
| 1088 | char focus_name_cstr[1024]; |
| 1091 | 1089 | sprintf(focus_name_cstr, "%s\\focus.fx", fx_dir); |
| 1092 | 1090 | TCHAR *focus_name = tstring_from_utf8(focus_name_cstr); |
| 1093 | 1091 | |
| 1092 | char deconverge_name_cstr[1024]; |
| 1094 | 1093 | sprintf(deconverge_name_cstr, "%s\\deconverge.fx", fx_dir); |
| 1095 | 1094 | TCHAR *deconverge_name = tstring_from_utf8(deconverge_name_cstr); |
| 1096 | 1095 | |
| 1096 | char color_name_cstr[1024]; |
| 1097 | 1097 | sprintf(color_name_cstr, "%s\\color.fx", fx_dir); |
| 1098 | 1098 | TCHAR *color_name = tstring_from_utf8(color_name_cstr); |
| 1099 | 1099 | |
| 1100 | char yiq_encode_name_cstr[1024]; |
| 1100 | 1101 | sprintf(yiq_encode_name_cstr, "%s\\yiq_encode.fx", fx_dir); |
| 1101 | 1102 | TCHAR *yiq_encode_name = tstring_from_utf8(yiq_encode_name_cstr); |
| 1102 | 1103 | |
| 1104 | char yiq_decode_name_cstr[1024]; |
| 1103 | 1105 | sprintf(yiq_decode_name_cstr, "%s\\yiq_decode.fx", fx_dir); |
| 1104 | 1106 | TCHAR *yiq_decode_name = tstring_from_utf8(yiq_decode_name_cstr); |
| 1105 | 1107 | |
| r19974 | r19975 | |
| 1183 | 1185 | return 1; |
| 1184 | 1186 | } |
| 1185 | 1187 | |
| 1188 | // create the vector shader |
| 1189 | #if HLSL_VECTOR |
| 1190 | char vector_cstr[1024]; |
| 1191 | sprintf(vector_cstr, "%s\\vector.fx", fx_dir); |
| 1192 | TCHAR *vector_name = tstring_from_utf8(vector_cstr); |
| 1193 | |
| 1194 | result = (*d3dintf->device.create_effect)(d3d->device, vector_name, &vector_effect); |
| 1195 | if(result != D3D_OK) |
| 1196 | { |
| 1197 | mame_printf_verbose("Direct3D: Unable to load vector.fx\n"); |
| 1198 | return 1; |
| 1199 | } |
| 1200 | if (vector_name) |
| 1201 | osd_free(vector_name); |
| 1202 | #endif |
| 1203 | |
| 1186 | 1204 | if (primary_name) |
| 1187 | 1205 | osd_free(primary_name); |
| 1188 | 1206 | if (post_name) |
| r19974 | r19975 | |
| 1367 | 1385 | UINT num_passes = 0; |
| 1368 | 1386 | d3d_info *d3d = (d3d_info *)window->drawdata; |
| 1369 | 1387 | |
| 1388 | #if HLSL_VECTOR |
| 1389 | if(PRIMFLAG_GET_VECTOR(poly->flags) && vector_enable) |
| 1390 | { |
| 1391 | lines_pending = true; |
| 1392 | } |
| 1393 | else if (PRIMFLAG_GET_VECTORBUF(poly->flags) && vector_enable) |
| 1394 | { |
| 1395 | } |
| 1396 | #endif |
| 1397 | |
| 1370 | 1398 | if(PRIMFLAG_GET_SCREENTEX(d3d->last_texture_flags) && poly->texture != NULL) |
| 1371 | 1399 | { |
| 1372 | 1400 | d3d_render_target *rt = find_render_target(poly->texture); |
| r19974 | r19975 | |
| 1782 | 1810 | |
| 1783 | 1811 | options->params_dirty = false; |
| 1784 | 1812 | } |
| 1813 | #if HLSL_VECTOR |
| 1814 | else if(PRIMFLAG_GET_VECTOR(poly->flags) && vector_enable) |
| 1815 | { |
| 1816 | } |
| 1817 | #endif |
| 1785 | 1818 | else |
| 1786 | 1819 | { |
| 1787 | 1820 | (*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->rawwidth : 8.0f); |
| r19974 | r19975 | |
| 1863 | 1896 | return true; |
| 1864 | 1897 | } |
| 1865 | 1898 | |
| 1899 | d3d_render_target* hlsl_info::get_vector_target(d3d_info *d3d) |
| 1900 | { |
| 1901 | #if HLSL_VECTOR |
| 1902 | if (!vector_enable) |
| 1903 | { |
| 1904 | return false; |
| 1905 | } |
| 1906 | |
| 1907 | return find_render_target(d3d->width, d3d->height, 0, 0); |
| 1908 | #endif |
| 1909 | return NULL; |
| 1910 | } |
| 1911 | |
| 1912 | void hlsl_info::create_vector_target(d3d_info *d3d, render_primitive *prim) |
| 1913 | { |
| 1914 | #if HLSL_VECTOR |
| 1915 | if (!add_render_target(d3d, NULL, d3d->width, d3d->height, 1, 1)) |
| 1916 | { |
| 1917 | vector_enable = false; |
| 1918 | } |
| 1919 | #endif |
| 1920 | } |
| 1921 | |
| 1866 | 1922 | //============================================================ |
| 1867 | 1923 | // hlsl_info::add_render_target - register a render target |
| 1868 | 1924 | //============================================================ |
| 1869 | 1925 | |
| 1870 | 1926 | bool hlsl_info::add_render_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int xprescale, int yprescale) |
| 1871 | 1927 | { |
| 1872 | | if (find_render_target(info)) |
| 1928 | UINT32 screen_index = 0; |
| 1929 | UINT32 page_index = 0; |
| 1930 | if (info != NULL) |
| 1873 | 1931 | { |
| 1874 | | remove_render_target(info); |
| 1932 | if (find_render_target(info)) |
| 1933 | { |
| 1934 | remove_render_target(info); |
| 1935 | } |
| 1936 | |
| 1937 | UINT32 screen_index_data = (UINT32)info->texinfo.osddata; |
| 1938 | screen_index = screen_index_data >> 1; |
| 1939 | page_index = screen_index_data & 1; |
| 1875 | 1940 | } |
| 1876 | 1941 | |
| 1877 | | UINT32 screen_index_data = (UINT32)info->texinfo.osddata; |
| 1878 | | UINT32 screen_index = screen_index_data >> 1; |
| 1879 | | UINT32 page_index = screen_index_data & 1; |
| 1880 | | |
| 1881 | 1942 | d3d_render_target* target = (d3d_render_target*)global_alloc_clear(d3d_render_target); |
| 1882 | 1943 | |
| 1883 | 1944 | if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale)) |
| r19974 | r19975 | |
| 1886 | 1947 | return false; |
| 1887 | 1948 | } |
| 1888 | 1949 | |
| 1889 | | target->info = info; |
| 1950 | if (info != NULL) |
| 1951 | { |
| 1952 | target->width = info->texinfo.width; |
| 1953 | target->height = info->texinfo.height; |
| 1954 | } |
| 1955 | else |
| 1956 | { |
| 1957 | target->width = d3d->width; |
| 1958 | target->height = d3d->height; |
| 1959 | } |
| 1890 | 1960 | |
| 1891 | | target->width = info->texinfo.width; |
| 1892 | | target->height = info->texinfo.height; |
| 1893 | | |
| 1894 | 1961 | target->screen_index = screen_index; |
| 1895 | 1962 | target->page_index = page_index; |
| 1896 | 1963 | |
| 1897 | | d3d_cache_target* cache = find_cache_target(target->screen_index, info->texinfo.width, info->texinfo.height); |
| 1964 | d3d_cache_target* cache = find_cache_target(target->screen_index, target->width, target->height); |
| 1898 | 1965 | if (cache == NULL) |
| 1899 | 1966 | { |
| 1900 | 1967 | if (!add_cache_target(d3d, info, width, height, xprescale, yprescale, target->screen_index)) |