Tag Info

Hot answers tagged

30

coderanger is right about HLSL targeting DirectX, GLSL targeting OpenGL and CG being available with both interfaces. However there are other things to consider (learned on the OGRE forum) : CG will not allow you to use the latest features of GLSL (I'm not sure about HLSL). It's a middle ground so you'll not be able to fully exploit the GLSL features, only ...


14

I can only talk about CG vs HLSL because those are the 2 I have used so far. Cg is not the same as HLSL. In Cg, NVIDIA did an excellent job in creating a very clean shader syntax. Its very similar to HLSL. But, tie-together with D3D9/D3D11 (init code, shader compilation code) is much cleaner on HLSL than Cg. -1 Cg. Cg has a nasty bit of start up code ...


9

My very basic understanding is that HLSL is only for DirectX and GLSL is only for OpenGL. Cg is basically the same language as HLSL, but can be used with either DirectX or OpenGL (though via different runtime code).


8

Another crucial difference between HLSL and GLSL (I don't know CG so I can't speak for it) is that with HLSL Microsoft provide the shader compiler as part of the D3D runtime whereas with GLSL your hardware vendor provides it as part of their driver. This has advantages and disadvantages on both sides. With the GLSL method the vendor can tune the compiler ...


6

Firstly you can do texture fetching inside conditional blocks in HLSL. tex2Dlod() and tex2Dgrad() will work fine inside one. It's just tex2D() that won't compile, and you can work round that by computing ddx() and ddy() outside the conditional and using tex2Dgrad(). To reliably stop the texture fetch (or any other block of code) being executed in HLSL, use ...


5

They are very different: smoothstep(x, y, z); basically does saturate((z-x)/(y-x)) and then smoothes the result to start and end smoothly. The result always lies between 0 and 1. lerp(x, y, z); returns z*y+(1-z)*x As long as x lies between 0 and 1 the result lies between x and y. What you want is saturate((z-x)/(y-x)) which gives you the same range as ...


5

It appears to be a slightly misleading book. Offset does not change drawing order or even the 3D position of pixels. It simply adds some numbers to the Z value (the one that's going to the Z tests and Z-buffer) of a pixel (hence the term "offset"), making it appear above or below other triangles. This is generally used to prioritize visibility of triangles ...


4

CG (as your tags indicate) supports the WPOS semantic in some profiles, for example this one. An input parameter bound to the WPOS semantic will get the window position (with the origin in the lower-left) of the fragment. Other languages, like GLSL, have similar predefined uniforms or inputs (gl_FragCoord for example), although the specifics of their value ...


4

If nothing else, you can manually calculate shadows using techniques similar to low-resolution ray tracing, then somehow put them on screen. I think this would be fairly easy, since unity supports hit detection with custom rays and all scene objects that have a collider, but of course this is highly inefficient. If you can't afford unity pro (not even the ...


3

Why not do that with a surface shader? you could have Per Vertex coloring and on a same time keep multi-light shading (Which is "almost" default when using surface shaders) Surface shaders doc : Writing surface shaders Surface shader Examples Surface Shaders with DX11 Tessellation According to those docs over here, you should be able to create a basic ...


3

The answer is in the documentation, in "API Overview/Graphics Overview": Shader descriptions have the following restrictions in comparison with standard Cg language. Variables and functions with the same names as GLSL and Cg reserved words cannot be used. It turns that the emulator, the PSVita and Android devices all have very different ...


3

I don't see any special shaders there, just some vertex colors that are generated with an ambient occlusion (or similar) calculation algorithm and perhaps some differently calculated vertex normals. The results remind me of a demo I've seen some time ago which simulated global illumination by "bending" vertex normals and generating occlusion values for ...


2

The Cg toolkit supports its own version of effect files, CgFX. These support techniques, states, annotations... I don't have any experience with them personally, but they are supported by FX Composer, at least. CGeffect cgCreateEffectFromFile( CGcontext context, const char * filename, const ...


2

The reference manual is up to date in the nvidia site Cg 3.0 Reference Manual, which i believe is where you can get most of the information you want. It does contain very detailed data of everything you can do with Cg, I don't think there's something missing there, but it may be hard to read at first as it's just a reference for all the technical aspects of ...


2

To get the RGB values of your scene influenced by the minimum of several alpha values from your fog, the most straightforward way to use a render texture. This requires Unity Pro. (Some alternatives are provided below if this isn't an option) Set up a second camera, with Culling Mask set so that it sees only your fog hole quads. Set its Background to the ...


2

One way of doing this is using min blending. With Unity this can be set up in ShaderLab using the BlendOp command. If your objects are all monochrome as seen here, you may simply be able to use min blending directly on the objects as they're rendered and avoid having an alpha channel at all. (White is transparent when using min blending.) Min blending ...


2

They are not equivalent. In the GLSL shader you use the same texture coordinate for your diffuse and normal map (gl_TexCoord[0]). In the CG shader you use separate ones (TEXCOORD0 and TEXCOORD1, which is presumably not set).


1

The shader was fine. But when I tried to use other shaders I realized what was wrong. It was the C++ code that was lacking lines (rrr!! This is the reason why I hate shaders! It's so complicated to make a link in your head between every line you write in one file and what must be written in the other for it to be recognized!). In the display function, I ...


1

I tried compiling it from the command-line as follows: cgc -profile glslf -entry FS_Main test.cg This gave the following error output: test.cg test.cg(18) : error C1066: invalid type in type constructor test.cg(18) : error C1010: expression left of ."rgb" is not a struct This immediately highlights the fact that you used texture2D on line 18 instead of ...


1

cgGetNamedParameter Example code: CGprogram cgprog; cgprog = cgCreateProgram(...); cgGLLoadProgram(cgprog); CGparameter modelviewproj, lightpos; modelviewproj = cgGetNamedParameter(cgprog, "modelviewproj"); lightpos = cgGetNamedParameter(cgprog, "lightpos"); Sample code paraphrased from the book Advanced Game Development with Programmable Graphics ...


1

I was thinking wrong. I do not more passes to receive every light in the scene. I took a shortcut and used a surface shader in the end. I post it here for reference Shader "Custom/Test01" { Properties { _MainTex ("Texture (RGBA)", 2D) = "white" {} } SubShader { Tags { "Queue" = "Transparent" ...


1

Um ... well ... it's a pretty basic example of triplanar texturing but it works ... Shader "My Shaders/TriPlanar" { Properties { Tex1 ("Texture 1", 2D) = "white" {} Tex2 ("Texture 2", 2D) = "white" {} Tex3 ("Texture 3", 2D) = "white" {} } SubShader { Pass { CGPROGRAM #pragma target ...


1

Yes, the position sent to the vertex shader is generally the local coordinates of the object's vertex. Your multiplication by worldViewProjMatrix in the vertex shader is what handles the transformation from world space to camera space to projection space, all in one shot. The GPU will interpolate any out variables from your vertex shader across the face of ...


1

CgFX files are not shaders. They are FX files. Shaders are a lower-level construct; a shader is just the source code for a particular shading stage. Techniques, passes, etc are all higher level than Cg. You cannot process CgFX's FX data into GLSL because GLSL has no equivalent constructs (just as Cg itself doesn't). You can process the files themselves with ...


1

The simplest option to get a depth bias is to move the near and far clip planes. See http://tomsdxfaq.blogspot.com/2002_07_01_archive.html#79344425#79344425 You could do that in a vertex shader if you wanted to, but it's easier to do it from the calling code.


1

The point of the waves generated in a texture is to use them as normal maps, allowing the appearance of more detail to the waves than would be possible without spending a lot of actual geometry on the water surface. It's been a while since I did much actual graphics work, but I believe the point regarding the wave parameterization is just mentioned as a ...


1

You might want to look into the RTSS (Run Time Shader System) that comes with Ogre as well. It is fairly new, but you basically write shaders in code rather than external files. I have not implemented it yet, but definitely plan to use this when the time comes. Here is a huge series of tutorials on the Ogre wiki as well for writing shaders. ...



Only top voted, non community-wiki answers of a minimum length are eligible