Jump to content
  • Advertisement

PlazmaInteractive

Member
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

107 Neutral

About PlazmaInteractive

  • Rank
    Newbie

Personal Information

  • Interests
    Programming

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I forgot to say this but my shader is actually registering mouse clicks from my C# code. When I right click, the density texture changes from blank to a red color while left clicking changes the velocity texture to a yellow color. I assume this is because my density texture is set to R float so it's only displaying the red channel while my velocity texture is in RG float, showing a yellow color. My other shaders is still available in the zip folder above but I'm going to share the shader that I'm using to render my simulation. Shader "FluidSimulation/Render" { SubShader { Pass { ZTest Always CGPROGRAM #include "UnityCG.cginc" #pragma vertex vert #pragma fragment frag uniform sampler2D _Read; struct v2f { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; }; v2f vert(appdata_base v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.uv = v.texcoord.xy; return o; } float4 frag(v2f i) : SV_TARGET { float3 result = tex2D(_Read, i.uv).xyz; return float4(result, 1.0); } ENDCG } } } Pretty simple shader that just takes in a texture I inputted from my C# code and display it. The reason why I'm posting this is because in other implementations, the shader does some minor modification before displaying the final result. Example 1, Example 2 Is there any modifications that I need to make to display my fluid simulation correctly? Also wondering if my Splat shader will work with my other shaders or if I should try changing to some other form of adding forces such as this one.
  2. I've been attempting to write a Navier Stokes fluid simulation using the Cg language in Unity for a few times now with no luck. Every attempt has only resulted in a blank result. I don't really know how to fix the problem but from what I see, I think the problem might lie in the rendering-to-texture aspect and not the shader themselves so this question might be more Unity-related the shader-related. But just in case, I've read Chapter 38 from GPU Gems and while I don't understand the maths, I do understand the implementation of it. If I'm correct, the order for each timestep of the simulation is: 1. Advection 2. Force application 3. Projection (computing divergence, solving Poisson equations using Jacobi iterations, gradient subtraction) So there's that. Multiple shaders would be required for each step and I need to have multiple textures to represent the state of fluid such as velocity, density and pressure. Those states each need to have two textures to read and write to, so I can swap them around after each step has been outputted to the correct texture. I also need a temporary divergence texture and a texture to display the final result. My first question is, what format should my textures be in? I've heard that you should use RGBA floating-point textures for each one but I don't know if that's really the case. Now about the implementation. Like I've said before, I think all my shaders have been written properly as I've compared them to numerous sources including GPU Gems codes and it looks similar. My shaders are based on this three.js implementation and this one. I want my simulation to be setup so that the user can click on the screen to add 'ink' and drag the mouse around to 'add force and velocity' to it. While the second implementation is a working example of a Unity implementation, it's not setup to how I want it to be and the three.js implementation does exactly that. So I combined the Splat shader from the three.js implementation to my own project to achieve the 'add force' that I want but I'm not sure if it's working properly. I've attached my shaders below along with a Unity package file for those who have Unity. If my shaders have all been written properly, then the problem lies in how to actually display it. Currently, I'm just inputting a density texture into my Render shader to display it but it's giving me a blank result. I don't know if there's anything I had to do first before displaying the fluid so if anyone knows, please let me know. Shaders.zip FluidSimulation.unitypackage
  3. I already have a forum post in Unity's forum that contains most of the details and code regarding the problem I'm having so look at that one first. So basically, I'm trying to write my own custom Cook-Torrance shader in Unity using Cg language. When I finished writing it up, the result shows a weird split halfway down the sphere where the first half looks correct and the second half being completely black. I don't know what's causing this weird visual glitch so I'm posting this here in case someone knows an answer. I'm using Trowbridge-Reitz for Distribution, Schlick-GGX for Geometric and Schlick approximation for Fresnel. You can see the result in the image below. The one after the image below is an image I found in this site that shows what I expected Cook-Torrance to look like.
  4. PlazmaInteractive

    [Unity and Cg] Am I calculating my PBR shader correctly?

    Well, in the meantime I decided to add in a simple IBL that someone in another forum have helped and this time, the results looked similar to Unity's own standard shader, but there is a problem regarding having a value of 1 roughness and 1 metallic. You can see all of the results here. My shader is the sphere in the left, standard shader is the one in the right. Here is the updated code. The modifications can be found starting from line 154.
  5. PlazmaInteractive

    [Unity and Cg] Am I calculating my PBR shader correctly?

    Yeah, I haven't added any IBL yet because I want to make sure I'm getting all the calculations correctly. About the roughness = 0 thing, in the visual results I linked above, I mentioned that I think the result looks correct at no roughness and 1 metallic. But what I was skeptical about is when it have a roughness of 1 and a metallic of 1 so a rough, metallic material. I thought it's meant to make the whole material look slightly darker like the one that Unity's own standard shader have. In their one, they use a smoothness value so just think of it as being an opposite of mine (0 smoothness means 1 roughness). You can see how theirs look darker but doesn't make it really, really dark like the one I have. Compare theirs to my one. So other than that, my whole calculations is correct? The one I'm confused about is how to add the diffuse and specular values together. I'm multiplying my diffuse value by 1.0 - metallic value for energy conservation but I'm not sure if that's the correct way to do it. In this paper—in which I am credited as a reviewer—Yoshiharu Gotanda presents equations for Oren-Nayar which are both simpler/more efficient than what you will have found elsewhere and more accurate compared to the full model than other approximations. http://research.tri-ace.com/Data/s2012_beyond_CourseNotes.pdf L. Spiro   Thanks for providing the paper. I haven't look into it extensively but it does look interesting so I'll study it when I have the time :)
  6. Hello everyone. I've started to learn shader programming as a hobby since the start of this year and I'm finally up to the point where I think I can learn how to implement PBR in my shader. So I read and studied a lot of articles that talk about PBR and its calculations. With that, I decided it was time to start coding. Firstly, I'm going for a metallic/roughness workflow for my PBR shader. I used the Oren-Nayar model for diffuse but I may change it to something more simple like Lambert as I've heard it's computationally more expensive. For the specular microfacet model I used GGX (normal distribution), Smith (geometry) and Schlick's approximation (fresnel). Because I'm still quite new with this, I got the calculations mainly from this site and this person's video. Now for the code. As I'm using Unity, I'm writing it with the Cg language wrapped in ShaderLab code. After adding in all the calculations in my shader, I see the results and I wasn't sure if I had implemented this properly. I tweaked the roughness and metallic value around and at some given value, it look correct while at the same time, it doesn't look correct on other values. I'm not great at explaining this in words so here are the visual results and my comments regarding them. The shader code can be found here. Again, as it's for Unity, the ShaderLab codes may be unfamiliar to you so just ignore those and find the Cg codes between the lines CGPROGRAM and ENDCG. I hope some of you understand what is happening here as it's very similar to HLSL and GLSL. If anyone know if I have implemented this correctly or not, please let me know. Thanks!
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!